module TD.Data.UpgradedGift
  (UpgradedGift(..)) 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.UpgradedGiftModel as UpgradedGiftModel
import qualified TD.Data.UpgradedGiftSymbol as UpgradedGiftSymbol
import qualified TD.Data.UpgradedGiftBackdrop as UpgradedGiftBackdrop
import qualified TD.Data.UpgradedGiftOriginalDetails as UpgradedGiftOriginalDetails
import qualified TD.Data.UpgradedGiftColors as UpgradedGiftColors
import qualified TD.Data.GiftResaleParameters as GiftResaleParameters

data UpgradedGift
  = UpgradedGift -- ^ Describes an upgraded gift that can be transferred to another owner or transferred to the TON blockchain as an NFT
    { UpgradedGift -> Maybe Int
_id                  :: Maybe Int                                                     -- ^ Unique identifier of the gift
    , UpgradedGift -> Maybe Int
regular_gift_id      :: Maybe Int                                                     -- ^ Unique identifier of the regular gift from which the gift was upgraded; may be 0 for short period of time for old gifts from database
    , UpgradedGift -> Maybe Int
publisher_chat_id    :: Maybe Int                                                     -- ^ Identifier of the chat that published the gift; 0 if none
    , UpgradedGift -> Maybe Text
title                :: Maybe T.Text                                                  -- ^ The title of the upgraded gift
    , UpgradedGift -> Maybe Text
name                 :: Maybe T.Text                                                  -- ^ Unique name of the upgraded gift that can be used with internalLinkTypeUpgradedGift or sendResoldGift
    , UpgradedGift -> Maybe Int
number               :: Maybe Int                                                     -- ^ Unique number of the upgraded gift among gifts upgraded from the same gift
    , UpgradedGift -> Maybe Int
total_upgraded_count :: Maybe Int                                                     -- ^ Total number of gifts that were upgraded from the same gift
    , UpgradedGift -> Maybe Int
max_upgraded_count   :: Maybe Int                                                     -- ^ The maximum number of gifts that can be upgraded from the same gift
    , UpgradedGift -> Maybe Bool
is_premium           :: Maybe Bool                                                    -- ^ True, if the original gift could have been bought only by Telegram Premium subscribers
    , UpgradedGift -> Maybe Bool
is_theme_available   :: Maybe Bool                                                    -- ^ True, if the gift can be used to set a theme in a chat
    , UpgradedGift -> Maybe Int
used_theme_chat_id   :: Maybe Int                                                     -- ^ Identifier of the chat for which the gift is used to set a theme; 0 if none or the gift isn't owned by the current user
    , UpgradedGift -> Maybe MessageSender
host_id              :: Maybe MessageSender.MessageSender                             -- ^ Identifier of the user or the chat to which the upgraded gift was assigned from blockchain; may be null if none or unknown
    , UpgradedGift -> Maybe MessageSender
owner_id             :: Maybe MessageSender.MessageSender                             -- ^ Identifier of the user or the chat that owns the upgraded gift; may be null if none or unknown
    , UpgradedGift -> Maybe Text
owner_address        :: Maybe T.Text                                                  -- ^ Address of the gift NFT owner in TON blockchain; may be empty if none. Append the address to getOption("ton_blockchain_explorer_url") to get a link with information about the address
    , UpgradedGift -> Maybe Text
owner_name           :: Maybe T.Text                                                  -- ^ Name of the owner for the case when owner identifier and address aren't known
    , UpgradedGift -> Maybe Text
gift_address         :: Maybe T.Text                                                  -- ^ Address of the gift NFT in TON blockchain; may be empty if none. Append the address to getOption("ton_blockchain_explorer_url") to get a link with information about the address
    , UpgradedGift -> Maybe UpgradedGiftModel
model                :: Maybe UpgradedGiftModel.UpgradedGiftModel                     -- ^ Model of the upgraded gift
    , UpgradedGift -> Maybe UpgradedGiftSymbol
symbol               :: Maybe UpgradedGiftSymbol.UpgradedGiftSymbol                   -- ^ Symbol of the upgraded gift
    , UpgradedGift -> Maybe UpgradedGiftBackdrop
backdrop             :: Maybe UpgradedGiftBackdrop.UpgradedGiftBackdrop               -- ^ Backdrop of the upgraded gift
    , UpgradedGift -> Maybe UpgradedGiftOriginalDetails
original_details     :: Maybe UpgradedGiftOriginalDetails.UpgradedGiftOriginalDetails -- ^ Information about the originally sent gift; may be null if unknown
    , UpgradedGift -> Maybe UpgradedGiftColors
colors               :: Maybe UpgradedGiftColors.UpgradedGiftColors                   -- ^ Colors that can be set for user's name, background of empty chat photo, replies to messages and link previews; may be null if none
    , UpgradedGift -> Maybe GiftResaleParameters
resale_parameters    :: Maybe GiftResaleParameters.GiftResaleParameters               -- ^ Resale parameters of the gift; may be null if resale isn't possible
    , UpgradedGift -> Maybe Text
value_currency       :: Maybe T.Text                                                  -- ^ ISO 4217 currency code of the currency in which value of the gift is represented; may be empty if unavailable
    , UpgradedGift -> Maybe Int
value_amount         :: Maybe Int                                                     -- ^ Estimated value of the gift; in the smallest units of the currency; 0 if unavailable
    }
  deriving (UpgradedGift -> UpgradedGift -> Bool
(UpgradedGift -> UpgradedGift -> Bool)
-> (UpgradedGift -> UpgradedGift -> Bool) -> Eq UpgradedGift
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UpgradedGift -> UpgradedGift -> Bool
== :: UpgradedGift -> UpgradedGift -> Bool
$c/= :: UpgradedGift -> UpgradedGift -> Bool
/= :: UpgradedGift -> UpgradedGift -> Bool
Eq, Int -> UpgradedGift -> ShowS
[UpgradedGift] -> ShowS
UpgradedGift -> String
(Int -> UpgradedGift -> ShowS)
-> (UpgradedGift -> String)
-> ([UpgradedGift] -> ShowS)
-> Show UpgradedGift
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UpgradedGift -> ShowS
showsPrec :: Int -> UpgradedGift -> ShowS
$cshow :: UpgradedGift -> String
show :: UpgradedGift -> String
$cshowList :: [UpgradedGift] -> ShowS
showList :: [UpgradedGift] -> ShowS
Show)

