module TD.Data.ReceivedGift
  (ReceivedGift(..)) 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
import qualified TD.Data.SentGift as SentGift

data ReceivedGift
  = ReceivedGift -- ^ Represents a gift received by a user or a chat
    { ReceivedGift -> Maybe Text
received_gift_id                 :: Maybe T.Text                      -- ^ Unique identifier of the received gift for the current user; only for the receiver of the gift
    , ReceivedGift -> Maybe MessageSender
sender_id                        :: Maybe MessageSender.MessageSender -- ^ Identifier of a user or a chat that sent the gift; may be null if unknown
    , ReceivedGift -> Maybe FormattedText
text                             :: Maybe FormattedText.FormattedText -- ^ Message added to the gift
    , ReceivedGift -> Maybe Bool
is_private                       :: Maybe Bool                        -- ^ True, if the sender and gift text are shown only to the gift receiver; otherwise, everyone are able to see them
    , ReceivedGift -> Maybe Bool
is_saved                         :: Maybe Bool                        -- ^ True, if the gift is displayed on the chat's profile page; only for the receiver of the gift
    , ReceivedGift -> Maybe Bool
is_pinned                        :: Maybe Bool                        -- ^ True, if the gift is pinned to the top of the chat's profile page
    , ReceivedGift -> Maybe Bool
can_be_upgraded                  :: Maybe Bool                        -- ^ True, if the gift is a regular gift that can be upgraded to a unique gift; only for the receiver of the gift
    , ReceivedGift -> Maybe Bool
can_be_transferred               :: Maybe Bool                        -- ^ True, if the gift is an upgraded gift that can be transferred to another owner; only for the receiver of the gift
    , ReceivedGift -> Maybe Bool
was_refunded                     :: Maybe Bool                        -- ^ True, if the gift was refunded and isn't available anymore
    , ReceivedGift -> Maybe Int
date                             :: Maybe Int                         -- ^ Point in time (Unix timestamp) when the gift was sent
    , ReceivedGift -> Maybe SentGift
gift                             :: Maybe SentGift.SentGift           -- ^ The gift
    , ReceivedGift -> Maybe [Int]
collection_ids                   :: Maybe [Int]                       -- ^ Identifiers of collections to which the gift is added; only for the receiver of the gift
    , ReceivedGift -> Maybe Int
sell_star_count                  :: Maybe Int                         -- ^ Number of Telegram Stars that can be claimed by the receiver instead of the regular gift; 0 if the gift can't be sold by the current user
    , ReceivedGift -> Maybe Int
prepaid_upgrade_star_count       :: Maybe Int                         -- ^ Number of Telegram Stars that were paid by the sender for the ability to upgrade the gift
    , ReceivedGift -> Maybe Bool
is_upgrade_separate              :: Maybe Bool                        -- ^ True, if the upgrade was bought after the gift was sent. In this case, prepaid upgrade cost must not be added to the gift cost
    , ReceivedGift -> Maybe Int
transfer_star_count              :: Maybe Int                         -- ^ Number of Telegram Stars that must be paid to transfer the upgraded gift; only for the receiver of the gift
    , ReceivedGift -> Maybe Int
drop_original_details_star_count :: Maybe Int                         -- ^ Number of Telegram Stars that must be paid to drop original details of the upgraded gift; 0 if not available; only for the receiver of the gift
    , ReceivedGift -> Maybe Int
next_transfer_date               :: Maybe Int                         -- ^ Point in time (Unix timestamp) when the gift can be transferred to another owner; can be in the past; 0 if the gift can be transferred immediately or transfer isn't possible; only for the receiver of the gift
    , ReceivedGift -> Maybe Int
next_resale_date                 :: Maybe Int                         -- ^ Point in time (Unix timestamp) when the gift can be resold to another user; can be in the past; 0 if the gift can't be resold; only for the receiver of the gift
    , ReceivedGift -> Maybe Int
export_date                      :: Maybe Int                         -- ^ Point in time (Unix timestamp) when the upgraded gift can be transferred to the TON blockchain as an NFT; can be in the past; 0 if NFT export isn't possible; only for the receiver of the gift
    , ReceivedGift -> Maybe Text
prepaid_upgrade_hash             :: Maybe T.Text                      -- ^ If non-empty, then the user can pay for an upgrade of the gift using buyGiftUpgrade
    }
  deriving (ReceivedGift -> ReceivedGift -> Bool
(ReceivedGift -> ReceivedGift -> Bool)
-> (ReceivedGift -> ReceivedGift -> Bool) -> Eq ReceivedGift
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReceivedGift -> ReceivedGift -> Bool
== :: ReceivedGift -> ReceivedGift -> Bool
$c/= :: ReceivedGift -> ReceivedGift -> Bool
/= :: ReceivedGift -> ReceivedGift -> Bool
Eq, Int -> ReceivedGift -> ShowS
[ReceivedGift] -> ShowS
ReceivedGift -> String
(Int -> ReceivedGift -> ShowS)
-> (ReceivedGift -> String)
-> ([ReceivedGift] -> ShowS)
-> Show ReceivedGift
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReceivedGift -> ShowS
showsPrec :: Int -> ReceivedGift -> ShowS
$cshow :: ReceivedGift -> String
show :: ReceivedGift -> String
$cshowList :: [ReceivedGift] -> ShowS
showList :: [ReceivedGift] -> ShowS
Show)

