module TD.Data.GiftOnChainPurchaseOfferTransaction
  (GiftOnChainPurchaseOfferTransaction(..)) 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 TD.Data.TonWalletMessage as TonWalletMessage

data GiftOnChainPurchaseOfferTransaction
  = GiftOnChainPurchaseOfferTransaction -- ^ Contains information about a transaction that must be sent from the TON wallet of the current user to send, accept, or cancel an on-chain gift purchase offer. Use sendTonWalletTransaction with regular_transaction_data and gasless_transaction_data created from message and gasless_message respectively to send the transaction. Successful sending of the transaction doesn't mean that the operation was completed; the result of the operation must be checked in the corresponding messageUpgradedGiftOnChainPurchaseOffer message in the chat 777000
    { GiftOnChainPurchaseOfferTransaction -> Maybe Text
offer_address              :: Maybe T.Text                            -- ^ Address of the smart contract of the offer on the TON blockchain
    , GiftOnChainPurchaseOfferTransaction -> Maybe Int
expiration_date            :: Maybe Int                               -- ^ Point in time (Unix timestamp) when the offer will expire
    , GiftOnChainPurchaseOfferTransaction -> Maybe TonWalletMessage
message                    :: Maybe TonWalletMessage.TonWalletMessage -- ^ The message that must be sent for a regular transfer
    , GiftOnChainPurchaseOfferTransaction -> Maybe TonWalletMessage
gasless_message            :: Maybe TonWalletMessage.TonWalletMessage -- ^ The message that must be sent for a gasless transfer; may be null if gasless transfer isn't available
    , GiftOnChainPurchaseOfferTransaction -> Maybe Int
rent_budget_amount         :: Maybe Int                               -- ^ The amount included in the message for rent of the offer smart contract, in the smallest units of TON Grams; 0 if none
    , GiftOnChainPurchaseOfferTransaction -> Maybe Int
execution_allowance_amount :: Maybe Int                               -- ^ The amount included in the message for execution of the offer smart contract, in the smallest units of TON Grams; 0 if none
    , GiftOnChainPurchaseOfferTransaction -> Maybe Int
forward_amount             :: Maybe Int                               -- ^ The amount forwarded with the gift transfer on acceptance of the offer, in the smallest units of TON Grams; 0 if none
    , GiftOnChainPurchaseOfferTransaction -> Maybe Int
fine_amount                :: Maybe Int                               -- ^ The expected fine for cancellation of the offer, in the smallest units of TON Grams; 0 if none. The final fine will be known after the cancellation is executed on the TON blockchain
    }
  deriving (GiftOnChainPurchaseOfferTransaction
-> GiftOnChainPurchaseOfferTransaction -> Bool
(GiftOnChainPurchaseOfferTransaction
 -> GiftOnChainPurchaseOfferTransaction -> Bool)
-> (GiftOnChainPurchaseOfferTransaction
    -> GiftOnChainPurchaseOfferTransaction -> Bool)
-> Eq GiftOnChainPurchaseOfferTransaction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GiftOnChainPurchaseOfferTransaction
-> GiftOnChainPurchaseOfferTransaction -> Bool
== :: GiftOnChainPurchaseOfferTransaction
-> GiftOnChainPurchaseOfferTransaction -> Bool
$c/= :: GiftOnChainPurchaseOfferTransaction
-> GiftOnChainPurchaseOfferTransaction -> Bool
/= :: GiftOnChainPurchaseOfferTransaction
-> GiftOnChainPurchaseOfferTransaction -> Bool
Eq, Int -> GiftOnChainPurchaseOfferTransaction -> ShowS
[GiftOnChainPurchaseOfferTransaction] -> ShowS
GiftOnChainPurchaseOfferTransaction -> String
(Int -> GiftOnChainPurchaseOfferTransaction -> ShowS)
-> (GiftOnChainPurchaseOfferTransaction -> String)
-> ([GiftOnChainPurchaseOfferTransaction] -> ShowS)
-> Show GiftOnChainPurchaseOfferTransaction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GiftOnChainPurchaseOfferTransaction -> ShowS
showsPrec :: Int -> GiftOnChainPurchaseOfferTransaction -> ShowS
$cshow :: GiftOnChainPurchaseOfferTransaction -> String
show :: GiftOnChainPurchaseOfferTransaction -> String
$cshowList :: [GiftOnChainPurchaseOfferTransaction] -> ShowS
showList :: [GiftOnChainPurchaseOfferTransaction] -> ShowS
Show)

instance I.ShortShow GiftOnChainPurchaseOfferTransaction where
  shortShow :: GiftOnChainPurchaseOfferTransaction -> String
