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