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

data UserGift
  = UserGift -- ^ Represents a gift received by a user
    { UserGift -> Maybe Int
sender_user_id             :: Maybe Int                         -- ^ Identifier of the user that sent the gift; 0 if unknown
    , UserGift -> Maybe FormattedText
text                       :: Maybe FormattedText.FormattedText -- ^ Message added to the gift
    , UserGift -> 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
    , UserGift -> Maybe Bool
is_saved                   :: Maybe Bool                        -- ^ True, if the gift is displayed on the user's profile page; only for the receiver of the gift
    , UserGift -> 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
    , UserGift -> Maybe Bool
can_be_transferred         :: Maybe Bool                        -- ^ True, if the gift is an upgraded gift that can be transferred to another user; only for the receiver of the gift
    , UserGift -> Maybe Bool
was_refunded               :: Maybe Bool                        -- ^ True, if the gift was refunded and isn't available anymore
    , UserGift -> Maybe Int
date                       :: Maybe Int                         -- ^ Point in time (Unix timestamp) when the gift was sent
    , UserGift -> Maybe SentGift
gift                       :: Maybe SentGift.SentGift           -- ^ The gift
    , UserGift -> Maybe Int
message_id                 :: Maybe Int                         -- ^ Identifier of the message with the gift in the chat with the sender of the gift; can be 0 or an identifier of a deleted message; only for the receiver of the gift
    , UserGift -> 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
    , UserGift -> 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
    , UserGift -> 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
    , UserGift -> Maybe Int
export_date                :: Maybe Int                         -- ^ Point in time (Unix timestamp) when the upgraded gift can be transferred to TON blockchain as an NFT; 0 if NFT export isn't possible; only for the receiver of the gift
    }
  deriving (UserGift -> UserGift -> Bool
(UserGift -> UserGift -> Bool)
-> (UserGift -> UserGift -> Bool) -> Eq UserGift
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UserGift -> UserGift -> Bool
== :: UserGift -> UserGift -> Bool
$c/= :: UserGift -> UserGift -> Bool
/= :: UserGift -> UserGift -> Bool
Eq, Int -> UserGift -> ShowS
[UserGift] -> ShowS
UserGift -> String
(Int -> UserGift -> ShowS)
-> (UserGift -> String) -> ([UserGift] -> ShowS) -> Show UserGift
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UserGift -> ShowS
showsPrec :: Int -> UserGift -> ShowS
$cshow :: UserGift -> String
show :: UserGift -> String
$cshowList :: [UserGift] -> ShowS
showList :: [UserGift] -> ShowS
Show)

instance I.ShortShow UserGift where
  shortShow :: UserGift -> String
shortShow UserGift
    { sender_user_id :: UserGift -> Maybe Int
sender_user_id             = Maybe Int
sender_user_id_
    , text :: UserGift -> Maybe FormattedText
text                       = Maybe FormattedText
text_
    , is_private :: UserGift -> Maybe Bool
is_private                 = Maybe Bool
is_private_
    , is_saved :: UserGift -> Maybe Bool
is_saved                   = Maybe Bool
is_saved_
    , can_be_upgraded :: UserGift -> Maybe Bool
can_be_upgraded            = Maybe Bool
can_be_upgraded_
    , can_be_transferred :: UserGift -> Maybe Bool
can_be_transferred         = Maybe Bool
can_be_transferred_
    , was_refunded :: UserGift -> Maybe Bool
was_refunded               = Maybe Bool
was_refunded_
    , date :: UserGift -> Maybe Int
date                       = Maybe Int
date_
    , gift :: UserGift -> Maybe SentGift
gift                       = Maybe SentGift
gift_
    , message_id :: UserGift -> Maybe Int
message_id                 = Maybe Int
message_id_
    , sell_star_count :: UserGift -> Maybe Int
sell_star_count            = Maybe Int
sell_star_count_
    , prepaid_upgrade_star_count :: UserGift -> Maybe Int
prepaid_upgrade_star_count = Maybe Int
prepaid_upgrade_star_count_
    , transfer_star_count :: UserGift -> Maybe Int
transfer_star_count        = Maybe Int
transfer_star_count_
    , export_date :: UserGift -> Maybe Int
export_date                = Maybe Int
export_date_
    }
      = String
"UserGift"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"sender_user_id"             String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
sender_user_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
"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
"message_id"                 String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_id_
        , 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
"transfer_star_count"        String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
transfer_star_count_
        , String
"export_date"                String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
export_date_
        ]

instance AT.FromJSON UserGift where
  parseJSON :: Value -> Parser UserGift
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
"userGift" -> Value -> Parser UserGift
parseUserGift Value
v
      String
_          -> Parser UserGift
forall a. Monoid a => a
mempty
    
    where
      parseUserGift :: A.Value -> AT.Parser UserGift
      parseUserGift :: Value -> Parser UserGift
parseUserGift = String -> (Object -> Parser UserGift) -> Value -> Parser UserGift
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserGift" ((Object -> Parser UserGift) -> Value -> Parser UserGift)
-> (Object -> Parser UserGift) -> Value -> Parser UserGift
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
sender_user_id_             <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"sender_user_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
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
message_id_                 <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"message_id"
        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 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
export_date_                <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"export_date"
        UserGift -> Parser UserGift
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserGift -> Parser UserGift) -> UserGift -> Parser UserGift
forall a b. (a -> b) -> a -> b
$ UserGift
          { sender_user_id :: Maybe Int
sender_user_id             = Maybe Int
sender_user_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_
          , 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_
          , message_id :: Maybe Int
message_id                 = Maybe Int
message_id_
          , 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_
          , transfer_star_count :: Maybe Int
transfer_star_count        = Maybe Int
transfer_star_count_
          , export_date :: Maybe Int
export_date                = Maybe Int
export_date_
          }
  parseJSON Value
_ = Parser UserGift
forall a. Monoid a => a
mempty