module TD.Data.UpgradedGiftDepositInfo
  (UpgradedGiftDepositInfo(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
import qualified Data.ByteString as BS

data UpgradedGiftDepositInfo
  = UpgradedGiftDepositInfo -- ^ Contains information needed to deposit an upgraded gift from the TON wallet of the current user to a Telegram account. The gift must be transferred by an internal message from the wallet to nft_address with gram_amount attached and with payload as the message body
    { UpgradedGiftDepositInfo -> Maybe Text
nft_address :: Maybe T.Text        -- ^ Address in TON blockchain to which the message must be sent
    , UpgradedGiftDepositInfo -> Maybe ByteString
payload     :: Maybe BS.ByteString -- ^ Body of the NFT transfer message
    , UpgradedGiftDepositInfo -> Maybe Int
gram_amount :: Maybe Int           -- ^ The amount of TON Grams that must be attached to the message to cover fees, in the smallest units of the cryptocurrency; excess amount will be returned to the wallet
    }
  deriving (UpgradedGiftDepositInfo -> UpgradedGiftDepositInfo -> Bool
(UpgradedGiftDepositInfo -> UpgradedGiftDepositInfo -> Bool)
-> (UpgradedGiftDepositInfo -> UpgradedGiftDepositInfo -> Bool)
-> Eq UpgradedGiftDepositInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UpgradedGiftDepositInfo -> UpgradedGiftDepositInfo -> Bool
== :: UpgradedGiftDepositInfo -> UpgradedGiftDepositInfo -> Bool
$c/= :: UpgradedGiftDepositInfo -> UpgradedGiftDepositInfo -> Bool
/= :: UpgradedGiftDepositInfo -> UpgradedGiftDepositInfo -> Bool
Eq, Int -> UpgradedGiftDepositInfo -> ShowS
[UpgradedGiftDepositInfo] -> ShowS
UpgradedGiftDepositInfo -> String
(Int -> UpgradedGiftDepositInfo -> ShowS)
-> (UpgradedGiftDepositInfo -> String)
-> ([UpgradedGiftDepositInfo] -> ShowS)
-> Show UpgradedGiftDepositInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UpgradedGiftDepositInfo -> ShowS
showsPrec :: Int -> UpgradedGiftDepositInfo -> ShowS
$cshow :: UpgradedGiftDepositInfo -> String
show :: UpgradedGiftDepositInfo -> String
$cshowList :: [UpgradedGiftDepositInfo] -> ShowS
showList :: [UpgradedGiftDepositInfo] -> ShowS
Show)

instance I.ShortShow UpgradedGiftDepositInfo where
  shortShow :: UpgradedGiftDepositInfo -> String
shortShow UpgradedGiftDepositInfo
    { nft_address :: UpgradedGiftDepositInfo -> Maybe Text
nft_address = Maybe Text
nft_address_
    , payload :: UpgradedGiftDepositInfo -> Maybe ByteString
payload     = Maybe ByteString
payload_
    , gram_amount :: UpgradedGiftDepositInfo -> Maybe Int
gram_amount = Maybe Int
gram_amount_
    }
      = String
"UpgradedGiftDepositInfo"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"nft_address" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
nft_address_
        , String
"payload"     String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
payload_
        , String
"gram_amount" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
gram_amount_
        ]

instance AT.FromJSON UpgradedGiftDepositInfo where
  parseJSON :: Value -> Parser UpgradedGiftDepositInfo
parseJSON v :: Value
v@(AT.Object Object
obj) = do
    String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String

    case String
t of
      String
"upgradedGiftDepositInfo" -> Value -> Parser UpgradedGiftDepositInfo
parseUpgradedGiftDepositInfo Value
v
      String
_                         -> Parser UpgradedGiftDepositInfo
forall a. Monoid a => a
mempty
    
    where
      parseUpgradedGiftDepositInfo :: A.Value -> AT.Parser UpgradedGiftDepositInfo
      parseUpgradedGiftDepositInfo :: Value -> Parser UpgradedGiftDepositInfo
parseUpgradedGiftDepositInfo = String
-> (Object -> Parser UpgradedGiftDepositInfo)
-> Value
-> Parser UpgradedGiftDepositInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UpgradedGiftDepositInfo" ((Object -> Parser UpgradedGiftDepositInfo)
 -> Value -> Parser UpgradedGiftDepositInfo)
-> (Object -> Parser UpgradedGiftDepositInfo)
-> Value
-> Parser UpgradedGiftDepositInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
nft_address_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"nft_address"
        Maybe ByteString
payload_     <- (String -> ByteString) -> Maybe String -> Maybe ByteString
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> ByteString
I.readBytes (Maybe String -> Maybe ByteString)
-> Parser (Maybe String) -> Parser (Maybe ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"payload"
        Maybe Int
gram_amount_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"gram_amount"
        UpgradedGiftDepositInfo -> Parser UpgradedGiftDepositInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UpgradedGiftDepositInfo -> Parser UpgradedGiftDepositInfo)
-> UpgradedGiftDepositInfo -> Parser UpgradedGiftDepositInfo
forall a b. (a -> b) -> a -> b
$ UpgradedGiftDepositInfo
          { nft_address :: Maybe Text
nft_address = Maybe Text
nft_address_
          , payload :: Maybe ByteString
payload     = Maybe ByteString
payload_
          , gram_amount :: Maybe Int
gram_amount = Maybe Int
gram_amount_
          }
  parseJSON Value
_ = Parser UpgradedGiftDepositInfo
forall a. Monoid a => a
mempty