instance I.ShortShow UpgradedGift where
  shortShow :: UpgradedGift -> String
shortShow UpgradedGift
    { _id :: UpgradedGift -> Maybe Int
_id                  = Maybe Int
_id_
    , regular_gift_id :: UpgradedGift -> Maybe Int
regular_gift_id      = Maybe Int
regular_gift_id_
    , publisher_chat_id :: UpgradedGift -> Maybe Int
publisher_chat_id    = Maybe Int
publisher_chat_id_
    , title :: UpgradedGift -> Maybe Text
title                = Maybe Text
title_
    , name :: UpgradedGift -> Maybe Text
name                 = Maybe Text
name_
    , number :: UpgradedGift -> Maybe Int
number               = Maybe Int
number_
    , total_upgraded_count :: UpgradedGift -> Maybe Int
total_upgraded_count = Maybe Int
total_upgraded_count_
    , max_upgraded_count :: UpgradedGift -> Maybe Int
max_upgraded_count   = Maybe Int
max_upgraded_count_
    , is_premium :: UpgradedGift -> Maybe Bool
is_premium           = Maybe Bool
is_premium_
    , is_theme_available :: UpgradedGift -> Maybe Bool
is_theme_available   = Maybe Bool
is_theme_available_
    , used_theme_chat_id :: UpgradedGift -> Maybe Int
used_theme_chat_id   = Maybe Int
used_theme_chat_id_
    , host_id :: UpgradedGift -> Maybe MessageSender
host_id              = Maybe MessageSender
host_id_
    , owner_id :: UpgradedGift -> Maybe MessageSender
owner_id             = Maybe MessageSender
owner_id_
    , owner_address :: UpgradedGift -> Maybe Text
owner_address        = Maybe Text
owner_address_
    , owner_name :: UpgradedGift -> Maybe Text
owner_name           = Maybe Text
owner_name_
    , gift_address :: UpgradedGift -> Maybe Text
gift_address         = Maybe Text
gift_address_
    , model :: UpgradedGift -> Maybe UpgradedGiftModel
model                = Maybe UpgradedGiftModel
model_
    , symbol :: UpgradedGift -> Maybe UpgradedGiftSymbol
symbol               = Maybe UpgradedGiftSymbol
symbol_
    , backdrop :: UpgradedGift -> Maybe UpgradedGiftBackdrop
backdrop             = Maybe UpgradedGiftBackdrop
backdrop_
    , original_details :: UpgradedGift -> Maybe UpgradedGiftOriginalDetails
original_details     = Maybe UpgradedGiftOriginalDetails
original_details_
    , colors :: UpgradedGift -> Maybe UpgradedGiftColors
colors               = Maybe UpgradedGiftColors
colors_
    , resale_parameters :: UpgradedGift -> Maybe GiftResaleParameters
resale_parameters    = Maybe GiftResaleParameters
resale_parameters_
    , value_currency :: UpgradedGift -> Maybe Text
value_currency       = Maybe Text
value_currency_
    , value_amount :: UpgradedGift -> Maybe Int
value_amount         = Maybe Int
value_amount_
    }
      = String
