module TD.Query.SendTonCenterApiRequest
  (SendTonCenterApiRequest(..)
  , defaultSendTonCenterApiRequest
  ) 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
import qualified TD.Data.TonCenterApiRequestType as TonCenterApiRequestType

-- | Sends a request to TON Center API and returns its response in JSON format. Returns 'TD.Data.Text.Text'
data SendTonCenterApiRequest
  = SendTonCenterApiRequest
    { SendTonCenterApiRequest -> Maybe Text
endpoint :: Maybe T.Text                                          -- ^ The path of the requested endpoint. See https://toncenter.com/api/v3/index.html for the list of supported endpoints
    , SendTonCenterApiRequest -> Maybe TonCenterApiRequestType
_type    :: Maybe TonCenterApiRequestType.TonCenterApiRequestType -- ^ Type of the request
    }
  deriving (SendTonCenterApiRequest -> SendTonCenterApiRequest -> Bool
(SendTonCenterApiRequest -> SendTonCenterApiRequest -> Bool)
-> (SendTonCenterApiRequest -> SendTonCenterApiRequest -> Bool)
-> Eq SendTonCenterApiRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SendTonCenterApiRequest -> SendTonCenterApiRequest -> Bool
== :: SendTonCenterApiRequest -> SendTonCenterApiRequest -> Bool
$c/= :: SendTonCenterApiRequest -> SendTonCenterApiRequest -> Bool
/= :: SendTonCenterApiRequest -> SendTonCenterApiRequest -> Bool
Eq, Int -> SendTonCenterApiRequest -> ShowS
[SendTonCenterApiRequest] -> ShowS
SendTonCenterApiRequest -> String
(Int -> SendTonCenterApiRequest -> ShowS)
-> (SendTonCenterApiRequest -> String)
-> ([SendTonCenterApiRequest] -> ShowS)
-> Show SendTonCenterApiRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SendTonCenterApiRequest -> ShowS
showsPrec :: Int -> SendTonCenterApiRequest -> ShowS
$cshow :: SendTonCenterApiRequest -> String
show :: SendTonCenterApiRequest -> String
$cshowList :: [SendTonCenterApiRequest] -> ShowS
showList :: [SendTonCenterApiRequest] -> ShowS
Show)

instance I.ShortShow SendTonCenterApiRequest where
  shortShow :: SendTonCenterApiRequest -> String
shortShow
    SendTonCenterApiRequest
      { endpoint :: SendTonCenterApiRequest -> Maybe Text
endpoint = Maybe Text
endpoint_
      , _type :: SendTonCenterApiRequest -> Maybe TonCenterApiRequestType
_type    = Maybe TonCenterApiRequestType
_type_
      }
        = String
"SendTonCenterApiRequest"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"endpoint" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
endpoint_
          , String
"_type"    String -> Maybe TonCenterApiRequestType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe TonCenterApiRequestType
_type_
          ]

instance AT.ToJSON SendTonCenterApiRequest where
  toJSON :: SendTonCenterApiRequest -> Value
toJSON
    SendTonCenterApiRequest
      { endpoint :: SendTonCenterApiRequest -> Maybe Text
endpoint = Maybe Text
endpoint_
      , _type :: SendTonCenterApiRequest -> Maybe TonCenterApiRequestType
_type    = Maybe TonCenterApiRequestType
_type_
      }
        = [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
"sendTonCenterApiRequest"
          , Key
"endpoint" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
endpoint_
          , Key
"type"     Key -> Maybe TonCenterApiRequestType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe TonCenterApiRequestType
_type_
          ]

defaultSendTonCenterApiRequest :: SendTonCenterApiRequest
defaultSendTonCenterApiRequest :: SendTonCenterApiRequest
defaultSendTonCenterApiRequest =
  SendTonCenterApiRequest
    { endpoint :: Maybe Text
endpoint = Maybe Text
forall a. Maybe a
Nothing
    , _type :: Maybe TonCenterApiRequestType
_type    = Maybe TonCenterApiRequestType
forall a. Maybe a
Nothing
    }