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