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