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