module TD.Data.MessageEffectType
(MessageEffectType(..)) 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.Sticker as Sticker
data MessageEffectType
= MessageEffectTypeEmojiReaction
{ MessageEffectType -> Maybe Sticker
select_animation :: Maybe Sticker.Sticker
, MessageEffectType -> Maybe Sticker
effect_animation :: Maybe Sticker.Sticker
}
| MessageEffectTypePremiumSticker
{ MessageEffectType -> Maybe Sticker
sticker :: Maybe Sticker.Sticker
}
deriving (MessageEffectType -> MessageEffectType -> Bool
(MessageEffectType -> MessageEffectType -> Bool)
-> (MessageEffectType -> MessageEffectType -> Bool)
-> Eq MessageEffectType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageEffectType -> MessageEffectType -> Bool
== :: MessageEffectType -> MessageEffectType -> Bool
$c/= :: MessageEffectType -> MessageEffectType -> Bool
/= :: MessageEffectType -> MessageEffectType -> Bool
Eq, Int -> MessageEffectType -> ShowS
[MessageEffectType] -> ShowS
MessageEffectType -> String
(Int -> MessageEffectType -> ShowS)
-> (MessageEffectType -> String)
-> ([MessageEffectType] -> ShowS)
-> Show MessageEffectType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageEffectType -> ShowS
showsPrec :: Int -> MessageEffectType -> ShowS
$cshow :: MessageEffectType -> String
show :: MessageEffectType -> String
$cshowList :: [MessageEffectType] -> ShowS
showList :: [MessageEffectType] -> ShowS
Show)
instance I.ShortShow MessageEffectType where
shortShow :: MessageEffectType -> String
shortShow MessageEffectTypeEmojiReaction
{ select_animation :: MessageEffectType -> Maybe Sticker
select_animation = Maybe Sticker
select_animation_
, effect_animation :: MessageEffectType -> Maybe Sticker
effect_animation = Maybe Sticker
effect_animation_
}
= String
"MessageEffectTypeEmojiReaction"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"select_animation" String -> Maybe Sticker -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Sticker
select_animation_
, String
"effect_animation" String -> Maybe Sticker -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Sticker
effect_animation_
]
shortShow MessageEffectTypePremiumSticker
{ sticker :: MessageEffectType -> Maybe Sticker
sticker = Maybe Sticker
sticker_
}
= String
"MessageEffectTypePremiumSticker"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"sticker" String -> Maybe Sticker -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Sticker
sticker_
]
instance AT.FromJSON MessageEffectType where
parseJSON :: Value -> Parser MessageEffectType
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
"messageEffectTypeEmojiReaction" -> Value -> Parser MessageEffectType
parseMessageEffectTypeEmojiReaction Value
v
String
"messageEffectTypePremiumSticker" -> Value -> Parser MessageEffectType
parseMessageEffectTypePremiumSticker Value
v
String
_ -> Parser MessageEffectType
forall a. Monoid a => a
mempty
where
parseMessageEffectTypeEmojiReaction :: A.Value -> AT.Parser MessageEffectType
parseMessageEffectTypeEmojiReaction :: Value -> Parser MessageEffectType
parseMessageEffectTypeEmojiReaction = String
-> (Object -> Parser MessageEffectType)
-> Value
-> Parser MessageEffectType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageEffectTypeEmojiReaction" ((Object -> Parser MessageEffectType)
-> Value -> Parser MessageEffectType)
-> (Object -> Parser MessageEffectType)
-> Value
-> Parser MessageEffectType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Sticker
select_animation_ <- Object
o Object -> Key -> Parser (Maybe Sticker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"select_animation"
Maybe Sticker
effect_animation_ <- Object
o Object -> Key -> Parser (Maybe Sticker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"effect_animation"
MessageEffectType -> Parser MessageEffectType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageEffectType -> Parser MessageEffectType)
-> MessageEffectType -> Parser MessageEffectType
forall a b. (a -> b) -> a -> b
$ MessageEffectTypeEmojiReaction
{ select_animation :: Maybe Sticker
select_animation = Maybe Sticker
select_animation_
, effect_animation :: Maybe Sticker
effect_animation = Maybe Sticker
effect_animation_
}
parseMessageEffectTypePremiumSticker :: A.Value -> AT.Parser MessageEffectType
parseMessageEffectTypePremiumSticker :: Value -> Parser MessageEffectType
parseMessageEffectTypePremiumSticker = String
-> (Object -> Parser MessageEffectType)
-> Value
-> Parser MessageEffectType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageEffectTypePremiumSticker" ((Object -> Parser MessageEffectType)
-> Value -> Parser MessageEffectType)
-> (Object -> Parser MessageEffectType)
-> Value
-> Parser MessageEffectType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Sticker
sticker_ <- Object
o Object -> Key -> Parser (Maybe Sticker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sticker"
MessageEffectType -> Parser MessageEffectType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageEffectType -> Parser MessageEffectType)
-> MessageEffectType -> Parser MessageEffectType
forall a b. (a -> b) -> a -> b
$ MessageEffectTypePremiumSticker
{ sticker :: Maybe Sticker
sticker = Maybe Sticker
sticker_
}
parseJSON Value
_ = Parser MessageEffectType
forall a. Monoid a => a
mempty