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