module TD.Data.AvailableReaction
(AvailableReaction(..)) 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
data AvailableReaction
= AvailableReaction
{ AvailableReaction -> Maybe ReactionType
_type :: Maybe ReactionType.ReactionType
, AvailableReaction -> Maybe Bool
needs_premium :: Maybe Bool
}
deriving (AvailableReaction -> AvailableReaction -> Bool
(AvailableReaction -> AvailableReaction -> Bool)
-> (AvailableReaction -> AvailableReaction -> Bool)
-> Eq AvailableReaction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AvailableReaction -> AvailableReaction -> Bool
== :: AvailableReaction -> AvailableReaction -> Bool
$c/= :: AvailableReaction -> AvailableReaction -> Bool
/= :: AvailableReaction -> AvailableReaction -> Bool
Eq, Int -> AvailableReaction -> ShowS
[AvailableReaction] -> ShowS
AvailableReaction -> String
(Int -> AvailableReaction -> ShowS)
-> (AvailableReaction -> String)
-> ([AvailableReaction] -> ShowS)
-> Show AvailableReaction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AvailableReaction -> ShowS
showsPrec :: Int -> AvailableReaction -> ShowS
$cshow :: AvailableReaction -> String
show :: AvailableReaction -> String
$cshowList :: [AvailableReaction] -> ShowS
showList :: [AvailableReaction] -> ShowS
Show)
instance I.ShortShow AvailableReaction where
shortShow :: AvailableReaction -> String
shortShow AvailableReaction
{ _type :: AvailableReaction -> Maybe ReactionType
_type = Maybe ReactionType
_type_
, needs_premium :: AvailableReaction -> Maybe Bool
needs_premium = Maybe Bool
needs_premium_
}
= String
"AvailableReaction"
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
"needs_premium" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
needs_premium_
]
instance AT.FromJSON AvailableReaction where
parseJSON :: Value -> Parser AvailableReaction
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
"availableReaction" -> Value -> Parser AvailableReaction
parseAvailableReaction Value
v
String
_ -> Parser AvailableReaction
forall a. Monoid a => a
mempty
where
parseAvailableReaction :: A.Value -> AT.Parser AvailableReaction
parseAvailableReaction :: Value -> Parser AvailableReaction
parseAvailableReaction = String
-> (Object -> Parser AvailableReaction)
-> Value
-> Parser AvailableReaction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AvailableReaction" ((Object -> Parser AvailableReaction)
-> Value -> Parser AvailableReaction)
-> (Object -> Parser AvailableReaction)
-> Value
-> Parser AvailableReaction
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 Bool
needs_premium_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"needs_premium"
AvailableReaction -> Parser AvailableReaction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AvailableReaction -> Parser AvailableReaction)
-> AvailableReaction -> Parser AvailableReaction
forall a b. (a -> b) -> a -> b
$ AvailableReaction
{ _type :: Maybe ReactionType
_type = Maybe ReactionType
_type_
, needs_premium :: Maybe Bool
needs_premium = Maybe Bool
needs_premium_
}
parseJSON Value
_ = Parser AvailableReaction
forall a. Monoid a => a
mempty