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