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