module TD.Query.SendWebAppData
  (SendWebAppData(..)
  , defaultSendWebAppData
  ) 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

-- | Sends data received from a keyboardButtonTypeWebApp Web App to a bot. Returns 'TD.Data.Ok.Ok'
data SendWebAppData
  = SendWebAppData
    { SendWebAppData -> Maybe Int
bot_user_id :: Maybe Int    -- ^ Identifier of the target bot
    , SendWebAppData -> Maybe Text
button_text :: Maybe T.Text -- ^ Text of the keyboardButtonTypeWebApp button, which opened the Web App
    , SendWebAppData -> Maybe Text
_data       :: Maybe T.Text -- ^ The data
    }
  deriving (SendWebAppData -> SendWebAppData -> Bool
(SendWebAppData -> SendWebAppData -> Bool)
-> (SendWebAppData -> SendWebAppData -> Bool) -> Eq SendWebAppData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SendWebAppData -> SendWebAppData -> Bool
== :: SendWebAppData -> SendWebAppData -> Bool
$c/= :: SendWebAppData -> SendWebAppData -> Bool
/= :: SendWebAppData -> SendWebAppData -> Bool
Eq, Int -> SendWebAppData -> ShowS
[SendWebAppData] -> ShowS
SendWebAppData -> String
(Int -> SendWebAppData -> ShowS)
-> (SendWebAppData -> String)
-> ([SendWebAppData] -> ShowS)
-> Show SendWebAppData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SendWebAppData -> ShowS
showsPrec :: Int -> SendWebAppData -> ShowS
$cshow :: SendWebAppData -> String
show :: SendWebAppData -> String
$cshowList :: [SendWebAppData] -> ShowS
showList :: [SendWebAppData] -> ShowS
Show)

instance I.ShortShow SendWebAppData where
  shortShow :: SendWebAppData -> String
shortShow
    SendWebAppData
      { bot_user_id :: SendWebAppData -> Maybe Int
bot_user_id = Maybe Int
bot_user_id_
      , button_text :: SendWebAppData -> Maybe Text
button_text = Maybe Text
button_text_
      , _data :: SendWebAppData -> Maybe Text
_data       = Maybe Text
_data_
      }
        = String
"SendWebAppData"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"bot_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
bot_user_id_
          , String
"button_text" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
button_text_
          , String
"_data"       String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_data_
          ]

instance AT.ToJSON SendWebAppData where
  toJSON :: SendWebAppData -> Value
toJSON
    SendWebAppData
      { bot_user_id :: SendWebAppData -> Maybe Int
bot_user_id = Maybe Int
bot_user_id_
      , button_text :: SendWebAppData -> Maybe Text
button_text = Maybe Text
button_text_
      , _data :: SendWebAppData -> Maybe Text
_data       = Maybe Text
_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
"sendWebAppData"
          , Key
"bot_user_id" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
bot_user_id_
          , Key
"button_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
button_text_
          , Key
"data"        Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
_data_
          ]

defaultSendWebAppData :: SendWebAppData
defaultSendWebAppData :: SendWebAppData
defaultSendWebAppData =
  SendWebAppData
    { bot_user_id :: Maybe Int
bot_user_id = Maybe Int
forall a. Maybe a
Nothing
    , button_text :: Maybe Text
button_text = Maybe Text
forall a. Maybe a
Nothing
    , _data :: Maybe Text
_data       = Maybe Text
forall a. Maybe a
Nothing
    }