module TD.Query.SendWebAppCustomRequest
  (SendWebAppCustomRequest(..)
  , defaultSendWebAppCustomRequest
  ) 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 a custom request from a Web App. Returns 'TD.Data.CustomRequestResult.CustomRequestResult'
data SendWebAppCustomRequest
  = SendWebAppCustomRequest
    { SendWebAppCustomRequest -> Maybe Int
bot_user_id :: Maybe Int    -- ^ Identifier of the bot
    , SendWebAppCustomRequest -> Maybe Text
method      :: Maybe T.Text -- ^ The method name
    , SendWebAppCustomRequest -> Maybe Text
parameters  :: Maybe T.Text -- ^ JSON-serialized method parameters
    }
  deriving (SendWebAppCustomRequest -> SendWebAppCustomRequest -> Bool
(SendWebAppCustomRequest -> SendWebAppCustomRequest -> Bool)
-> (SendWebAppCustomRequest -> SendWebAppCustomRequest -> Bool)
-> Eq SendWebAppCustomRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SendWebAppCustomRequest -> SendWebAppCustomRequest -> Bool
== :: SendWebAppCustomRequest -> SendWebAppCustomRequest -> Bool
$c/= :: SendWebAppCustomRequest -> SendWebAppCustomRequest -> Bool
/= :: SendWebAppCustomRequest -> SendWebAppCustomRequest -> Bool
Eq, Int -> SendWebAppCustomRequest -> ShowS
[SendWebAppCustomRequest] -> ShowS
SendWebAppCustomRequest -> String
(Int -> SendWebAppCustomRequest -> ShowS)
-> (SendWebAppCustomRequest -> String)
-> ([SendWebAppCustomRequest] -> ShowS)
-> Show SendWebAppCustomRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SendWebAppCustomRequest -> ShowS
showsPrec :: Int -> SendWebAppCustomRequest -> ShowS
$cshow :: SendWebAppCustomRequest -> String
show :: SendWebAppCustomRequest -> String
$cshowList :: [SendWebAppCustomRequest] -> ShowS
showList :: [SendWebAppCustomRequest] -> ShowS
Show)

instance I.ShortShow SendWebAppCustomRequest where
  shortShow :: SendWebAppCustomRequest -> String
shortShow
    SendWebAppCustomRequest
      { bot_user_id :: SendWebAppCustomRequest -> Maybe Int
bot_user_id = Maybe Int
bot_user_id_
      , method :: SendWebAppCustomRequest -> Maybe Text
method      = Maybe Text
method_
      , parameters :: SendWebAppCustomRequest -> Maybe Text
parameters  = Maybe Text
parameters_
      }
        = String
"SendWebAppCustomRequest"
          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
"method"      String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
method_
          , String
"parameters"  String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
parameters_
          ]

instance AT.ToJSON SendWebAppCustomRequest where
  toJSON :: SendWebAppCustomRequest -> Value
toJSON
    SendWebAppCustomRequest
      { bot_user_id :: SendWebAppCustomRequest -> Maybe Int
bot_user_id = Maybe Int
bot_user_id_
      , method :: SendWebAppCustomRequest -> Maybe Text
method      = Maybe Text
method_
      , parameters :: SendWebAppCustomRequest -> Maybe Text
parameters  = Maybe Text
parameters_
      }
        = [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
"sendWebAppCustomRequest"
          , 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
"method"      Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
method_
          , Key
"parameters"  Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
parameters_
          ]

defaultSendWebAppCustomRequest :: SendWebAppCustomRequest
defaultSendWebAppCustomRequest :: SendWebAppCustomRequest
defaultSendWebAppCustomRequest =
  SendWebAppCustomRequest
    { bot_user_id :: Maybe Int
bot_user_id = Maybe Int
forall a. Maybe a
Nothing
    , method :: Maybe Text
method      = Maybe Text
forall a. Maybe a
Nothing
    , parameters :: Maybe Text
parameters  = Maybe Text
forall a. Maybe a
Nothing
    }