module TD.Query.SearchGiftsForResale
  (SearchGiftsForResale(..)
  , defaultSearchGiftsForResale
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.GiftForResaleOrder as GiftForResaleOrder
import qualified TD.Data.UpgradedGiftAttributeId as UpgradedGiftAttributeId
import qualified Data.Text as T

-- | Returns upgraded gifts that can be bought from other owners using sendResoldGift or getGiftOnChainPurchaseTransaction. Returns 'TD.Data.GiftsForResale.GiftsForResale'
data SearchGiftsForResale
  = SearchGiftsForResale
    { SearchGiftsForResale -> Maybe Int
gift_id      :: Maybe Int                                               -- ^ Identifier of the regular gift that was upgraded to a unique gift
    , SearchGiftsForResale -> Maybe GiftForResaleOrder
order        :: Maybe GiftForResaleOrder.GiftForResaleOrder             -- ^ Order in which the results will be sorted
    , SearchGiftsForResale -> Maybe Bool
for_crafting :: Maybe Bool                                              -- ^ Pass true to get only gifts suitable for crafting
    , SearchGiftsForResale -> Maybe Bool
for_stars    :: Maybe Bool                                              -- ^ Pass true to get gifts that can be bought using Telegram Stars. If none of for_stars, for_grams, and for_fragment is true, then gifts that can be bought using Telegram Stars or TON Grams are returned, except gifts sold on-chain. The filter must be shown only if getOption("show_gift_resale_star_filter") is true and must be selected by default if getOption("select_gift_resale_star_filter_by_default") is true
    , SearchGiftsForResale -> Maybe Bool
for_grams    :: Maybe Bool                                              -- ^ Pass true to get gifts that can be bought using TON Grams, including gifts sold on-chain using a fixed-price sale contract if getOption("can_buy_on_chain_fixed_price_gifts") is true. The filter must be shown only if getOption("show_gift_resale_gram_filter") is true and must be selected by default if getOption("select_gift_resale_gram_filter_by_default") is true
    , SearchGiftsForResale -> Maybe Bool
for_fragment :: Maybe Bool                                              -- ^ Pass true to get gifts sold on-chain on Fragment; may be true only if getOption("can_buy_on_chain_gifts") is true. Must be false if for_crafting is true or if the gift will be bought for another user or a channel chat
    , SearchGiftsForResale -> Maybe [UpgradedGiftAttributeId]
attributes   :: Maybe [UpgradedGiftAttributeId.UpgradedGiftAttributeId] -- ^ Attributes used to filter gifts. If multiple attributes of the same type are specified, then all of them are allowed. If no attributes of a specific type are specified, then all values for this attribute type are allowed
    , SearchGiftsForResale -> Maybe Text
offset       :: Maybe T.Text                                            -- ^ Offset of the first entry to return as received from the previous request with the same order and attributes; use an empty string to get the first chunk of results
    , SearchGiftsForResale -> Maybe Int
limit        :: Maybe Int                                               -- ^ The maximum number of gifts to return
    }
  deriving (SearchGiftsForResale -> SearchGiftsForResale -> Bool
(SearchGiftsForResale -> SearchGiftsForResale -> Bool)
-> (SearchGiftsForResale -> SearchGiftsForResale -> Bool)
-> Eq SearchGiftsForResale
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SearchGiftsForResale -> SearchGiftsForResale -> Bool
== :: SearchGiftsForResale -> SearchGiftsForResale -> Bool
$c/= :: SearchGiftsForResale -> SearchGiftsForResale -> Bool
/= :: SearchGiftsForResale -> SearchGiftsForResale -> Bool
Eq, Int -> SearchGiftsForResale -> ShowS
[SearchGiftsForResale] -> ShowS
SearchGiftsForResale -> String
(Int -> SearchGiftsForResale -> ShowS)
-> (SearchGiftsForResale -> String)
-> ([SearchGiftsForResale] -> ShowS)
-> Show SearchGiftsForResale
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SearchGiftsForResale -> ShowS
showsPrec :: Int -> SearchGiftsForResale -> ShowS
$cshow :: SearchGiftsForResale -> String
show :: SearchGiftsForResale -> String
$cshowList :: [SearchGiftsForResale] -> ShowS
showList :: [SearchGiftsForResale] -> ShowS
Show)

instance I.ShortShow SearchGiftsForResale where
  shortShow :: SearchGiftsForResale -> String
shortShow
    SearchGiftsForResale
      { gift_id :: SearchGiftsForResale -> Maybe Int
gift_id      = Maybe Int
gift_id_
      , order :: SearchGiftsForResale -> Maybe GiftForResaleOrder
order        = Maybe GiftForResaleOrder
order_
      , for_crafting :: SearchGiftsForResale -> Maybe Bool
for_crafting = Maybe Bool
for_crafting_
      , for_stars :: SearchGiftsForResale -> Maybe Bool
for_stars    = Maybe Bool
for_stars_
      , for_grams :: SearchGiftsForResale -> Maybe Bool
for_grams    = Maybe Bool
for_grams_
      , for_fragment :: SearchGiftsForResale -> Maybe Bool
for_fragment = Maybe Bool
for_fragment_
      , attributes :: SearchGiftsForResale -> Maybe [UpgradedGiftAttributeId]
attributes   = Maybe [UpgradedGiftAttributeId]
attributes_
      , offset :: SearchGiftsForResale -> Maybe Text
offset       = Maybe Text
offset_
      , limit :: SearchGiftsForResale -> Maybe Int
limit        = Maybe Int
limit_
      }
        = String
"SearchGiftsForResale"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"gift_id"      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
gift_id_
          , String
"order"        String -> Maybe GiftForResaleOrder -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe GiftForResaleOrder
order_
          , String
"for_crafting" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
for_crafting_
          , String
"for_stars"    String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
for_stars_
          , String
"for_grams"    String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
for_grams_
          , String
"for_fragment" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
for_fragment_
          , String
"attributes"   String -> Maybe [UpgradedGiftAttributeId] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [UpgradedGiftAttributeId]
attributes_
          , String
"offset"       String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
offset_
          , String
"limit"        String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
limit_
          ]

