module TD.Data.MessageViewers
(MessageViewers(..)) 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.MessageViewer as MessageViewer
data MessageViewers
= MessageViewers
{ MessageViewers -> Maybe [MessageViewer]
viewers :: Maybe [MessageViewer.MessageViewer]
}
deriving (MessageViewers -> MessageViewers -> Bool
(MessageViewers -> MessageViewers -> Bool)
-> (MessageViewers -> MessageViewers -> Bool) -> Eq MessageViewers
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageViewers -> MessageViewers -> Bool
== :: MessageViewers -> MessageViewers -> Bool
$c/= :: MessageViewers -> MessageViewers -> Bool
/= :: MessageViewers -> MessageViewers -> Bool
Eq, Int -> MessageViewers -> ShowS
[MessageViewers] -> ShowS
MessageViewers -> String
(Int -> MessageViewers -> ShowS)
-> (MessageViewers -> String)
-> ([MessageViewers] -> ShowS)
-> Show MessageViewers
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageViewers -> ShowS
showsPrec :: Int -> MessageViewers -> ShowS
$cshow :: MessageViewers -> String
show :: MessageViewers -> String
$cshowList :: [MessageViewers] -> ShowS
showList :: [MessageViewers] -> ShowS
Show)
instance I.ShortShow MessageViewers where
shortShow :: MessageViewers -> String
shortShow MessageViewers
{ viewers :: MessageViewers -> Maybe [MessageViewer]
viewers = Maybe [MessageViewer]
viewers_
}
= String
"MessageViewers"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"viewers" String -> Maybe [MessageViewer] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [MessageViewer]
viewers_
]
instance AT.FromJSON MessageViewers where
parseJSON :: Value -> Parser MessageViewers
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
"messageViewers" -> Value -> Parser MessageViewers
parseMessageViewers Value
v
String
_ -> Parser MessageViewers
forall a. Monoid a => a
mempty
where
parseMessageViewers :: A.Value -> AT.Parser MessageViewers
parseMessageViewers :: Value -> Parser MessageViewers
parseMessageViewers = String
-> (Object -> Parser MessageViewers)
-> Value
-> Parser MessageViewers
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageViewers" ((Object -> Parser MessageViewers)
-> Value -> Parser MessageViewers)
-> (Object -> Parser MessageViewers)
-> Value
-> Parser MessageViewers
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe [MessageViewer]
viewers_ <- Object
o Object -> Key -> Parser (Maybe [MessageViewer])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"viewers"
MessageViewers -> Parser MessageViewers
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageViewers -> Parser MessageViewers)
-> MessageViewers -> Parser MessageViewers
forall a b. (a -> b) -> a -> b
$ MessageViewers
{ viewers :: Maybe [MessageViewer]
viewers = Maybe [MessageViewer]
viewers_
}
parseJSON Value
_ = Parser MessageViewers
forall a. Monoid a => a
mempty