module TD.Data.EmojiStatus
( EmojiStatus(..)
, defaultEmojiStatus
) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data EmojiStatus
= EmojiStatus
{ EmojiStatus -> Maybe Int
custom_emoji_id :: Maybe Int
, EmojiStatus -> Maybe Int
expiration_date :: Maybe Int
}
deriving (EmojiStatus -> EmojiStatus -> Bool
(EmojiStatus -> EmojiStatus -> Bool)
-> (EmojiStatus -> EmojiStatus -> Bool) -> Eq EmojiStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EmojiStatus -> EmojiStatus -> Bool
== :: EmojiStatus -> EmojiStatus -> Bool
$c/= :: EmojiStatus -> EmojiStatus -> Bool
/= :: EmojiStatus -> EmojiStatus -> Bool
Eq, Int -> EmojiStatus -> ShowS
[EmojiStatus] -> ShowS
EmojiStatus -> String
(Int -> EmojiStatus -> ShowS)
-> (EmojiStatus -> String)
-> ([EmojiStatus] -> ShowS)
-> Show EmojiStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EmojiStatus -> ShowS
showsPrec :: Int -> EmojiStatus -> ShowS
$cshow :: EmojiStatus -> String
show :: EmojiStatus -> String
$cshowList :: [EmojiStatus] -> ShowS
showList :: [EmojiStatus] -> ShowS
Show)
instance I.ShortShow EmojiStatus where
shortShow :: EmojiStatus -> String
shortShow EmojiStatus
{ custom_emoji_id :: EmojiStatus -> Maybe Int
custom_emoji_id = Maybe Int
custom_emoji_id_
, expiration_date :: EmojiStatus -> Maybe Int
expiration_date = Maybe Int
expiration_date_
}
= String
"EmojiStatus"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"custom_emoji_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
custom_emoji_id_
, String
"expiration_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
expiration_date_
]
instance AT.FromJSON EmojiStatus where
parseJSON :: Value -> Parser EmojiStatus
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
"emojiStatus" -> Value -> Parser EmojiStatus
parseEmojiStatus Value
v
String
_ -> Parser EmojiStatus
forall a. Monoid a => a
mempty
where
parseEmojiStatus :: A.Value -> AT.Parser EmojiStatus
parseEmojiStatus :: Value -> Parser EmojiStatus
parseEmojiStatus = String
-> (Object -> Parser EmojiStatus) -> Value -> Parser EmojiStatus
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"EmojiStatus" ((Object -> Parser EmojiStatus) -> Value -> Parser EmojiStatus)
-> (Object -> Parser EmojiStatus) -> Value -> Parser EmojiStatus
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
custom_emoji_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
"custom_emoji_id"
Maybe Int
expiration_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"expiration_date"
EmojiStatus -> Parser EmojiStatus
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (EmojiStatus -> Parser EmojiStatus)
-> EmojiStatus -> Parser EmojiStatus
forall a b. (a -> b) -> a -> b
$ EmojiStatus
{ custom_emoji_id :: Maybe Int
custom_emoji_id = Maybe Int
custom_emoji_id_
, expiration_date :: Maybe Int
expiration_date = Maybe Int
expiration_date_
}
parseJSON Value
_ = Parser EmojiStatus
forall a. Monoid a => a
mempty
instance AT.ToJSON EmojiStatus where
toJSON :: EmojiStatus -> Value
toJSON EmojiStatus
{ custom_emoji_id :: EmojiStatus -> Maybe Int
custom_emoji_id = Maybe Int
custom_emoji_id_
, expiration_date :: EmojiStatus -> Maybe Int
expiration_date = Maybe Int
expiration_date_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"emojiStatus"
, Key
"custom_emoji_id" Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (Int -> Value) -> Maybe Int -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Value
I.writeInt64 Maybe Int
custom_emoji_id_
, Key
"expiration_date" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
expiration_date_
]
defaultEmojiStatus :: EmojiStatus
defaultEmojiStatus :: EmojiStatus
defaultEmojiStatus =
EmojiStatus
{ custom_emoji_id :: Maybe Int
custom_emoji_id = Maybe Int
forall a. Maybe a
Nothing
, expiration_date :: Maybe Int
expiration_date = Maybe Int
forall a. Maybe a
Nothing
}