module TD.Query.SendGiftOnChainPurchaseOffer
  (SendGiftOnChainPurchaseOffer(..)
  , defaultSendGiftOnChainPurchaseOffer
  ) 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

-- | Sends an on-chain offer to purchase an upgraded gift for TON Grams; can be used only if getOption("can_use_ton_wallet"). Returns the transaction that must be sent from the TON wallet of the current user to create the offer. The offer is created only after the transaction is executed on the TON blockchain. Returns 'TD.Data.GiftOnChainPurchaseOfferTransaction.GiftOnChainPurchaseOfferTransaction'
data SendGiftOnChainPurchaseOffer
  = SendGiftOnChainPurchaseOffer
    { SendGiftOnChainPurchaseOffer -> Maybe Text
gift_name   :: Maybe T.Text -- ^ Name of the upgraded gift
    , SendGiftOnChainPurchaseOffer -> Maybe Int
gram_amount :: Maybe Int    -- ^ The price offered for the gift, in the smallest units of TON Grams; must be at least upgradedGift.min_on_chain_purchase_offer_gram_amount
    , SendGiftOnChainPurchaseOffer -> Maybe Int
duration    :: Maybe Int    -- ^ Duration of the offer, in seconds; must be one of 21600, 43200, 86400, 129600, 172800, or 259200
    }
  deriving (SendGiftOnChainPurchaseOffer
-> SendGiftOnChainPurchaseOffer -> Bool
(SendGiftOnChainPurchaseOffer
 -> SendGiftOnChainPurchaseOffer -> Bool)
-> (SendGiftOnChainPurchaseOffer
    -> SendGiftOnChainPurchaseOffer -> Bool)
-> Eq SendGiftOnChainPurchaseOffer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SendGiftOnChainPurchaseOffer
-> SendGiftOnChainPurchaseOffer -> Bool
== :: SendGiftOnChainPurchaseOffer
-> SendGiftOnChainPurchaseOffer -> Bool
$c/= :: SendGiftOnChainPurchaseOffer
-> SendGiftOnChainPurchaseOffer -> Bool
/= :: SendGiftOnChainPurchaseOffer
-> SendGiftOnChainPurchaseOffer -> Bool
Eq, Int -> SendGiftOnChainPurchaseOffer -> ShowS
[SendGiftOnChainPurchaseOffer] -> ShowS
SendGiftOnChainPurchaseOffer -> String
(Int -> SendGiftOnChainPurchaseOffer -> ShowS)
-> (SendGiftOnChainPurchaseOffer -> String)
-> ([SendGiftOnChainPurchaseOffer] -> ShowS)
-> Show SendGiftOnChainPurchaseOffer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SendGiftOnChainPurchaseOffer -> ShowS
showsPrec :: Int -> SendGiftOnChainPurchaseOffer -> ShowS
$cshow :: SendGiftOnChainPurchaseOffer -> String
show :: SendGiftOnChainPurchaseOffer -> String
$cshowList :: [SendGiftOnChainPurchaseOffer] -> ShowS
showList :: [SendGiftOnChainPurchaseOffer] -> ShowS
Show)

instance I.ShortShow SendGiftOnChainPurchaseOffer where
  shortShow :: SendGiftOnChainPurchaseOffer -> String
shortShow
    SendGiftOnChainPurchaseOffer
      { gift_name :: SendGiftOnChainPurchaseOffer -> Maybe Text
gift_name   = Maybe Text
gift_name_
      , gram_amount :: SendGiftOnChainPurchaseOffer -> Maybe Int
gram_amount = Maybe Int
gram_amount_
      , duration :: SendGiftOnChainPurchaseOffer -> Maybe Int
duration    = Maybe Int
duration_
      }
        = String
"SendGiftOnChainPurchaseOffer"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"gift_name"   String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
gift_name_
          , String
"gram_amount" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
gram_amount_
          , String
"duration"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
duration_
          ]

instance AT.ToJSON SendGiftOnChainPurchaseOffer where
  toJSON :: SendGiftOnChainPurchaseOffer -> Value
toJSON
    SendGiftOnChainPurchaseOffer
      { gift_name :: SendGiftOnChainPurchaseOffer -> Maybe Text
gift_name   = Maybe Text
gift_name_
      , gram_amount :: SendGiftOnChainPurchaseOffer -> Maybe Int
gram_amount = Maybe Int
gram_amount_
      , duration :: SendGiftOnChainPurchaseOffer -> Maybe Int
duration    = Maybe Int
duration_
      }
        = [Pair] -> Value
A.object
          [ Key
"@type"       Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"sendGiftOnChainPurchaseOffer"
          , Key
"gift_name"   Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
gift_name_
          , Key
"gram_amount" Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (Int -> Value) -> Maybe Int -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Value
I.writeInt64  Maybe Int
gram_amount_
          , Key
"duration"    Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
duration_
          ]

defaultSendGiftOnChainPurchaseOffer :: SendGiftOnChainPurchaseOffer
defaultSendGiftOnChainPurchaseOffer :: SendGiftOnChainPurchaseOffer
defaultSendGiftOnChainPurchaseOffer =
  SendGiftOnChainPurchaseOffer
    { gift_name :: Maybe Text
gift_name   = Maybe Text
forall a. Maybe a
Nothing
    , gram_amount :: Maybe Int
gram_amount = Maybe Int
forall a. Maybe a
Nothing
    , duration :: Maybe Int
duration    = Maybe Int
forall a. Maybe a
Nothing
    }