instance I.ShortShow ReceivedGift where
  shortShow :: ReceivedGift -> String
shortShow ReceivedGift
    { received_gift_id :: ReceivedGift -> Maybe Text
received_gift_id                 = Maybe Text
received_gift_id_
    , sender_id :: ReceivedGift -> Maybe MessageSender
sender_id                        = Maybe MessageSender
sender_id_
    , text :: ReceivedGift -> Maybe FormattedText
text                             = Maybe FormattedText
text_
    , is_private :: ReceivedGift -> Maybe Bool
is_private                       = Maybe Bool
is_private_
    , is_saved :: ReceivedGift -> Maybe Bool
is_saved                         = Maybe Bool
is_saved_
    , is_pinned :: ReceivedGift -> Maybe Bool
is_pinned                        = Maybe Bool
is_pinned_
    , can_be_upgraded :: ReceivedGift -> Maybe Bool
can_be_upgraded                  = Maybe Bool
can_be_upgraded_
    , can_be_transferred :: ReceivedGift -> Maybe Bool
can_be_transferred               = Maybe Bool
can_be_transferred_
    , was_refunded :: ReceivedGift -> Maybe Bool
was_refunded                     = Maybe Bool
was_refunded_
    , date :: ReceivedGift -> Maybe Int
date                             = Maybe Int
date_
    , gift :: ReceivedGift -> Maybe SentGift
gift                             = Maybe SentGift
gift_
    , collection_ids :: ReceivedGift -> Maybe [Int]
collection_ids                   = Maybe [Int]
collection_ids_
    , sell_star_count :: ReceivedGift -> Maybe Int
sell_star_count                  = Maybe Int
sell_star_count_
    , prepaid_upgrade_star_count :: ReceivedGift -> Maybe Int
prepaid_upgrade_star_count       = Maybe Int
prepaid_upgrade_star_count_
    , is_upgrade_separate :: ReceivedGift -> Maybe Bool
is_upgrade_separate              = Maybe Bool
is_upgrade_separate_
    , transfer_star_count :: ReceivedGift -> Maybe Int
transfer_star_count              = Maybe Int
transfer_star_count_
    , drop_original_details_star_count :: ReceivedGift -> Maybe Int
drop_original_details_star_count = Maybe Int
drop_original_details_star_count_
    , next_transfer_date :: ReceivedGift -> Maybe Int
next_transfer_date               = Maybe Int
next_transfer_date_
    , next_resale_date :: ReceivedGift -> Maybe Int
next_resale_date                 = Maybe Int
next_resale_date_
    , export_date :: ReceivedGift -> Maybe Int
export_date                      = Maybe Int
export_date_
    , prepaid_upgrade_hash :: ReceivedGift -> Maybe Text
prepaid_upgrade_hash             = Maybe Text
prepaid_upgrade_hash_
    }
      = String
"ReceivedGift"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"received_gift_id"                 String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
received_gift_id_
        , String
"sender_id"                        String -> Maybe MessageSender -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSender
sender_id_
        , 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_
        , String
"is_saved"                         String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_saved_
        , String
"is_pinned"                        String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_pinned_
        , String
"can_be_upgraded"                  String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_be_upgraded_
        , String
"can_be_transferred"               String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_be_transferred_
        , String
"was_refunded"                     String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
was_refunded_
        , String
"date"                             String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
date_
        , String
"gift"                             String -> Maybe SentGift -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe SentGift
gift_
        , String
"collection_ids"                   String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
collection_ids_
        , String
"sell_star_count"                  String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
sell_star_count_
        , String
"prepaid_upgrade_star_count"       String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
prepaid_upgrade_star_count_
        , String
"is_upgrade_separate"              String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_upgrade_separate_
        , String
"transfer_star_count"              String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
transfer_star_count_
        , String
"drop_original_details_star_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
drop_original_details_star_count_
        , String
"next_transfer_date"               String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
next_transfer_date_
        , String
"next_resale_date"                 String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
next_resale_date_
        , String
"export_date"                      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
export_date_
        , String
"prepaid_upgrade_hash"             String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
prepaid_upgrade_hash_
        ]

