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