shortShow GiftOnChainPurchaseOfferTransaction
    { offer_address :: GiftOnChainPurchaseOfferTransaction -> Maybe Text
offer_address              = Maybe Text
offer_address_
    , expiration_date :: GiftOnChainPurchaseOfferTransaction -> Maybe Int
expiration_date            = Maybe Int
expiration_date_
    , message :: GiftOnChainPurchaseOfferTransaction -> Maybe TonWalletMessage
message                    = Maybe TonWalletMessage
message_
    , gasless_message :: GiftOnChainPurchaseOfferTransaction -> Maybe TonWalletMessage
gasless_message            = Maybe TonWalletMessage
gasless_message_
    , rent_budget_amount :: GiftOnChainPurchaseOfferTransaction -> Maybe Int
rent_budget_amount         = Maybe Int
rent_budget_amount_
    , execution_allowance_amount :: GiftOnChainPurchaseOfferTransaction -> Maybe Int
execution_allowance_amount = Maybe Int
execution_allowance_amount_
    , forward_amount :: GiftOnChainPurchaseOfferTransaction -> Maybe Int
forward_amount             = Maybe Int
forward_amount_
    , fine_amount :: GiftOnChainPurchaseOfferTransaction -> Maybe Int
fine_amount                = Maybe Int
fine_amount_
    }
      = String
"GiftOnChainPurchaseOfferTransaction"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"offer_address"              String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
offer_address_
        , String
"expiration_date"            String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
expiration_date_
        , String
"message"                    String -> Maybe TonWalletMessage -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe TonWalletMessage
message_
        , String
"gasless_message"            String -> Maybe TonWalletMessage -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe TonWalletMessage
gasless_message_
        , String
"rent_budget_amount"         String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
rent_budget_amount_
        , String
"execution_allowance_amount" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
execution_allowance_amount_
        , String
"forward_amount"             String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
forward_amount_
        , String
"fine_amount"                String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
fine_amount_
        ]

instance AT.FromJSON GiftOnChainPurchaseOfferTransaction where
  parseJSON :: Value -> Parser GiftOnChainPurchaseOfferTransaction
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
"giftOnChainPurchaseOfferTransaction" -> Value -> Parser GiftOnChainPurchaseOfferTransaction
parseGiftOnChainPurchaseOfferTransaction Value
v
      String
_                                     -> Parser GiftOnChainPurchaseOfferTransaction
forall a. Monoid a => a
mempty
    
    where
      parseGiftOnChainPurchaseOfferTransaction :: A.Value -> AT.Parser GiftOnChainPurchaseOfferTransaction
      parseGiftOnChainPurchaseOfferTransaction :: Value -> Parser GiftOnChainPurchaseOfferTransaction
parseGiftOnChainPurchaseOfferTransaction = String
-> (Object -> Parser GiftOnChainPurchaseOfferTransaction)
-> Value
-> Parser GiftOnChainPurchaseOfferTransaction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GiftOnChainPurchaseOfferTransaction" ((Object -> Parser GiftOnChainPurchaseOfferTransaction)
 -> Value -> Parser GiftOnChainPurchaseOfferTransaction)
-> (Object -> Parser GiftOnChainPurchaseOfferTransaction)
-> Value
-> Parser GiftOnChainPurchaseOfferTransaction
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
offer_address_              <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"offer_address"
        Maybe Int
expiration_date_            <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"expiration_date"
        Maybe TonWalletMessage
message_                    <- Object
o Object -> Key -> Parser (Maybe TonWalletMessage)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"message"
        Maybe TonWalletMessage
gasless_message_            <- Object
o Object -> Key -> Parser (Maybe TonWalletMessage)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"gasless_message"
        Maybe Int
rent_budget_amount_         <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
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
"rent_budget_amount"
        Maybe Int
execution_allowance_amount_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
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
"execution_allowance_amount"
        Maybe Int
forward_amount_             <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
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
"forward_amount"
        Maybe Int
fine_amount_                <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
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
"fine_amount"
        GiftOnChainPurchaseOfferTransaction
-> Parser GiftOnChainPurchaseOfferTransaction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GiftOnChainPurchaseOfferTransaction
 -> Parser GiftOnChainPurchaseOfferTransaction)
-> GiftOnChainPurchaseOfferTransaction
-> Parser GiftOnChainPurchaseOfferTransaction
forall a b. (a -> b) -> a -> b
$ GiftOnChainPurchaseOfferTransaction
          { offer_address :: Maybe Text
offer_address              = Maybe Text
offer_address_
          , expiration_date :: Maybe Int
expiration_date            = Maybe Int
expiration_date_
          , message :: Maybe TonWalletMessage
message                    = Maybe TonWalletMessage
message_
          , gasless_message :: Maybe TonWalletMessage
gasless_message            = Maybe TonWalletMessage
gasless_message_
          , rent_budget_amount :: Maybe Int
rent_budget_amount         = Maybe Int
rent_budget_amount_
          , execution_allowance_amount :: Maybe Int
execution_allowance_amount = Maybe Int
execution_allowance_amount_
          , forward_amount :: Maybe Int
forward_amount             = Maybe Int
forward_amount_
          , fine_amount :: Maybe Int
fine_amount                = Maybe Int
fine_amount_
          }
  parseJSON Value
_ = Parser GiftOnChainPurchaseOfferTransaction
forall a. Monoid a => a
mempty