module TD.Data.InlineKeyboardButton
( InlineKeyboardButton(..)
, defaultInlineKeyboardButton
) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
import qualified TD.Data.ButtonStyle as ButtonStyle
import qualified TD.Data.InlineKeyboardButtonType as InlineKeyboardButtonType
data InlineKeyboardButton
= InlineKeyboardButton
{ InlineKeyboardButton -> Maybe Text
text :: Maybe T.Text
, InlineKeyboardButton -> Maybe Int
icon_custom_emoji_id :: Maybe Int
, InlineKeyboardButton -> Maybe ButtonStyle
style :: Maybe ButtonStyle.ButtonStyle
, InlineKeyboardButton -> Maybe InlineKeyboardButtonType
_type :: Maybe InlineKeyboardButtonType.InlineKeyboardButtonType
}
deriving (InlineKeyboardButton -> InlineKeyboardButton -> Bool
(InlineKeyboardButton -> InlineKeyboardButton -> Bool)
-> (InlineKeyboardButton -> InlineKeyboardButton -> Bool)
-> Eq InlineKeyboardButton
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InlineKeyboardButton -> InlineKeyboardButton -> Bool
== :: InlineKeyboardButton -> InlineKeyboardButton -> Bool
$c/= :: InlineKeyboardButton -> InlineKeyboardButton -> Bool
/= :: InlineKeyboardButton -> InlineKeyboardButton -> Bool
Eq, Int -> InlineKeyboardButton -> ShowS
[InlineKeyboardButton] -> ShowS
InlineKeyboardButton -> String
(Int -> InlineKeyboardButton -> ShowS)
-> (InlineKeyboardButton -> String)
-> ([InlineKeyboardButton] -> ShowS)
-> Show InlineKeyboardButton
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InlineKeyboardButton -> ShowS
showsPrec :: Int -> InlineKeyboardButton -> ShowS
$cshow :: InlineKeyboardButton -> String
show :: InlineKeyboardButton -> String
$cshowList :: [InlineKeyboardButton] -> ShowS
showList :: [InlineKeyboardButton] -> ShowS
Show)
instance I.ShortShow InlineKeyboardButton where
shortShow :: InlineKeyboardButton -> String
shortShow InlineKeyboardButton
{ text :: InlineKeyboardButton -> Maybe Text
text = Maybe Text
text_
, icon_custom_emoji_id :: InlineKeyboardButton -> Maybe Int
icon_custom_emoji_id = Maybe Int
icon_custom_emoji_id_
, style :: InlineKeyboardButton -> Maybe ButtonStyle
style = Maybe ButtonStyle
style_
, _type :: InlineKeyboardButton -> Maybe InlineKeyboardButtonType
_type = Maybe InlineKeyboardButtonType
_type_
}
= String
"InlineKeyboardButton"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"text" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
text_
, String
"icon_custom_emoji_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
icon_custom_emoji_id_
, String
"style" String -> Maybe ButtonStyle -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ButtonStyle
style_
, String
"_type" String -> Maybe InlineKeyboardButtonType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InlineKeyboardButtonType
_type_
]
instance AT.FromJSON InlineKeyboardButton where
parseJSON :: Value -> Parser InlineKeyboardButton
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
"inlineKeyboardButton" -> Value -> Parser InlineKeyboardButton
parseInlineKeyboardButton Value
v
String
_ -> Parser InlineKeyboardButton
forall a. Monoid a => a
mempty
where
parseInlineKeyboardButton :: A.Value -> AT.Parser InlineKeyboardButton
parseInlineKeyboardButton :: Value -> Parser InlineKeyboardButton
parseInlineKeyboardButton = String
-> (Object -> Parser InlineKeyboardButton)
-> Value
-> Parser InlineKeyboardButton
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InlineKeyboardButton" ((Object -> Parser InlineKeyboardButton)
-> Value -> Parser InlineKeyboardButton)
-> (Object -> Parser InlineKeyboardButton)
-> Value
-> Parser InlineKeyboardButton
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
text_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"text"
Maybe Int
icon_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
"icon_custom_emoji_id"
Maybe ButtonStyle
style_ <- Object
o Object -> Key -> Parser (Maybe ButtonStyle)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"style"
Maybe InlineKeyboardButtonType
_type_ <- Object
o Object -> Key -> Parser (Maybe InlineKeyboardButtonType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
InlineKeyboardButton -> Parser InlineKeyboardButton
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InlineKeyboardButton -> Parser InlineKeyboardButton)
-> InlineKeyboardButton -> Parser InlineKeyboardButton
forall a b. (a -> b) -> a -> b
$ InlineKeyboardButton
{ text :: Maybe Text
text = Maybe Text
text_
, icon_custom_emoji_id :: Maybe Int
icon_custom_emoji_id = Maybe Int
icon_custom_emoji_id_
, style :: Maybe ButtonStyle
style = Maybe ButtonStyle
style_
, _type :: Maybe InlineKeyboardButtonType
_type = Maybe InlineKeyboardButtonType
_type_
}
parseJSON Value
_ = Parser InlineKeyboardButton
forall a. Monoid a => a
mempty
instance AT.ToJSON InlineKeyboardButton where
toJSON :: InlineKeyboardButton -> Value
toJSON InlineKeyboardButton
{ text :: InlineKeyboardButton -> Maybe Text
text = Maybe Text
text_
, icon_custom_emoji_id :: InlineKeyboardButton -> Maybe Int
icon_custom_emoji_id = Maybe Int
icon_custom_emoji_id_
, style :: InlineKeyboardButton -> Maybe ButtonStyle
style = Maybe ButtonStyle
style_
, _type :: InlineKeyboardButton -> Maybe InlineKeyboardButtonType
_type = Maybe InlineKeyboardButtonType
_type_
}
= [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
"inlineKeyboardButton"
, Key
"text" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
text_
, Key
"icon_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
icon_custom_emoji_id_
, Key
"style" Key -> Maybe ButtonStyle -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe ButtonStyle
style_
, Key
"type" Key -> Maybe InlineKeyboardButtonType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InlineKeyboardButtonType
_type_
]
defaultInlineKeyboardButton :: InlineKeyboardButton
defaultInlineKeyboardButton :: InlineKeyboardButton
defaultInlineKeyboardButton =
InlineKeyboardButton
{ text :: Maybe Text
text = Maybe Text
forall a. Maybe a
Nothing
, icon_custom_emoji_id :: Maybe Int
icon_custom_emoji_id = Maybe Int
forall a. Maybe a
Nothing
, style :: Maybe ButtonStyle
style = Maybe ButtonStyle
forall a. Maybe a
Nothing
, _type :: Maybe InlineKeyboardButtonType
_type = Maybe InlineKeyboardButtonType
forall a. Maybe a
Nothing
}