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

data ReceivedGifts
  = ReceivedGifts -- ^ Represents a list of gifts received by a user or a chat
    { ReceivedGifts -> Maybe Int
total_count               :: Maybe Int                         -- ^ The total number of received gifts
    , ReceivedGifts -> Maybe [ReceivedGift]
gifts                     :: Maybe [ReceivedGift.ReceivedGift] -- ^ The list of gifts
    , ReceivedGifts -> Maybe Bool
are_notifications_enabled :: Maybe Bool                        -- ^ True, if notifications about new gifts of the owner are enabled
    , ReceivedGifts -> Maybe Text
next_offset               :: Maybe T.Text                      -- ^ The offset for the next request. If empty, then there are no more results
    }
  deriving (ReceivedGifts -> ReceivedGifts -> Bool
(ReceivedGifts -> ReceivedGifts -> Bool)
-> (ReceivedGifts -> ReceivedGifts -> Bool) -> Eq ReceivedGifts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReceivedGifts -> ReceivedGifts -> Bool
== :: ReceivedGifts -> ReceivedGifts -> Bool
$c/= :: ReceivedGifts -> ReceivedGifts -> Bool
/= :: ReceivedGifts -> ReceivedGifts -> Bool
Eq, Int -> ReceivedGifts -> ShowS
[ReceivedGifts] -> ShowS
ReceivedGifts -> String
(Int -> ReceivedGifts -> ShowS)
-> (ReceivedGifts -> String)
-> ([ReceivedGifts] -> ShowS)
-> Show ReceivedGifts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReceivedGifts -> ShowS
showsPrec :: Int -> ReceivedGifts -> ShowS
$cshow :: ReceivedGifts -> String
show :: ReceivedGifts -> String
$cshowList :: [ReceivedGifts] -> ShowS
showList :: [ReceivedGifts] -> ShowS
Show)

instance I.ShortShow ReceivedGifts where
  shortShow :: ReceivedGifts -> String
shortShow ReceivedGifts
    { total_count :: ReceivedGifts -> Maybe Int
total_count               = Maybe Int
total_count_
    , gifts :: ReceivedGifts -> Maybe [ReceivedGift]
gifts                     = Maybe [ReceivedGift]
gifts_
    , are_notifications_enabled :: ReceivedGifts -> Maybe Bool
are_notifications_enabled = Maybe Bool
are_notifications_enabled_
    , next_offset :: ReceivedGifts -> Maybe Text
next_offset               = Maybe Text
next_offset_
    }
      = String
"ReceivedGifts"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"total_count"               String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_count_
        , String
"gifts"                     String -> Maybe [ReceivedGift] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [ReceivedGift]
gifts_
        , String
"are_notifications_enabled" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
are_notifications_enabled_
        , String
"next_offset"               String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
next_offset_
        ]

instance AT.FromJSON ReceivedGifts where
  parseJSON :: Value -> Parser ReceivedGifts
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
"receivedGifts" -> Value -> Parser ReceivedGifts
parseReceivedGifts Value
v
      String
_               -> Parser ReceivedGifts
forall a. Monoid a => a
mempty
    
    where
      parseReceivedGifts :: A.Value -> AT.Parser ReceivedGifts
      parseReceivedGifts :: Value -> Parser ReceivedGifts
parseReceivedGifts = String
-> (Object -> Parser ReceivedGifts)
-> Value
-> Parser ReceivedGifts
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReceivedGifts" ((Object -> Parser ReceivedGifts) -> Value -> Parser ReceivedGifts)
-> (Object -> Parser ReceivedGifts)
-> Value
-> Parser ReceivedGifts
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
total_count_               <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"total_count"
        Maybe [ReceivedGift]
gifts_                     <- Object
o Object -> Key -> Parser (Maybe [ReceivedGift])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"gifts"
        Maybe Bool
are_notifications_enabled_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"are_notifications_enabled"
        Maybe Text
next_offset_               <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"next_offset"
        ReceivedGifts -> Parser ReceivedGifts
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReceivedGifts -> Parser ReceivedGifts)
-> ReceivedGifts -> Parser ReceivedGifts
forall a b. (a -> b) -> a -> b
$ ReceivedGifts
          { total_count :: Maybe Int
total_count               = Maybe Int
total_count_
          , gifts :: Maybe [ReceivedGift]
gifts                     = Maybe [ReceivedGift]
gifts_
          , are_notifications_enabled :: Maybe Bool
are_notifications_enabled = Maybe Bool
are_notifications_enabled_
          , next_offset :: Maybe Text
next_offset               = Maybe Text
next_offset_
          }
  parseJSON Value
_ = Parser ReceivedGifts
forall a. Monoid a => a
mempty