instance AT.ToJSON SearchGiftsForResale where
  toJSON :: SearchGiftsForResale -> Value
toJSON
    SearchGiftsForResale
      { gift_id :: SearchGiftsForResale -> Maybe Int
gift_id      = Maybe Int
gift_id_
      , order :: SearchGiftsForResale -> Maybe GiftForResaleOrder
order        = Maybe GiftForResaleOrder
order_
      , for_crafting :: SearchGiftsForResale -> Maybe Bool
for_crafting = Maybe Bool
for_crafting_
      , for_stars :: SearchGiftsForResale -> Maybe Bool
for_stars    = Maybe Bool
for_stars_
      , for_grams :: SearchGiftsForResale -> Maybe Bool
for_grams    = Maybe Bool
for_grams_
      , for_fragment :: SearchGiftsForResale -> Maybe Bool
for_fragment = Maybe Bool
for_fragment_
      , attributes :: SearchGiftsForResale -> Maybe [UpgradedGiftAttributeId]
attributes   = Maybe [UpgradedGiftAttributeId]
attributes_
      , offset :: SearchGiftsForResale -> Maybe Text
offset       = Maybe Text
offset_
      , limit :: SearchGiftsForResale -> Maybe Int
limit        = Maybe Int
limit_
      }
        = [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
"searchGiftsForResale"
          , Key
"gift_id"      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
gift_id_
          , Key
"order"        Key -> Maybe GiftForResaleOrder -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe GiftForResaleOrder
order_
          , Key
"for_crafting" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
for_crafting_
          , Key
"for_stars"    Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
for_stars_
          , Key
"for_grams"    Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
for_grams_
          , Key
"for_fragment" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
for_fragment_
          , Key
"attributes"   Key -> Maybe [UpgradedGiftAttributeId] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [UpgradedGiftAttributeId]
attributes_
          , Key
"offset"       Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
offset_
          , Key
"limit"        Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
limit_
          ]

defaultSearchGiftsForResale :: SearchGiftsForResale
defaultSearchGiftsForResale :: SearchGiftsForResale
defaultSearchGiftsForResale =
  SearchGiftsForResale
    { gift_id :: Maybe Int
gift_id      = Maybe Int
forall a. Maybe a
Nothing
    , order :: Maybe GiftForResaleOrder
order        = Maybe GiftForResaleOrder
forall a. Maybe a
Nothing
    , for_crafting :: Maybe Bool
for_crafting = Maybe Bool
forall a. Maybe a
Nothing
    , for_stars :: Maybe Bool
for_stars    = Maybe Bool
forall a. Maybe a
Nothing
    , for_grams :: Maybe Bool
for_grams    = Maybe Bool
forall a. Maybe a
Nothing
    , for_fragment :: Maybe Bool
for_fragment = Maybe Bool
forall a. Maybe a
Nothing
    , attributes :: Maybe [UpgradedGiftAttributeId]
attributes   = Maybe [UpgradedGiftAttributeId]
forall a. Maybe a
Nothing
    , offset :: Maybe Text
offset       = Maybe Text
forall a. Maybe a
Nothing
    , limit :: Maybe Int
limit        = Maybe Int
forall a. Maybe a
Nothing
    }