module TD.Query.GetGiftOnChainPurchaseTransaction
  (GetGiftOnChainPurchaseTransaction(..)
  , defaultGetGiftOnChainPurchaseTransaction
  ) 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.MessageSender as MessageSender
import qualified TD.Data.FormattedText as FormattedText

-- | Returns a transaction that must be sent from the TON wallet of the current user to buy an upgraded gift for which upgradedGift.uses_on_chain_resale is true; can be used only if getOption("can_use_ton_wallet"). Gifts for which giftResaleParameters.is_fixed_on_chain is true can be bought only if getOption("can_buy_on_chain_fixed_price_gifts") is true, and other gifts can be bought only if getOption("can_buy_on_chain_gifts") is true. The type of the returned transaction depends on the type of the sale. The gift will be received by the new owner after the transaction is executed on the TON blockchain. If the gift is bought for the current user, then it will be received by the TON wallet of the current user, and will be shown on the user's profile page if it is still in the wallet. Returns 'TD.Data.GiftOnChainSaleTransaction.GiftOnChainSaleTransaction'
data GetGiftOnChainPurchaseTransaction
  = GetGiftOnChainPurchaseTransaction
    { GetGiftOnChainPurchaseTransaction -> Maybe Text
gift_name   :: Maybe T.Text                      -- ^ Name of the upgraded gift
    , GetGiftOnChainPurchaseTransaction -> Maybe MessageSender
owner_id    :: Maybe MessageSender.MessageSender -- ^ Identifier of the user or the channel chat that will receive the gift; must be the current user if giftResaleParameters.is_fixed_on_chain is false
    , GetGiftOnChainPurchaseTransaction -> Maybe Int
gram_amount :: Maybe Int                         -- ^ The price of the gift, in the smallest units of TON Grams; must be equal to giftResaleParameters.gram_amount. The request fails with the error "STARGIFT_ONCHAIN_PRICE_CHANGED" if the price has changed. The amount that will be paid can be greater than the price because of blockchain fees
    , GetGiftOnChainPurchaseTransaction -> Maybe FormattedText
text        :: Maybe FormattedText.FormattedText -- ^ Text to show along with the gift; 0-getOption("gift_text_length_max") characters. Only Bold, Italic, Underline, Strikethrough, Spoiler, CustomEmoji, and DateTime entities are allowed. Must be empty if the receiver enabled paid messages and the price of the gift is less than the price of a paid message to the user
    , GetGiftOnChainPurchaseTransaction -> Maybe Bool
is_private  :: Maybe Bool                        -- ^ Pass true to show the gift text and sender only to the gift receiver; otherwise, everyone will be able to see them
    }
  deriving (GetGiftOnChainPurchaseTransaction
-> GetGiftOnChainPurchaseTransaction -> Bool
(GetGiftOnChainPurchaseTransaction
 -> GetGiftOnChainPurchaseTransaction -> Bool)
-> (GetGiftOnChainPurchaseTransaction
    -> GetGiftOnChainPurchaseTransaction -> Bool)
-> Eq GetGiftOnChainPurchaseTransaction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetGiftOnChainPurchaseTransaction
-> GetGiftOnChainPurchaseTransaction -> Bool
== :: GetGiftOnChainPurchaseTransaction
-> GetGiftOnChainPurchaseTransaction -> Bool
$c/= :: GetGiftOnChainPurchaseTransaction
-> GetGiftOnChainPurchaseTransaction -> Bool
/= :: GetGiftOnChainPurchaseTransaction
-> GetGiftOnChainPurchaseTransaction -> Bool
Eq, Int -> GetGiftOnChainPurchaseTransaction -> ShowS
[GetGiftOnChainPurchaseTransaction] -> ShowS
GetGiftOnChainPurchaseTransaction -> String
(Int -> GetGiftOnChainPurchaseTransaction -> ShowS)
-> (GetGiftOnChainPurchaseTransaction -> String)
-> ([GetGiftOnChainPurchaseTransaction] -> ShowS)
-> Show GetGiftOnChainPurchaseTransaction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetGiftOnChainPurchaseTransaction -> ShowS
showsPrec :: Int -> GetGiftOnChainPurchaseTransaction -> ShowS
$cshow :: GetGiftOnChainPurchaseTransaction -> String
show :: GetGiftOnChainPurchaseTransaction -> String
$cshowList :: [GetGiftOnChainPurchaseTransaction] -> ShowS
showList :: [GetGiftOnChainPurchaseTransaction] -> ShowS
Show)

