module TD.Data.MessageEffect
(MessageEffect(..)) 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
import qualified Data.Text as T
import qualified TD.Data.MessageEffectType as MessageEffectType
data MessageEffect
= MessageEffect
{ MessageEffect -> Maybe Int
_id :: Maybe Int
, MessageEffect -> Maybe Sticker
static_icon :: Maybe Sticker.Sticker
, MessageEffect -> Maybe Text
emoji :: Maybe T.Text
, MessageEffect -> Maybe Bool
is_premium :: Maybe Bool
, MessageEffect -> Maybe MessageEffectType
_type :: Maybe MessageEffectType.MessageEffectType
}
deriving (MessageEffect -> MessageEffect -> Bool
(MessageEffect -> MessageEffect -> Bool)
-> (MessageEffect -> MessageEffect -> Bool) -> Eq MessageEffect
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageEffect -> MessageEffect -> Bool
== :: MessageEffect -> MessageEffect -> Bool
$c/= :: MessageEffect -> MessageEffect -> Bool
/= :: MessageEffect -> MessageEffect -> Bool
Eq, Int -> MessageEffect -> ShowS
[MessageEffect] -> ShowS
MessageEffect -> String
(Int -> MessageEffect -> ShowS)
-> (MessageEffect -> String)
-> ([MessageEffect] -> ShowS)
-> Show MessageEffect
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageEffect -> ShowS
showsPrec :: Int -> MessageEffect -> ShowS
$cshow :: MessageEffect -> String
show :: MessageEffect -> String
$cshowList :: [MessageEffect] -> ShowS
showList :: [MessageEffect] -> ShowS
Show)
instance I.ShortShow MessageEffect where
shortShow :: MessageEffect -> String
shortShow MessageEffect
{ _id :: MessageEffect -> Maybe Int
_id = Maybe Int
_id_
, static_icon :: MessageEffect -> Maybe Sticker
static_icon = Maybe Sticker
static_icon_
, emoji :: MessageEffect -> Maybe Text
emoji = Maybe Text
emoji_
, is_premium :: MessageEffect -> Maybe Bool
is_premium = Maybe Bool
is_premium_
, _type :: MessageEffect -> Maybe MessageEffectType
_type = Maybe MessageEffectType
_type_
}
= String
"MessageEffect"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
, String
"static_icon" String -> Maybe Sticker -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Sticker
static_icon_
, String
"emoji" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
emoji_
, String
"is_premium" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_premium_
, String
"_type" String -> Maybe MessageEffectType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageEffectType
_type_
]
instance AT.FromJSON MessageEffect where
parseJSON :: Value -> Parser MessageEffect
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
"messageEffect" -> Value -> Parser MessageEffect
parseMessageEffect Value
v
String
_ -> Parser MessageEffect
forall a. Monoid a => a
mempty
where
parseMessageEffect :: A.Value -> AT.Parser MessageEffect
parseMessageEffect :: Value -> Parser MessageEffect
parseMessageEffect = String
-> (Object -> Parser MessageEffect)
-> Value
-> Parser MessageEffect
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageEffect" ((Object -> Parser MessageEffect) -> Value -> Parser MessageEffect)
-> (Object -> Parser MessageEffect)
-> Value
-> Parser MessageEffect
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
_id_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"id"
Maybe Sticker
static_icon_ <- Object
o Object -> Key -> Parser (Maybe Sticker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"static_icon"
Maybe Text
emoji_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"emoji"
Maybe Bool
is_premium_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_premium"
Maybe MessageEffectType
_type_ <- Object
o Object -> Key -> Parser (Maybe MessageEffectType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
MessageEffect -> Parser MessageEffect
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageEffect -> Parser MessageEffect)
-> MessageEffect -> Parser MessageEffect
forall a b. (a -> b) -> a -> b
$ MessageEffect
{ _id :: Maybe Int
_id = Maybe Int
_id_
, static_icon :: Maybe Sticker
static_icon = Maybe Sticker
static_icon_
, emoji :: Maybe Text
emoji = Maybe Text
emoji_
, is_premium :: Maybe Bool
is_premium = Maybe Bool
is_premium_
, _type :: Maybe MessageEffectType
_type = Maybe MessageEffectType
_type_
}
parseJSON Value
_ = Parser MessageEffect
forall a. Monoid a => a
mempty