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.InlineKeyboardButtonType as InlineKeyboardButtonType
data InlineKeyboardButton
= InlineKeyboardButton
{ InlineKeyboardButton -> Maybe Text
text :: Maybe T.Text
, 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_
, _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
"_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 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_
, _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_
, _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
"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
, _type :: Maybe InlineKeyboardButtonType
_type = Maybe InlineKeyboardButtonType
forall a. Maybe a
Nothing
}