module TD.Data.AvailableReactions
(AvailableReactions(..)) 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.AvailableReaction as AvailableReaction
import qualified TD.Data.ReactionUnavailabilityReason as ReactionUnavailabilityReason
data AvailableReactions
= AvailableReactions
{ AvailableReactions -> Maybe [AvailableReaction]
top_reactions :: Maybe [AvailableReaction.AvailableReaction]
, AvailableReactions -> Maybe [AvailableReaction]
recent_reactions :: Maybe [AvailableReaction.AvailableReaction]
, AvailableReactions -> Maybe [AvailableReaction]
popular_reactions :: Maybe [AvailableReaction.AvailableReaction]
, AvailableReactions -> Maybe Bool
allow_custom_emoji :: Maybe Bool
, AvailableReactions -> Maybe Bool
are_tags :: Maybe Bool
, AvailableReactions -> Maybe ReactionUnavailabilityReason
unavailability_reason :: Maybe ReactionUnavailabilityReason.ReactionUnavailabilityReason
}
deriving (AvailableReactions -> AvailableReactions -> Bool
(AvailableReactions -> AvailableReactions -> Bool)
-> (AvailableReactions -> AvailableReactions -> Bool)
-> Eq AvailableReactions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AvailableReactions -> AvailableReactions -> Bool
== :: AvailableReactions -> AvailableReactions -> Bool
$c/= :: AvailableReactions -> AvailableReactions -> Bool
/= :: AvailableReactions -> AvailableReactions -> Bool
Eq, Int -> AvailableReactions -> ShowS
[AvailableReactions] -> ShowS
AvailableReactions -> String
(Int -> AvailableReactions -> ShowS)
-> (AvailableReactions -> String)
-> ([AvailableReactions] -> ShowS)
-> Show AvailableReactions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AvailableReactions -> ShowS
showsPrec :: Int -> AvailableReactions -> ShowS
$cshow :: AvailableReactions -> String
show :: AvailableReactions -> String
$cshowList :: [AvailableReactions] -> ShowS
showList :: [AvailableReactions] -> ShowS
Show)
instance I.ShortShow AvailableReactions where
shortShow :: AvailableReactions -> String
shortShow AvailableReactions
{ top_reactions :: AvailableReactions -> Maybe [AvailableReaction]
top_reactions = Maybe [AvailableReaction]
top_reactions_
, recent_reactions :: AvailableReactions -> Maybe [AvailableReaction]
recent_reactions = Maybe [AvailableReaction]
recent_reactions_
, popular_reactions :: AvailableReactions -> Maybe [AvailableReaction]
popular_reactions = Maybe [AvailableReaction]
popular_reactions_
, allow_custom_emoji :: AvailableReactions -> Maybe Bool
allow_custom_emoji = Maybe Bool
allow_custom_emoji_
, are_tags :: AvailableReactions -> Maybe Bool
are_tags = Maybe Bool
are_tags_
, unavailability_reason :: AvailableReactions -> Maybe ReactionUnavailabilityReason
unavailability_reason = Maybe ReactionUnavailabilityReason
unavailability_reason_
}
= String
"AvailableReactions"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"top_reactions" String -> Maybe [AvailableReaction] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [AvailableReaction]
top_reactions_
, String
"recent_reactions" String -> Maybe [AvailableReaction] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [AvailableReaction]
recent_reactions_
, String
"popular_reactions" String -> Maybe [AvailableReaction] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [AvailableReaction]
popular_reactions_
, String
"allow_custom_emoji" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_custom_emoji_
, String
"are_tags" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
are_tags_
, String
"unavailability_reason" String -> Maybe ReactionUnavailabilityReason -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ReactionUnavailabilityReason
unavailability_reason_
]
instance AT.FromJSON AvailableReactions where
parseJSON :: Value -> Parser AvailableReactions
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
"availableReactions" -> Value -> Parser AvailableReactions
parseAvailableReactions Value
v
String
_ -> Parser AvailableReactions
forall a. Monoid a => a
mempty
where
parseAvailableReactions :: A.Value -> AT.Parser AvailableReactions
parseAvailableReactions :: Value -> Parser AvailableReactions
parseAvailableReactions = String
-> (Object -> Parser AvailableReactions)
-> Value
-> Parser AvailableReactions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AvailableReactions" ((Object -> Parser AvailableReactions)
-> Value -> Parser AvailableReactions)
-> (Object -> Parser AvailableReactions)
-> Value
-> Parser AvailableReactions
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe [AvailableReaction]
top_reactions_ <- Object
o Object -> Key -> Parser (Maybe [AvailableReaction])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"top_reactions"
Maybe [AvailableReaction]
recent_reactions_ <- Object
o Object -> Key -> Parser (Maybe [AvailableReaction])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"recent_reactions"
Maybe [AvailableReaction]
popular_reactions_ <- Object
o Object -> Key -> Parser (Maybe [AvailableReaction])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"popular_reactions"
Maybe Bool
allow_custom_emoji_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"allow_custom_emoji"
Maybe Bool
are_tags_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"are_tags"
Maybe ReactionUnavailabilityReason
unavailability_reason_ <- Object
o Object -> Key -> Parser (Maybe ReactionUnavailabilityReason)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"unavailability_reason"
AvailableReactions -> Parser AvailableReactions
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AvailableReactions -> Parser AvailableReactions)
-> AvailableReactions -> Parser AvailableReactions
forall a b. (a -> b) -> a -> b
$ AvailableReactions
{ top_reactions :: Maybe [AvailableReaction]
top_reactions = Maybe [AvailableReaction]
top_reactions_
, recent_reactions :: Maybe [AvailableReaction]
recent_reactions = Maybe [AvailableReaction]
recent_reactions_
, popular_reactions :: Maybe [AvailableReaction]
popular_reactions = Maybe [AvailableReaction]
popular_reactions_
, allow_custom_emoji :: Maybe Bool
allow_custom_emoji = Maybe Bool
allow_custom_emoji_
, are_tags :: Maybe Bool
are_tags = Maybe Bool
are_tags_
, unavailability_reason :: Maybe ReactionUnavailabilityReason
unavailability_reason = Maybe ReactionUnavailabilityReason
unavailability_reason_
}
parseJSON Value
_ = Parser AvailableReactions
forall a. Monoid a => a
mempty