module TD.Data.UserGifts
(UserGifts(..)) 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.UserGift as UserGift
import qualified Data.Text as T
data UserGifts
= UserGifts
{ UserGifts -> Maybe Int
total_count :: Maybe Int
, UserGifts -> Maybe [UserGift]
gifts :: Maybe [UserGift.UserGift]
, UserGifts -> Maybe Text
next_offset :: Maybe T.Text
}
deriving (UserGifts -> UserGifts -> Bool
(UserGifts -> UserGifts -> Bool)
-> (UserGifts -> UserGifts -> Bool) -> Eq UserGifts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UserGifts -> UserGifts -> Bool
== :: UserGifts -> UserGifts -> Bool
$c/= :: UserGifts -> UserGifts -> Bool
/= :: UserGifts -> UserGifts -> Bool
Eq, Int -> UserGifts -> ShowS
[UserGifts] -> ShowS
UserGifts -> String
(Int -> UserGifts -> ShowS)
-> (UserGifts -> String)
-> ([UserGifts] -> ShowS)
-> Show UserGifts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UserGifts -> ShowS
showsPrec :: Int -> UserGifts -> ShowS
$cshow :: UserGifts -> String
show :: UserGifts -> String
$cshowList :: [UserGifts] -> ShowS
showList :: [UserGifts] -> ShowS
Show)
instance I.ShortShow UserGifts where
shortShow :: UserGifts -> String
shortShow UserGifts
{ total_count :: UserGifts -> Maybe Int
total_count = Maybe Int
total_count_
, gifts :: UserGifts -> Maybe [UserGift]
gifts = Maybe [UserGift]
gifts_
, next_offset :: UserGifts -> Maybe Text
next_offset = Maybe Text
next_offset_
}
= String
"UserGifts"
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 [UserGift] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [UserGift]
gifts_
, String
"next_offset" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
next_offset_
]
instance AT.FromJSON UserGifts where
parseJSON :: Value -> Parser UserGifts
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
"userGifts" -> Value -> Parser UserGifts
parseUserGifts Value
v
String
_ -> Parser UserGifts
forall a. Monoid a => a
mempty
where
parseUserGifts :: A.Value -> AT.Parser UserGifts
parseUserGifts :: Value -> Parser UserGifts
parseUserGifts = String -> (Object -> Parser UserGifts) -> Value -> Parser UserGifts
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserGifts" ((Object -> Parser UserGifts) -> Value -> Parser UserGifts)
-> (Object -> Parser UserGifts) -> Value -> Parser UserGifts
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 [UserGift]
gifts_ <- Object
o Object -> Key -> Parser (Maybe [UserGift])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"gifts"
Maybe Text
next_offset_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"next_offset"
UserGifts -> Parser UserGifts
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserGifts -> Parser UserGifts) -> UserGifts -> Parser UserGifts
forall a b. (a -> b) -> a -> b
$ UserGifts
{ total_count :: Maybe Int
total_count = Maybe Int
total_count_
, gifts :: Maybe [UserGift]
gifts = Maybe [UserGift]
gifts_
, next_offset :: Maybe Text
next_offset = Maybe Text
next_offset_
}
parseJSON Value
_ = Parser UserGifts
forall a. Monoid a => a
mempty