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

data GiftAuctionAcquiredGift
  = GiftAuctionAcquiredGift -- ^ Represents a gift that was acquired by the current user on an auction
    { GiftAuctionAcquiredGift -> Maybe MessageSender
receiver_id            :: Maybe MessageSender.MessageSender -- ^ Receiver of the gift
    , GiftAuctionAcquiredGift -> Maybe Int
date                   :: Maybe Int                         -- ^ Point in time (Unix timestamp) when the gift was acquired
    , GiftAuctionAcquiredGift -> Maybe Int
star_count             :: Maybe Int                         -- ^ The number of Telegram Stars that were paid for the gift
    , GiftAuctionAcquiredGift -> Maybe Int
auction_round_number   :: Maybe Int                         -- ^ Identifier of the auction round in which the gift was acquired
    , GiftAuctionAcquiredGift -> Maybe Int
auction_round_position :: Maybe Int                         -- ^ Position of the user in the round among all auction participants
    , GiftAuctionAcquiredGift -> Maybe Int
unique_gift_number     :: Maybe Int                         -- ^ Unique number of the gift among gifts upgraded from the same gift after upgrade; 0 if yet unassigned
    , GiftAuctionAcquiredGift -> Maybe FormattedText
text                   :: Maybe FormattedText.FormattedText -- ^ Message added to the gift
    , GiftAuctionAcquiredGift -> Maybe Bool
is_private             :: Maybe Bool                        -- ^ True, if the sender and gift text are shown only to the gift receiver; otherwise, everyone will be able to see them
    }
  deriving (GiftAuctionAcquiredGift -> GiftAuctionAcquiredGift -> Bool
(GiftAuctionAcquiredGift -> GiftAuctionAcquiredGift -> Bool)
-> (GiftAuctionAcquiredGift -> GiftAuctionAcquiredGift -> Bool)
-> Eq GiftAuctionAcquiredGift
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GiftAuctionAcquiredGift -> GiftAuctionAcquiredGift -> Bool
== :: GiftAuctionAcquiredGift -> GiftAuctionAcquiredGift -> Bool
$c/= :: GiftAuctionAcquiredGift -> GiftAuctionAcquiredGift -> Bool
/= :: GiftAuctionAcquiredGift -> GiftAuctionAcquiredGift -> Bool
Eq, Int -> GiftAuctionAcquiredGift -> ShowS
[GiftAuctionAcquiredGift] -> ShowS
GiftAuctionAcquiredGift -> String
(Int -> GiftAuctionAcquiredGift -> ShowS)
-> (GiftAuctionAcquiredGift -> String)
-> ([GiftAuctionAcquiredGift] -> ShowS)
-> Show GiftAuctionAcquiredGift
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GiftAuctionAcquiredGift -> ShowS
showsPrec :: Int -> GiftAuctionAcquiredGift -> ShowS
$cshow :: GiftAuctionAcquiredGift -> String
show :: GiftAuctionAcquiredGift -> String
$cshowList :: [GiftAuctionAcquiredGift] -> ShowS
showList :: [GiftAuctionAcquiredGift] -> ShowS
Show)

instance I.ShortShow GiftAuctionAcquiredGift where
  shortShow :: GiftAuctionAcquiredGift -> String
shortShow GiftAuctionAcquiredGift
    { receiver_id :: GiftAuctionAcquiredGift -> Maybe MessageSender
receiver_id            = Maybe MessageSender
receiver_id_
    , date :: GiftAuctionAcquiredGift -> Maybe Int
date                   = Maybe Int
date_
    , star_count :: GiftAuctionAcquiredGift -> Maybe Int
star_count             = Maybe Int
star_count_
    , auction_round_number :: GiftAuctionAcquiredGift -> Maybe Int
auction_round_number   = Maybe Int
auction_round_number_
    , auction_round_position :: GiftAuctionAcquiredGift -> Maybe Int
auction_round_position = Maybe Int
auction_round_position_
    , unique_gift_number :: GiftAuctionAcquiredGift -> Maybe Int
unique_gift_number     = Maybe Int
unique_gift_number_
    , text :: GiftAuctionAcquiredGift -> Maybe FormattedText
text                   = Maybe FormattedText
text_
    , is_private :: GiftAuctionAcquiredGift -> Maybe Bool
is_private             = Maybe Bool
is_private_
    }
      = String
"GiftAuctionAcquiredGift"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"receiver_id"            String -> Maybe MessageSender -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSender
receiver_id_
        , String
"date"                   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
date_
        , String
"star_count"             String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
star_count_
        , String
"auction_round_number"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
auction_round_number_
        , String
"auction_round_position" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
auction_round_position_
        , String
"unique_gift_number"     String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
unique_gift_number_
        , 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_
        ]

instance AT.FromJSON GiftAuctionAcquiredGift where
  parseJSON :: Value -> Parser GiftAuctionAcquiredGift
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
"giftAuctionAcquiredGift" -> Value -> Parser GiftAuctionAcquiredGift
parseGiftAuctionAcquiredGift Value
v
      String
_                         -> Parser GiftAuctionAcquiredGift
forall a. Monoid a => a
mempty
    
    where
      parseGiftAuctionAcquiredGift :: A.Value -> AT.Parser GiftAuctionAcquiredGift
      parseGiftAuctionAcquiredGift :: Value -> Parser GiftAuctionAcquiredGift
parseGiftAuctionAcquiredGift = String
-> (Object -> Parser GiftAuctionAcquiredGift)
-> Value
-> Parser GiftAuctionAcquiredGift
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GiftAuctionAcquiredGift" ((Object -> Parser GiftAuctionAcquiredGift)
 -> Value -> Parser GiftAuctionAcquiredGift)
-> (Object -> Parser GiftAuctionAcquiredGift)
-> Value
-> Parser GiftAuctionAcquiredGift
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe MessageSender
receiver_id_            <- Object
o Object -> Key -> Parser (Maybe MessageSender)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"receiver_id"
        Maybe Int
date_                   <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"date"
        Maybe Int
star_count_             <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"star_count"
        Maybe Int
auction_round_number_   <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"auction_round_number"
        Maybe Int
auction_round_position_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"auction_round_position"
        Maybe Int
unique_gift_number_     <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"unique_gift_number"
        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"
        GiftAuctionAcquiredGift -> Parser GiftAuctionAcquiredGift
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GiftAuctionAcquiredGift -> Parser GiftAuctionAcquiredGift)
-> GiftAuctionAcquiredGift -> Parser GiftAuctionAcquiredGift
forall a b. (a -> b) -> a -> b
$ GiftAuctionAcquiredGift
          { receiver_id :: Maybe MessageSender
receiver_id            = Maybe MessageSender
receiver_id_
          , date :: Maybe Int
date                   = Maybe Int
date_
          , star_count :: Maybe Int
star_count             = Maybe Int
star_count_
          , auction_round_number :: Maybe Int
auction_round_number   = Maybe Int
auction_round_number_
          , auction_round_position :: Maybe Int
auction_round_position = Maybe Int
auction_round_position_
          , unique_gift_number :: Maybe Int
unique_gift_number     = Maybe Int
unique_gift_number_
          , text :: Maybe FormattedText
text                   = Maybe FormattedText
text_
          , is_private :: Maybe Bool
is_private             = Maybe Bool
is_private_
          }
  parseJSON Value
_ = Parser GiftAuctionAcquiredGift
forall a. Monoid a => a
mempty