instance I.ShortShow GetGiftOnChainPurchaseTransaction where
  shortShow :: GetGiftOnChainPurchaseTransaction -> String
shortShow
    GetGiftOnChainPurchaseTransaction
      { gift_name :: GetGiftOnChainPurchaseTransaction -> Maybe Text
gift_name   = Maybe Text
gift_name_
      , owner_id :: GetGiftOnChainPurchaseTransaction -> Maybe MessageSender
owner_id    = Maybe MessageSender
owner_id_
      , gram_amount :: GetGiftOnChainPurchaseTransaction -> Maybe Int
gram_amount = Maybe Int
gram_amount_
      , text :: GetGiftOnChainPurchaseTransaction -> Maybe FormattedText
text        = Maybe FormattedText
text_
      , is_private :: GetGiftOnChainPurchaseTransaction -> Maybe Bool
is_private  = Maybe Bool
is_private_
      }
        = String
"GetGiftOnChainPurchaseTransaction"
          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
"owner_id"    String -> Maybe MessageSender -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSender
owner_id_
          , String
"gram_amount" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
gram_amount_
          , String
"text"        String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
text_
          , String
"is_private"  String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_private_
          ]

instance AT.ToJSON GetGiftOnChainPurchaseTransaction where
  toJSON :: GetGiftOnChainPurchaseTransaction -> Value
toJSON
    GetGiftOnChainPurchaseTransaction
      { gift_name :: GetGiftOnChainPurchaseTransaction -> Maybe Text
gift_name   = Maybe Text
gift_name_
      , owner_id :: GetGiftOnChainPurchaseTransaction -> Maybe MessageSender
owner_id    = Maybe MessageSender
owner_id_
      , gram_amount :: GetGiftOnChainPurchaseTransaction -> Maybe Int
gram_amount = Maybe Int
gram_amount_
      , text :: GetGiftOnChainPurchaseTransaction -> Maybe FormattedText
text        = Maybe FormattedText
text_
      , is_private :: GetGiftOnChainPurchaseTransaction -> Maybe Bool
is_private  = Maybe Bool
is_private_
      }
        = [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
"getGiftOnChainPurchaseTransaction"
          , 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
"owner_id"    Key -> Maybe MessageSender -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe MessageSender
owner_id_
          , 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
"text"        Key -> Maybe FormattedText -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe FormattedText
text_
          , Key
"is_private"  Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_private_
          ]

defaultGetGiftOnChainPurchaseTransaction :: GetGiftOnChainPurchaseTransaction
defaultGetGiftOnChainPurchaseTransaction :: GetGiftOnChainPurchaseTransaction
defaultGetGiftOnChainPurchaseTransaction =
  GetGiftOnChainPurchaseTransaction
    { gift_name :: Maybe Text
gift_name   = Maybe Text
forall a. Maybe a
Nothing
    , owner_id :: Maybe MessageSender
owner_id    = Maybe MessageSender
forall a. Maybe a
Nothing
    , gram_amount :: Maybe Int
gram_amount = Maybe Int
forall a. Maybe a
Nothing
    , text :: Maybe FormattedText
text        = Maybe FormattedText
forall a. Maybe a
Nothing
    , is_private :: Maybe Bool
is_private  = Maybe Bool
forall a. Maybe a
Nothing
    }