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. 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 [UpgradedGiftAttributeId]
attributes :: Maybe [UpgradedGiftAttributeId.UpgradedGiftAttributeId] -- ^ Attributes used to filter received gifts. If multiple attributes of the same type are specified, then all of them are allowed. If none attributes of 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 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_
      , 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
"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_
      , 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
"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
    , 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
    }