module TD.Data.ChatPhotoStickerType
(ChatPhotoStickerType(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data ChatPhotoStickerType
= ChatPhotoStickerTypeRegularOrMask
{ ChatPhotoStickerType -> Maybe Int
sticker_set_id :: Maybe Int
, ChatPhotoStickerType -> Maybe Int
sticker_id :: Maybe Int
}
| ChatPhotoStickerTypeCustomEmoji
{ ChatPhotoStickerType -> Maybe Int
custom_emoji_id :: Maybe Int
}
deriving (ChatPhotoStickerType -> ChatPhotoStickerType -> Bool
(ChatPhotoStickerType -> ChatPhotoStickerType -> Bool)
-> (ChatPhotoStickerType -> ChatPhotoStickerType -> Bool)
-> Eq ChatPhotoStickerType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatPhotoStickerType -> ChatPhotoStickerType -> Bool
== :: ChatPhotoStickerType -> ChatPhotoStickerType -> Bool
$c/= :: ChatPhotoStickerType -> ChatPhotoStickerType -> Bool
/= :: ChatPhotoStickerType -> ChatPhotoStickerType -> Bool
Eq, Int -> ChatPhotoStickerType -> ShowS
[ChatPhotoStickerType] -> ShowS
ChatPhotoStickerType -> String
(Int -> ChatPhotoStickerType -> ShowS)
-> (ChatPhotoStickerType -> String)
-> ([ChatPhotoStickerType] -> ShowS)
-> Show ChatPhotoStickerType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatPhotoStickerType -> ShowS
showsPrec :: Int -> ChatPhotoStickerType -> ShowS
$cshow :: ChatPhotoStickerType -> String
show :: ChatPhotoStickerType -> String
$cshowList :: [ChatPhotoStickerType] -> ShowS
showList :: [ChatPhotoStickerType] -> ShowS
Show)
instance I.ShortShow ChatPhotoStickerType where
shortShow :: ChatPhotoStickerType -> String
shortShow ChatPhotoStickerTypeRegularOrMask
{ sticker_set_id :: ChatPhotoStickerType -> Maybe Int
sticker_set_id = Maybe Int
sticker_set_id_
, sticker_id :: ChatPhotoStickerType -> Maybe Int
sticker_id = Maybe Int
sticker_id_
}
= String
"ChatPhotoStickerTypeRegularOrMask"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"sticker_set_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
sticker_set_id_
, String
"sticker_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
sticker_id_
]
shortShow ChatPhotoStickerTypeCustomEmoji
{ custom_emoji_id :: ChatPhotoStickerType -> Maybe Int
custom_emoji_id = Maybe Int
custom_emoji_id_
}
= String
"ChatPhotoStickerTypeCustomEmoji"
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_
]
instance AT.FromJSON ChatPhotoStickerType where
parseJSON :: Value -> Parser ChatPhotoStickerType
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
"chatPhotoStickerTypeRegularOrMask" -> Value -> Parser ChatPhotoStickerType
parseChatPhotoStickerTypeRegularOrMask Value
v
String
"chatPhotoStickerTypeCustomEmoji" -> Value -> Parser ChatPhotoStickerType
parseChatPhotoStickerTypeCustomEmoji Value
v
String
_ -> Parser ChatPhotoStickerType
forall a. Monoid a => a
mempty
where
parseChatPhotoStickerTypeRegularOrMask :: A.Value -> AT.Parser ChatPhotoStickerType
parseChatPhotoStickerTypeRegularOrMask :: Value -> Parser ChatPhotoStickerType
parseChatPhotoStickerTypeRegularOrMask = String
-> (Object -> Parser ChatPhotoStickerType)
-> Value
-> Parser ChatPhotoStickerType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatPhotoStickerTypeRegularOrMask" ((Object -> Parser ChatPhotoStickerType)
-> Value -> Parser ChatPhotoStickerType)
-> (Object -> Parser ChatPhotoStickerType)
-> Value
-> Parser ChatPhotoStickerType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
sticker_set_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
"sticker_set_id"
Maybe Int
sticker_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
"sticker_id"
ChatPhotoStickerType -> Parser ChatPhotoStickerType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatPhotoStickerType -> Parser ChatPhotoStickerType)
-> ChatPhotoStickerType -> Parser ChatPhotoStickerType
forall a b. (a -> b) -> a -> b
$ ChatPhotoStickerTypeRegularOrMask
{ sticker_set_id :: Maybe Int
sticker_set_id = Maybe Int
sticker_set_id_
, sticker_id :: Maybe Int
sticker_id = Maybe Int
sticker_id_
}
parseChatPhotoStickerTypeCustomEmoji :: A.Value -> AT.Parser ChatPhotoStickerType
parseChatPhotoStickerTypeCustomEmoji :: Value -> Parser ChatPhotoStickerType
parseChatPhotoStickerTypeCustomEmoji = String
-> (Object -> Parser ChatPhotoStickerType)
-> Value
-> Parser ChatPhotoStickerType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatPhotoStickerTypeCustomEmoji" ((Object -> Parser ChatPhotoStickerType)
-> Value -> Parser ChatPhotoStickerType)
-> (Object -> Parser ChatPhotoStickerType)
-> Value
-> Parser ChatPhotoStickerType
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"
ChatPhotoStickerType -> Parser ChatPhotoStickerType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatPhotoStickerType -> Parser ChatPhotoStickerType)
-> ChatPhotoStickerType -> Parser ChatPhotoStickerType
forall a b. (a -> b) -> a -> b
$ ChatPhotoStickerTypeCustomEmoji
{ custom_emoji_id :: Maybe Int
custom_emoji_id = Maybe Int
custom_emoji_id_
}
parseJSON Value
_ = Parser ChatPhotoStickerType
forall a. Monoid a => a
mempty
instance AT.ToJSON ChatPhotoStickerType where
toJSON :: ChatPhotoStickerType -> Value
toJSON ChatPhotoStickerTypeRegularOrMask
{ sticker_set_id :: ChatPhotoStickerType -> Maybe Int
sticker_set_id = Maybe Int
sticker_set_id_
, sticker_id :: ChatPhotoStickerType -> Maybe Int
sticker_id = Maybe Int
sticker_id_
}
= [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
"chatPhotoStickerTypeRegularOrMask"
, Key
"sticker_set_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
sticker_set_id_
, Key
"sticker_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
sticker_id_
]
toJSON ChatPhotoStickerTypeCustomEmoji
{ custom_emoji_id :: ChatPhotoStickerType -> Maybe Int
custom_emoji_id = Maybe Int
custom_emoji_id_
}
= [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
"chatPhotoStickerTypeCustomEmoji"
, 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_
]