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