module TD.Data.GiftCollection
(GiftCollection(..)) 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.Sticker as Sticker
data GiftCollection
= GiftCollection
{ GiftCollection -> Maybe Int
_id :: Maybe Int
, GiftCollection -> Maybe Text
name :: Maybe T.Text
, GiftCollection -> Maybe Sticker
icon :: Maybe Sticker.Sticker
, GiftCollection -> Maybe Int
gift_count :: Maybe Int
}
deriving (GiftCollection -> GiftCollection -> Bool
(GiftCollection -> GiftCollection -> Bool)
-> (GiftCollection -> GiftCollection -> Bool) -> Eq GiftCollection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GiftCollection -> GiftCollection -> Bool
== :: GiftCollection -> GiftCollection -> Bool
$c/= :: GiftCollection -> GiftCollection -> Bool
/= :: GiftCollection -> GiftCollection -> Bool
Eq, Int -> GiftCollection -> ShowS
[GiftCollection] -> ShowS
GiftCollection -> String
(Int -> GiftCollection -> ShowS)
-> (GiftCollection -> String)
-> ([GiftCollection] -> ShowS)
-> Show GiftCollection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GiftCollection -> ShowS
showsPrec :: Int -> GiftCollection -> ShowS
$cshow :: GiftCollection -> String
show :: GiftCollection -> String
$cshowList :: [GiftCollection] -> ShowS
showList :: [GiftCollection] -> ShowS
Show)
instance I.ShortShow GiftCollection where
shortShow :: GiftCollection -> String
shortShow GiftCollection
{ _id :: GiftCollection -> Maybe Int
_id = Maybe Int
_id_
, name :: GiftCollection -> Maybe Text
name = Maybe Text
name_
, icon :: GiftCollection -> Maybe Sticker
icon = Maybe Sticker
icon_
, gift_count :: GiftCollection -> Maybe Int
gift_count = Maybe Int
gift_count_
}
= String
"GiftCollection"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
, String
"name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
, String
"icon" String -> Maybe Sticker -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Sticker
icon_
, String
"gift_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
gift_count_
]
instance AT.FromJSON GiftCollection where
parseJSON :: Value -> Parser GiftCollection
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
"giftCollection" -> Value -> Parser GiftCollection
parseGiftCollection Value
v
String
_ -> Parser GiftCollection
forall a. Monoid a => a
mempty
where
parseGiftCollection :: A.Value -> AT.Parser GiftCollection
parseGiftCollection :: Value -> Parser GiftCollection
parseGiftCollection = String
-> (Object -> Parser GiftCollection)
-> Value
-> Parser GiftCollection
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GiftCollection" ((Object -> Parser GiftCollection)
-> Value -> Parser GiftCollection)
-> (Object -> Parser GiftCollection)
-> Value
-> Parser GiftCollection
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"id"
Maybe Text
name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"name"
Maybe Sticker
icon_ <- Object
o Object -> Key -> Parser (Maybe Sticker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"icon"
Maybe Int
gift_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"gift_count"
GiftCollection -> Parser GiftCollection
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GiftCollection -> Parser GiftCollection)
-> GiftCollection -> Parser GiftCollection
forall a b. (a -> b) -> a -> b
$ GiftCollection
{ _id :: Maybe Int
_id = Maybe Int
_id_
, name :: Maybe Text
name = Maybe Text
name_
, icon :: Maybe Sticker
icon = Maybe Sticker
icon_
, gift_count :: Maybe Int
gift_count = Maybe Int
gift_count_
}
parseJSON Value
_ = Parser GiftCollection
forall a. Monoid a => a
mempty