"UpgradedGift"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_id"                  String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
        , String
"regular_gift_id"      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
regular_gift_id_
        , String
"publisher_chat_id"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
publisher_chat_id_
        , String
"title"                String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
        , String
"name"                 String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
        , String
"number"               String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
number_
        , String
"total_upgraded_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_upgraded_count_
        , String
"max_upgraded_count"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
max_upgraded_count_
        , String
"is_premium"           String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_premium_
        , String
"is_theme_available"   String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_theme_available_
        , String
"used_theme_chat_id"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
used_theme_chat_id_
        , String
"host_id"              String -> Maybe MessageSender -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSender
host_id_
        , String
"owner_id"             String -> Maybe MessageSender -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSender
owner_id_
        , String
"owner_address"        String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
owner_address_
        , String
"owner_name"           String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
owner_name_
        , String
"gift_address"         String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
gift_address_
        , String
"model"                String -> Maybe UpgradedGiftModel -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe UpgradedGiftModel
model_
        , String
"symbol"               String -> Maybe UpgradedGiftSymbol -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe UpgradedGiftSymbol
symbol_
        , String
"backdrop"             String -> Maybe UpgradedGiftBackdrop -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe UpgradedGiftBackdrop
backdrop_
        , String
"original_details"     String -> Maybe UpgradedGiftOriginalDetails -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe UpgradedGiftOriginalDetails
original_details_
        , String
"colors"               String -> Maybe UpgradedGiftColors -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe UpgradedGiftColors
colors_
        , String
"resale_parameters"    String -> Maybe GiftResaleParameters -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe GiftResaleParameters
resale_parameters_
        , String
"value_currency"       String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
value_currency_
        , String
"value_amount"         String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
value_amount_
        ]

instance AT.FromJSON UpgradedGift where
  parseJSON :: Value -> Parser UpgradedGift
parseJSON v :: Value
v@(AT.Object Object
obj) = do
    String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String

    case String
t of
      String
"upgradedGift" -> Value -> Parser UpgradedGift
parseUpgradedGift Value
v
      String
_              -> Parser UpgradedGift
forall a. Monoid a => a
mempty
    
    where
      parseUpgradedGift :: A.Value -> AT.Parser UpgradedGift
      parseUpgradedGift :: Value -> Parser UpgradedGift
parseUpgradedGift = String
-> (Object -> Parser UpgradedGift) -> Value -> Parser UpgradedGift
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UpgradedGift" ((Object -> Parser UpgradedGift) -> Value -> Parser UpgradedGift)
-> (Object -> Parser UpgradedGift) -> Value -> Parser UpgradedGift
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
_id_                  <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"id"
        Maybe Int
regular_gift_id_      <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"regular_gift_id"
        Maybe Int
publisher_chat_id_    <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"publisher_chat_id"
        Maybe Text
title_                <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"title"
        Maybe Text
name_                 <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"name"
        Maybe Int
number_               <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"number"
        Maybe Int
total_upgraded_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"total_upgraded_count"
        Maybe Int
max_upgraded_count_   <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"max_upgraded_count"
        Maybe Bool
is_premium_           <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"is_premium"
        Maybe Bool
is_theme_available_   <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"is_theme_available"
        Maybe Int
used_theme_chat_id_   <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"used_theme_chat_id"
        Maybe MessageSender
