module TD.Data.CallbackQueryPayload
(CallbackQueryPayload(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.ByteString as BS
import qualified Data.Text as T
data CallbackQueryPayload
= CallbackQueryPayloadData
{ CallbackQueryPayload -> Maybe ByteString
_data :: Maybe BS.ByteString
}
| CallbackQueryPayloadDataWithPassword
{ CallbackQueryPayload -> Maybe Text
password :: Maybe T.Text
, _data :: Maybe BS.ByteString
}
| CallbackQueryPayloadGame
{ CallbackQueryPayload -> Maybe Text
game_short_name :: Maybe T.Text
}
deriving (CallbackQueryPayload -> CallbackQueryPayload -> Bool
(CallbackQueryPayload -> CallbackQueryPayload -> Bool)
-> (CallbackQueryPayload -> CallbackQueryPayload -> Bool)
-> Eq CallbackQueryPayload
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CallbackQueryPayload -> CallbackQueryPayload -> Bool
== :: CallbackQueryPayload -> CallbackQueryPayload -> Bool
$c/= :: CallbackQueryPayload -> CallbackQueryPayload -> Bool
/= :: CallbackQueryPayload -> CallbackQueryPayload -> Bool
Eq, Int -> CallbackQueryPayload -> ShowS
[CallbackQueryPayload] -> ShowS
CallbackQueryPayload -> String
(Int -> CallbackQueryPayload -> ShowS)
-> (CallbackQueryPayload -> String)
-> ([CallbackQueryPayload] -> ShowS)
-> Show CallbackQueryPayload
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CallbackQueryPayload -> ShowS
showsPrec :: Int -> CallbackQueryPayload -> ShowS
$cshow :: CallbackQueryPayload -> String
show :: CallbackQueryPayload -> String
$cshowList :: [CallbackQueryPayload] -> ShowS
showList :: [CallbackQueryPayload] -> ShowS
Show)
instance I.ShortShow CallbackQueryPayload where
shortShow :: CallbackQueryPayload -> String
shortShow CallbackQueryPayloadData
{ _data :: CallbackQueryPayload -> Maybe ByteString
_data = Maybe ByteString
_data_
}
= String
"CallbackQueryPayloadData"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_data" String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
_data_
]
shortShow CallbackQueryPayloadDataWithPassword
{ password :: CallbackQueryPayload -> Maybe Text
password = Maybe Text
password_
, _data :: CallbackQueryPayload -> Maybe ByteString
_data = Maybe ByteString
_data_
}
= String
"CallbackQueryPayloadDataWithPassword"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"password" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
password_
, String
"_data" String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
_data_
]
shortShow CallbackQueryPayloadGame
{ game_short_name :: CallbackQueryPayload -> Maybe Text
game_short_name = Maybe Text
game_short_name_
}
= String
"CallbackQueryPayloadGame"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"game_short_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
game_short_name_
]
instance AT.FromJSON CallbackQueryPayload where
parseJSON :: Value -> Parser CallbackQueryPayload
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
"callbackQueryPayloadData" -> Value -> Parser CallbackQueryPayload
parseCallbackQueryPayloadData Value
v
String
"callbackQueryPayloadDataWithPassword" -> Value -> Parser CallbackQueryPayload
parseCallbackQueryPayloadDataWithPassword Value
v
String
"callbackQueryPayloadGame" -> Value -> Parser CallbackQueryPayload
parseCallbackQueryPayloadGame Value
v
String
_ -> Parser CallbackQueryPayload
forall a. Monoid a => a
mempty
where
parseCallbackQueryPayloadData :: A.Value -> AT.Parser CallbackQueryPayload
parseCallbackQueryPayloadData :: Value -> Parser CallbackQueryPayload
parseCallbackQueryPayloadData = String
-> (Object -> Parser CallbackQueryPayload)
-> Value
-> Parser CallbackQueryPayload
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CallbackQueryPayloadData" ((Object -> Parser CallbackQueryPayload)
-> Value -> Parser CallbackQueryPayload)
-> (Object -> Parser CallbackQueryPayload)
-> Value
-> Parser CallbackQueryPayload
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe ByteString
_data_ <- (String -> ByteString) -> Maybe String -> Maybe ByteString
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> ByteString
I.readBytes (Maybe String -> Maybe ByteString)
-> Parser (Maybe String) -> Parser (Maybe ByteString)
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
"data"
CallbackQueryPayload -> Parser CallbackQueryPayload
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CallbackQueryPayload -> Parser CallbackQueryPayload)
-> CallbackQueryPayload -> Parser CallbackQueryPayload
forall a b. (a -> b) -> a -> b
$ CallbackQueryPayloadData
{ _data :: Maybe ByteString
_data = Maybe ByteString
_data_
}
parseCallbackQueryPayloadDataWithPassword :: A.Value -> AT.Parser CallbackQueryPayload
parseCallbackQueryPayloadDataWithPassword :: Value -> Parser CallbackQueryPayload
parseCallbackQueryPayloadDataWithPassword = String
-> (Object -> Parser CallbackQueryPayload)
-> Value
-> Parser CallbackQueryPayload
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CallbackQueryPayloadDataWithPassword" ((Object -> Parser CallbackQueryPayload)
-> Value -> Parser CallbackQueryPayload)
-> (Object -> Parser CallbackQueryPayload)
-> Value
-> Parser CallbackQueryPayload
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
password_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"password"
Maybe ByteString
_data_ <- (String -> ByteString) -> Maybe String -> Maybe ByteString
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> ByteString
I.readBytes (Maybe String -> Maybe ByteString)
-> Parser (Maybe String) -> Parser (Maybe ByteString)
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
"data"
CallbackQueryPayload -> Parser CallbackQueryPayload
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CallbackQueryPayload -> Parser CallbackQueryPayload)
-> CallbackQueryPayload -> Parser CallbackQueryPayload
forall a b. (a -> b) -> a -> b
$ CallbackQueryPayloadDataWithPassword
{ password :: Maybe Text
password = Maybe Text
password_
, _data :: Maybe ByteString
_data = Maybe ByteString
_data_
}
parseCallbackQueryPayloadGame :: A.Value -> AT.Parser CallbackQueryPayload
parseCallbackQueryPayloadGame :: Value -> Parser CallbackQueryPayload
parseCallbackQueryPayloadGame = String
-> (Object -> Parser CallbackQueryPayload)
-> Value
-> Parser CallbackQueryPayload
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CallbackQueryPayloadGame" ((Object -> Parser CallbackQueryPayload)
-> Value -> Parser CallbackQueryPayload)
-> (Object -> Parser CallbackQueryPayload)
-> Value
-> Parser CallbackQueryPayload
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
game_short_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"game_short_name"
CallbackQueryPayload -> Parser CallbackQueryPayload
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CallbackQueryPayload -> Parser CallbackQueryPayload)
-> CallbackQueryPayload -> Parser CallbackQueryPayload
forall a b. (a -> b) -> a -> b
$ CallbackQueryPayloadGame
{ game_short_name :: Maybe Text
game_short_name = Maybe Text
game_short_name_
}
parseJSON Value
_ = Parser CallbackQueryPayload
forall a. Monoid a => a
mempty
instance AT.ToJSON CallbackQueryPayload where
toJSON :: CallbackQueryPayload -> Value
toJSON CallbackQueryPayloadData
{ _data :: CallbackQueryPayload -> Maybe ByteString
_data = Maybe ByteString
_data_
}
= [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
"callbackQueryPayloadData"
, Key
"data" Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (ByteString -> Value) -> Maybe ByteString -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Value
I.writeBytes Maybe ByteString
_data_
]
toJSON CallbackQueryPayloadDataWithPassword
{ password :: CallbackQueryPayload -> Maybe Text
password = Maybe Text
password_
, _data :: CallbackQueryPayload -> Maybe ByteString
_data = Maybe ByteString
_data_
}
= [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
"callbackQueryPayloadDataWithPassword"
, Key
"password" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
password_
, Key
"data" Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (ByteString -> Value) -> Maybe ByteString -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Value
I.writeBytes Maybe ByteString
_data_
]
toJSON CallbackQueryPayloadGame
{ game_short_name :: CallbackQueryPayload -> Maybe Text
game_short_name = Maybe Text
game_short_name_
}
= [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
"callbackQueryPayloadGame"
, Key
"game_short_name" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
game_short_name_
]