module TD.Data.KeyboardButton
( KeyboardButton(..)
, defaultKeyboardButton
) 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.KeyboardButtonType as KeyboardButtonType
data KeyboardButton
= KeyboardButton
{ KeyboardButton -> Maybe Text
text :: Maybe T.Text
, KeyboardButton -> Maybe KeyboardButtonType
_type :: Maybe KeyboardButtonType.KeyboardButtonType
}
deriving (KeyboardButton -> KeyboardButton -> Bool
(KeyboardButton -> KeyboardButton -> Bool)
-> (KeyboardButton -> KeyboardButton -> Bool) -> Eq KeyboardButton
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: KeyboardButton -> KeyboardButton -> Bool
== :: KeyboardButton -> KeyboardButton -> Bool
$c/= :: KeyboardButton -> KeyboardButton -> Bool
/= :: KeyboardButton -> KeyboardButton -> Bool
Eq, Int -> KeyboardButton -> ShowS
[KeyboardButton] -> ShowS
KeyboardButton -> String
(Int -> KeyboardButton -> ShowS)
-> (KeyboardButton -> String)
-> ([KeyboardButton] -> ShowS)
-> Show KeyboardButton
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> KeyboardButton -> ShowS
showsPrec :: Int -> KeyboardButton -> ShowS
$cshow :: KeyboardButton -> String
show :: KeyboardButton -> String
$cshowList :: [KeyboardButton] -> ShowS
showList :: [KeyboardButton] -> ShowS
Show)
instance I.ShortShow KeyboardButton where
shortShow :: KeyboardButton -> String
shortShow KeyboardButton
{ text :: KeyboardButton -> Maybe Text
text = Maybe Text
text_
, _type :: KeyboardButton -> Maybe KeyboardButtonType
_type = Maybe KeyboardButtonType
_type_
}
= String
"KeyboardButton"
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 KeyboardButtonType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe KeyboardButtonType
_type_
]
instance AT.FromJSON KeyboardButton where
parseJSON :: Value -> Parser KeyboardButton
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
"keyboardButton" -> Value -> Parser KeyboardButton
parseKeyboardButton Value
v
String
_ -> Parser KeyboardButton
forall a. Monoid a => a
mempty
where
parseKeyboardButton :: A.Value -> AT.Parser KeyboardButton
parseKeyboardButton :: Value -> Parser KeyboardButton
parseKeyboardButton = String
-> (Object -> Parser KeyboardButton)
-> Value
-> Parser KeyboardButton
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"KeyboardButton" ((Object -> Parser KeyboardButton)
-> Value -> Parser KeyboardButton)
-> (Object -> Parser KeyboardButton)
-> Value
-> Parser KeyboardButton
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 KeyboardButtonType
_type_ <- Object
o Object -> Key -> Parser (Maybe KeyboardButtonType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
KeyboardButton -> Parser KeyboardButton
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (KeyboardButton -> Parser KeyboardButton)
-> KeyboardButton -> Parser KeyboardButton
forall a b. (a -> b) -> a -> b
$ KeyboardButton
{ text :: Maybe Text
text = Maybe Text
text_
, _type :: Maybe KeyboardButtonType
_type = Maybe KeyboardButtonType
_type_
}
parseJSON Value
_ = Parser KeyboardButton
forall a. Monoid a => a
mempty
instance AT.ToJSON KeyboardButton where
toJSON :: KeyboardButton -> Value
toJSON KeyboardButton
{ text :: KeyboardButton -> Maybe Text
text = Maybe Text
text_
, _type :: KeyboardButton -> Maybe KeyboardButtonType
_type = Maybe KeyboardButtonType
_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
"keyboardButton"
, 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 KeyboardButtonType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe KeyboardButtonType
_type_
]
defaultKeyboardButton :: KeyboardButton
defaultKeyboardButton :: KeyboardButton
defaultKeyboardButton =
KeyboardButton
{ text :: Maybe Text
text = Maybe Text
forall a. Maybe a
Nothing
, _type :: Maybe KeyboardButtonType
_type = Maybe KeyboardButtonType
forall a. Maybe a
Nothing
}