module TD.Data.AddedReaction
(AddedReaction(..)) 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.ReactionType as ReactionType
import qualified TD.Data.MessageSender as MessageSender
data AddedReaction
= AddedReaction
{ AddedReaction -> Maybe ReactionType
_type :: Maybe ReactionType.ReactionType
, AddedReaction -> Maybe MessageSender
sender_id :: Maybe MessageSender.MessageSender
, AddedReaction -> Maybe Bool
is_outgoing :: Maybe Bool
, AddedReaction -> Maybe Int
date :: Maybe Int
}
deriving (AddedReaction -> AddedReaction -> Bool
(AddedReaction -> AddedReaction -> Bool)
-> (AddedReaction -> AddedReaction -> Bool) -> Eq AddedReaction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AddedReaction -> AddedReaction -> Bool
== :: AddedReaction -> AddedReaction -> Bool
$c/= :: AddedReaction -> AddedReaction -> Bool
/= :: AddedReaction -> AddedReaction -> Bool
Eq, Int -> AddedReaction -> ShowS
[AddedReaction] -> ShowS
AddedReaction -> String
(Int -> AddedReaction -> ShowS)
-> (AddedReaction -> String)
-> ([AddedReaction] -> ShowS)
-> Show AddedReaction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AddedReaction -> ShowS
showsPrec :: Int -> AddedReaction -> ShowS
$cshow :: AddedReaction -> String
show :: AddedReaction -> String
$cshowList :: [AddedReaction] -> ShowS
showList :: [AddedReaction] -> ShowS
Show)
instance I.ShortShow AddedReaction where
shortShow :: AddedReaction -> String
shortShow AddedReaction
{ _type :: AddedReaction -> Maybe ReactionType
_type = Maybe ReactionType
_type_
, sender_id :: AddedReaction -> Maybe MessageSender
sender_id = Maybe MessageSender
sender_id_
, is_outgoing :: AddedReaction -> Maybe Bool
is_outgoing = Maybe Bool
is_outgoing_
, date :: AddedReaction -> Maybe Int
date = Maybe Int
date_
}
= String
"AddedReaction"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_type" String -> Maybe ReactionType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ReactionType
_type_
, String
"sender_id" String -> Maybe MessageSender -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSender
sender_id_
, String
"is_outgoing" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_outgoing_
, String
"date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
date_
]
instance AT.FromJSON AddedReaction where
parseJSON :: Value -> Parser AddedReaction
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
"addedReaction" -> Value -> Parser AddedReaction
parseAddedReaction Value
v
String
_ -> Parser AddedReaction
forall a. Monoid a => a
mempty
where
parseAddedReaction :: A.Value -> AT.Parser AddedReaction
parseAddedReaction :: Value -> Parser AddedReaction
parseAddedReaction = String
-> (Object -> Parser AddedReaction)
-> Value
-> Parser AddedReaction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AddedReaction" ((Object -> Parser AddedReaction) -> Value -> Parser AddedReaction)
-> (Object -> Parser AddedReaction)
-> Value
-> Parser AddedReaction
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe ReactionType
_type_ <- Object
o Object -> Key -> Parser (Maybe ReactionType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
Maybe MessageSender
sender_id_ <- Object
o Object -> Key -> Parser (Maybe MessageSender)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sender_id"
Maybe Bool
is_outgoing_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_outgoing"
Maybe Int
date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"date"
AddedReaction -> Parser AddedReaction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AddedReaction -> Parser AddedReaction)
-> AddedReaction -> Parser AddedReaction
forall a b. (a -> b) -> a -> b
$ AddedReaction
{ _type :: Maybe ReactionType
_type = Maybe ReactionType
_type_
, sender_id :: Maybe MessageSender
sender_id = Maybe MessageSender
sender_id_
, is_outgoing :: Maybe Bool
is_outgoing = Maybe Bool
is_outgoing_
, date :: Maybe Int
date = Maybe Int
date_
}
parseJSON Value
_ = Parser AddedReaction
forall a. Monoid a => a
mempty