module TD.Query.SendCustomRequest
  (SendCustomRequest(..)
  , defaultSendCustomRequest
  ) 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; for bots only. Returns 'TD.Data.CustomRequestResult.CustomRequestResult'
data SendCustomRequest
  = SendCustomRequest
    { SendCustomRequest -> Maybe Text
method     :: Maybe T.Text -- ^ The method name
    , SendCustomRequest -> Maybe Text
parameters :: Maybe T.Text -- ^ JSON-serialized method parameters
    }
  deriving (SendCustomRequest -> SendCustomRequest -> Bool
(SendCustomRequest -> SendCustomRequest -> Bool)
-> (SendCustomRequest -> SendCustomRequest -> Bool)
-> Eq SendCustomRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SendCustomRequest -> SendCustomRequest -> Bool
== :: SendCustomRequest -> SendCustomRequest -> Bool
$c/= :: SendCustomRequest -> SendCustomRequest -> Bool
/= :: SendCustomRequest -> SendCustomRequest -> Bool
Eq, Int -> SendCustomRequest -> ShowS
[SendCustomRequest] -> ShowS
SendCustomRequest -> String
(Int -> SendCustomRequest -> ShowS)
-> (SendCustomRequest -> String)
-> ([SendCustomRequest] -> ShowS)
-> Show SendCustomRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SendCustomRequest -> ShowS
showsPrec :: Int -> SendCustomRequest -> ShowS
$cshow :: SendCustomRequest -> String
show :: SendCustomRequest -> String
$cshowList :: [SendCustomRequest] -> ShowS
showList :: [SendCustomRequest] -> ShowS
Show)

instance I.ShortShow SendCustomRequest where
  shortShow :: SendCustomRequest -> String
shortShow
    SendCustomRequest
      { method :: SendCustomRequest -> Maybe Text
method     = Maybe Text
method_
      , parameters :: SendCustomRequest -> Maybe Text
parameters = Maybe Text
parameters_
      }
        = String
"SendCustomRequest"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ 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 SendCustomRequest where
  toJSON :: SendCustomRequest -> Value
toJSON
    SendCustomRequest
      { method :: SendCustomRequest -> Maybe Text
method     = Maybe Text
method_
      , parameters :: SendCustomRequest -> 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
"sendCustomRequest"
          , 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_
          ]

defaultSendCustomRequest :: SendCustomRequest
defaultSendCustomRequest :: SendCustomRequest
defaultSendCustomRequest =
  SendCustomRequest
    { method :: Maybe Text
method     = Maybe Text
forall a. Maybe a
Nothing
    , parameters :: Maybe Text
parameters = Maybe Text
forall a. Maybe a
Nothing
    }