instance AT.FromJSON ReceivedGift where
  parseJSON :: Value -> Parser ReceivedGift
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
"receivedGift" -> Value -> Parser ReceivedGift
parseReceivedGift Value
v
      String
_              -> Parser ReceivedGift
forall a. Monoid a => a
mempty
    
    where
      parseReceivedGift :: A.Value -> AT.Parser ReceivedGift
      parseReceivedGift :: Value -> Parser ReceivedGift
parseReceivedGift = String
-> (Object -> Parser ReceivedGift) -> Value -> Parser ReceivedGift
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReceivedGift" ((Object -> Parser ReceivedGift) -> Value -> Parser ReceivedGift)
-> (Object -> Parser ReceivedGift) -> Value -> Parser ReceivedGift
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
received_gift_id_                 <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"received_gift_id"
        Maybe MessageSender
sender_id_                        <- Object
o Object -> Key -> Parser (Maybe MessageSender)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"sender_id"
        Maybe FormattedText
text_                             <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        Maybe Bool
is_private_                       <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_private"
        Maybe Bool
is_saved_                         <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_saved"
        Maybe Bool
is_pinned_                        <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_pinned"
        Maybe Bool
can_be_upgraded_                  <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"can_be_upgraded"
        Maybe Bool
can_be_transferred_               <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"can_be_transferred"
        Maybe Bool
was_refunded_                     <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"was_refunded"
        Maybe Int
date_                             <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"date"
        Maybe SentGift
gift_                             <- Object
o Object -> Key -> Parser (Maybe SentGift)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"gift"
        Maybe [Int]
collection_ids_                   <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"collection_ids"
        Maybe Int
sell_star_count_                  <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"sell_star_count"
        Maybe Int
prepaid_upgrade_star_count_       <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"prepaid_upgrade_star_count"
        Maybe Bool
is_upgrade_separate_              <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_upgrade_separate"
        Maybe Int
transfer_star_count_              <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"transfer_star_count"
        Maybe Int
drop_original_details_star_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"drop_original_details_star_count"
        Maybe Int
next_transfer_date_               <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"next_transfer_date"
        Maybe Int
next_resale_date_                 <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"next_resale_date"
        Maybe Int
export_date_                      <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"export_date"
        Maybe Text
prepaid_upgrade_hash_             <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"prepaid_upgrade_hash"
        ReceivedGift -> Parser ReceivedGift
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReceivedGift -> Parser ReceivedGift)
-> ReceivedGift -> Parser ReceivedGift
forall a b. (a -> b) -> a -> b
$ ReceivedGift
          { received_gift_id :: Maybe Text
received_gift_id                 = Maybe Text
received_gift_id_
          , sender_id :: Maybe MessageSender
sender_id                        = Maybe MessageSender
sender_id_
          , text :: Maybe FormattedText
text                             = Maybe FormattedText
text_
          , is_private :: Maybe Bool
is_private                       = Maybe Bool
is_private_
          , is_saved :: Maybe Bool
is_saved                         = Maybe Bool
is_saved_
          , is_pinned :: Maybe Bool
is_pinned                        = Maybe Bool
is_pinned_
          , can_be_upgraded :: Maybe Bool
can_be_upgraded                  = Maybe Bool
can_be_upgraded_
          , can_be_transferred :: Maybe Bool
can_be_transferred               = Maybe Bool
can_be_transferred_
          , was_refunded :: Maybe Bool
was_refunded                     = Maybe Bool
was_refunded_
          , date :: Maybe Int
date                             = Maybe Int
date_
          , gift :: Maybe SentGift
gift                             = Maybe SentGift
gift_
          , collection_ids :: Maybe [Int]
collection_ids                   = Maybe [Int]
collection_ids_
          , sell_star_count :: Maybe Int
sell_star_count                  = Maybe Int
sell_star_count_
          , prepaid_upgrade_star_count :: Maybe Int
prepaid_upgrade_star_count       = Maybe Int
prepaid_upgrade_star_count_
          , is_upgrade_separate :: Maybe Bool
is_upgrade_separate              = Maybe Bool
is_upgrade_separate_
          , transfer_star_count :: Maybe Int
transfer_star_count              = Maybe Int
transfer_star_count_
          , drop_original_details_star_count :: Maybe Int
drop_original_details_star_count = Maybe Int
drop_original_details_star_count_
          , next_transfer_date :: Maybe Int
next_transfer_date               = Maybe Int
next_transfer_date_
          , next_resale_date :: Maybe Int
next_resale_date                 = Maybe Int
next_resale_date_
          , export_date :: Maybe Int
export_date                      = Maybe Int
export_date_
          , prepaid_upgrade_hash :: Maybe Text
prepaid_upgrade_hash             = Maybe Text
prepaid_upgrade_hash_
          }
  parseJSON Value
_ = Parser ReceivedGift
forall a. Monoid a => a
mempty