module TD.Query.GetGiftOnChainListingTransaction
  (GetGiftOnChainListingTransaction(..)
  , defaultGetGiftOnChainListingTransaction
  ) 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

-- | Returns a transaction that must be sent from the TON wallet of the current user to put an upgraded gift for which upgradedGift.uses_on_chain_resale is true up for sale, or to change the price of a gift for which giftResaleParameters.is_fixed_on_chain and giftResaleParameters.can_be_managed are true; can be used only if getOption("can_use_ton_wallet"). The type of the sale is chosen by the server. The gift is put up for sale only after the transaction is executed on the TON blockchain and the sale smart contract confirms that it has received the gift. The price of the gift minus the fee specified in upgradedGift.fee_basis_points will be received by the TON wallet of the current user when the gift is sold. If giftResaleParameters.is_fixed_on_chain is false, then the current sale must be canceled first using getGiftOnChainDelistingTransaction to change the price of the gift. Returns 'TD.Data.GiftOnChainSaleTransaction.GiftOnChainSaleTransaction'
data GetGiftOnChainListingTransaction
  = GetGiftOnChainListingTransaction
    { GetGiftOnChainListingTransaction -> Maybe Text
gift_name   :: Maybe T.Text -- ^ Name of the upgraded gift
    , GetGiftOnChainListingTransaction -> Maybe Int
gram_amount :: Maybe Int    -- ^ The price of the gift that the buyer will pay, in the smallest units of TON Grams. The price in 1/100 of a Gram must be in the range getOption("gift_resale_gram_cent_count_min")-getOption("gift_resale_gram_cent_count_max")
    }
  deriving (GetGiftOnChainListingTransaction
-> GetGiftOnChainListingTransaction -> Bool
(GetGiftOnChainListingTransaction
 -> GetGiftOnChainListingTransaction -> Bool)
-> (GetGiftOnChainListingTransaction
    -> GetGiftOnChainListingTransaction -> Bool)
-> Eq GetGiftOnChainListingTransaction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetGiftOnChainListingTransaction
-> GetGiftOnChainListingTransaction -> Bool
== :: GetGiftOnChainListingTransaction
-> GetGiftOnChainListingTransaction -> Bool
$c/= :: GetGiftOnChainListingTransaction
-> GetGiftOnChainListingTransaction -> Bool
/= :: GetGiftOnChainListingTransaction
-> GetGiftOnChainListingTransaction -> Bool
Eq, Int -> GetGiftOnChainListingTransaction -> ShowS
[GetGiftOnChainListingTransaction] -> ShowS
GetGiftOnChainListingTransaction -> String
(Int -> GetGiftOnChainListingTransaction -> ShowS)
-> (GetGiftOnChainListingTransaction -> String)
-> ([GetGiftOnChainListingTransaction] -> ShowS)
-> Show GetGiftOnChainListingTransaction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetGiftOnChainListingTransaction -> ShowS
showsPrec :: Int -> GetGiftOnChainListingTransaction -> ShowS
$cshow :: GetGiftOnChainListingTransaction -> String
show :: GetGiftOnChainListingTransaction -> String
$cshowList :: [GetGiftOnChainListingTransaction] -> ShowS
showList :: [GetGiftOnChainListingTransaction] -> ShowS
Show)

instance I.ShortShow GetGiftOnChainListingTransaction where
  shortShow :: GetGiftOnChainListingTransaction -> String
shortShow
    GetGiftOnChainListingTransaction
      { gift_name :: GetGiftOnChainListingTransaction -> Maybe Text
gift_name   = Maybe Text
gift_name_
      , gram_amount :: GetGiftOnChainListingTransaction -> Maybe Int
gram_amount = Maybe Int
gram_amount_
      }
        = String
"GetGiftOnChainListingTransaction"
          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_
          ]

instance AT.ToJSON GetGiftOnChainListingTransaction where
  toJSON :: GetGiftOnChainListingTransaction -> Value
toJSON
    GetGiftOnChainListingTransaction
      { gift_name :: GetGiftOnChainListingTransaction -> Maybe Text
gift_name   = Maybe Text
gift_name_
      , gram_amount :: GetGiftOnChainListingTransaction -> Maybe Int
gram_amount = Maybe Int
gram_amount_
      }
        = [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
"getGiftOnChainListingTransaction"
          , 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_
          ]

defaultGetGiftOnChainListingTransaction :: GetGiftOnChainListingTransaction
defaultGetGiftOnChainListingTransaction :: GetGiftOnChainListingTransaction
defaultGetGiftOnChainListingTransaction =
  GetGiftOnChainListingTransaction
    { 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
    }