module TD.Data.MessageInteractionInfo
(MessageInteractionInfo(..)) 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.MessageReplyInfo as MessageReplyInfo
import qualified TD.Data.MessageReactions as MessageReactions
data MessageInteractionInfo
= MessageInteractionInfo
{ MessageInteractionInfo -> Maybe Int
view_count :: Maybe Int
, MessageInteractionInfo -> Maybe Int
forward_count :: Maybe Int
, MessageInteractionInfo -> Maybe MessageReplyInfo
reply_info :: Maybe MessageReplyInfo.MessageReplyInfo
, MessageInteractionInfo -> Maybe MessageReactions
reactions :: Maybe MessageReactions.MessageReactions
}
deriving (MessageInteractionInfo -> MessageInteractionInfo -> Bool
(MessageInteractionInfo -> MessageInteractionInfo -> Bool)
-> (MessageInteractionInfo -> MessageInteractionInfo -> Bool)
-> Eq MessageInteractionInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageInteractionInfo -> MessageInteractionInfo -> Bool
== :: MessageInteractionInfo -> MessageInteractionInfo -> Bool
$c/= :: MessageInteractionInfo -> MessageInteractionInfo -> Bool
/= :: MessageInteractionInfo -> MessageInteractionInfo -> Bool
Eq, Int -> MessageInteractionInfo -> ShowS
[MessageInteractionInfo] -> ShowS
MessageInteractionInfo -> String
(Int -> MessageInteractionInfo -> ShowS)
-> (MessageInteractionInfo -> String)
-> ([MessageInteractionInfo] -> ShowS)
-> Show MessageInteractionInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageInteractionInfo -> ShowS
showsPrec :: Int -> MessageInteractionInfo -> ShowS
$cshow :: MessageInteractionInfo -> String
show :: MessageInteractionInfo -> String
$cshowList :: [MessageInteractionInfo] -> ShowS
showList :: [MessageInteractionInfo] -> ShowS
Show)
instance I.ShortShow MessageInteractionInfo where
shortShow :: MessageInteractionInfo -> String
shortShow MessageInteractionInfo
{ view_count :: MessageInteractionInfo -> Maybe Int
view_count = Maybe Int
view_count_
, forward_count :: MessageInteractionInfo -> Maybe Int
forward_count = Maybe Int
forward_count_
, reply_info :: MessageInteractionInfo -> Maybe MessageReplyInfo
reply_info = Maybe MessageReplyInfo
reply_info_
, reactions :: MessageInteractionInfo -> Maybe MessageReactions
reactions = Maybe MessageReactions
reactions_
}
= String
"MessageInteractionInfo"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"view_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
view_count_
, String
"forward_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
forward_count_
, String
"reply_info" String -> Maybe MessageReplyInfo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageReplyInfo
reply_info_
, String
"reactions" String -> Maybe MessageReactions -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageReactions
reactions_
]
instance AT.FromJSON MessageInteractionInfo where
parseJSON :: Value -> Parser MessageInteractionInfo
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
"messageInteractionInfo" -> Value -> Parser MessageInteractionInfo
parseMessageInteractionInfo Value
v
String
_ -> Parser MessageInteractionInfo
forall a. Monoid a => a
mempty
where
parseMessageInteractionInfo :: A.Value -> AT.Parser MessageInteractionInfo
parseMessageInteractionInfo :: Value -> Parser MessageInteractionInfo
parseMessageInteractionInfo = String
-> (Object -> Parser MessageInteractionInfo)
-> Value
-> Parser MessageInteractionInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageInteractionInfo" ((Object -> Parser MessageInteractionInfo)
-> Value -> Parser MessageInteractionInfo)
-> (Object -> Parser MessageInteractionInfo)
-> Value
-> Parser MessageInteractionInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
view_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"view_count"
Maybe Int
forward_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"forward_count"
Maybe MessageReplyInfo
reply_info_ <- Object
o Object -> Key -> Parser (Maybe MessageReplyInfo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"reply_info"
Maybe MessageReactions
reactions_ <- Object
o Object -> Key -> Parser (Maybe MessageReactions)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"reactions"
MessageInteractionInfo -> Parser MessageInteractionInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageInteractionInfo -> Parser MessageInteractionInfo)
-> MessageInteractionInfo -> Parser MessageInteractionInfo
forall a b. (a -> b) -> a -> b
$ MessageInteractionInfo
{ view_count :: Maybe Int
view_count = Maybe Int
view_count_
, forward_count :: Maybe Int
forward_count = Maybe Int
forward_count_
, reply_info :: Maybe MessageReplyInfo
reply_info = Maybe MessageReplyInfo
reply_info_
, reactions :: Maybe MessageReactions
reactions = Maybe MessageReactions
reactions_
}
parseJSON Value
_ = Parser MessageInteractionInfo
forall a. Monoid a => a
mempty