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