host_id_              <- Object
o Object -> Key -> Parser (Maybe MessageSender)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"host_id"
        Maybe MessageSender
owner_id_             <- Object
o Object -> Key -> Parser (Maybe MessageSender)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"owner_id"
        Maybe Text
owner_address_        <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"owner_address"
        Maybe Text
owner_name_           <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"owner_name"
        Maybe Text
gift_address_         <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"gift_address"
        Maybe UpgradedGiftModel
model_                <- Object
o Object -> Key -> Parser (Maybe UpgradedGiftModel)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"model"
        Maybe UpgradedGiftSymbol
symbol_               <- Object
o Object -> Key -> Parser (Maybe UpgradedGiftSymbol)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"symbol"
        Maybe UpgradedGiftBackdrop
backdrop_             <- Object
o Object -> Key -> Parser (Maybe UpgradedGiftBackdrop)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"backdrop"
        Maybe UpgradedGiftOriginalDetails
original_details_     <- Object
o Object -> Key -> Parser (Maybe UpgradedGiftOriginalDetails)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"original_details"
        Maybe UpgradedGiftColors
colors_               <- Object
o Object -> Key -> Parser (Maybe UpgradedGiftColors)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"colors"
        Maybe GiftResaleParameters
resale_parameters_    <- Object
o Object -> Key -> Parser (Maybe GiftResaleParameters)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"resale_parameters"
        Maybe Text
value_currency_       <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"value_currency"
        Maybe Int
value_amount_         <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"value_amount"
        UpgradedGift -> Parser UpgradedGift
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UpgradedGift -> Parser UpgradedGift)
-> UpgradedGift -> Parser UpgradedGift
forall a b. (a -> b) -> a -> b
$ UpgradedGift
          { _id :: Maybe Int
_id                  = Maybe Int
_id_
          , regular_gift_id :: Maybe Int
regular_gift_id      = Maybe Int
regular_gift_id_
          , publisher_chat_id :: Maybe Int
publisher_chat_id    = Maybe Int
publisher_chat_id_
          , title :: Maybe Text
title                = Maybe Text
title_
          , name :: Maybe Text
name                 = Maybe Text
name_
          , number :: Maybe Int
number               = Maybe Int
number_
          , total_upgraded_count :: Maybe Int
total_upgraded_count = Maybe Int
total_upgraded_count_
          , max_upgraded_count :: Maybe Int
max_upgraded_count   = Maybe Int
max_upgraded_count_
          , is_premium :: Maybe Bool
is_premium           = Maybe Bool
is_premium_
          , is_theme_available :: Maybe Bool
is_theme_available   = Maybe Bool
is_theme_available_
          , used_theme_chat_id :: Maybe Int
used_theme_chat_id   = Maybe Int
used_theme_chat_id_
          , host_id :: Maybe MessageSender
host_id              = Maybe MessageSender
host_id_
          , owner_id :: Maybe MessageSender
owner_id             = Maybe MessageSender
owner_id_
          , owner_address :: Maybe Text
owner_address        = Maybe Text
owner_address_
          , owner_name :: Maybe Text
owner_name           = Maybe Text
owner_name_
          , gift_address :: Maybe Text
gift_address         = Maybe Text
gift_address_
          , model :: Maybe UpgradedGiftModel
model                = Maybe UpgradedGiftModel
model_
          , symbol :: Maybe UpgradedGiftSymbol
symbol               = Maybe UpgradedGiftSymbol
symbol_
          , backdrop :: Maybe UpgradedGiftBackdrop
backdrop             = Maybe UpgradedGiftBackdrop
backdrop_
          , original_details :: Maybe UpgradedGiftOriginalDetails
original_details     = Maybe UpgradedGiftOriginalDetails
original_details_
          , colors :: Maybe UpgradedGiftColors
colors               = Maybe UpgradedGiftColors
colors_
          , resale_parameters :: Maybe GiftResaleParameters
resale_parameters    = Maybe GiftResaleParameters
resale_parameters_
          , value_currency :: Maybe Text
value_currency       = Maybe Text
value_currency_
          , value_amount :: Maybe Int
value_amount         = Maybe Int
value_amount_
          }
  parseJSON Value
_ = Parser UpgradedGift
forall a. Monoid a => a
mempty