module TD.Query.SetTonConnectSessionWalletClientId
  (SetTonConnectSessionWalletClientId(..)
  , defaultSetTonConnectSessionWalletClientId
  ) 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

-- | Sets wallet_client_id for a pending TON Connect session. Then, sendTonConnectSessionConnectResult must be used to accept or reject the session. If the session was created for an OAuth request, then acceptOauthRequest must be used instead. Returns 'TD.Data.TonConnectChallenge.TonConnectChallenge'
data SetTonConnectSessionWalletClientId
  = SetTonConnectSessionWalletClientId
    { SetTonConnectSessionWalletClientId -> Maybe Int
session_id       :: Maybe Int    -- ^ Unique identifier of the session
    , SetTonConnectSessionWalletClientId -> Maybe Text
wallet_client_id :: Maybe T.Text -- ^ Hex-encoded public X25519 key of the current user's application calculated from the TON wallet private key and session parameters
    }
  deriving (SetTonConnectSessionWalletClientId
-> SetTonConnectSessionWalletClientId -> Bool
(SetTonConnectSessionWalletClientId
 -> SetTonConnectSessionWalletClientId -> Bool)
-> (SetTonConnectSessionWalletClientId
    -> SetTonConnectSessionWalletClientId -> Bool)
-> Eq SetTonConnectSessionWalletClientId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetTonConnectSessionWalletClientId
-> SetTonConnectSessionWalletClientId -> Bool
== :: SetTonConnectSessionWalletClientId
-> SetTonConnectSessionWalletClientId -> Bool
$c/= :: SetTonConnectSessionWalletClientId
-> SetTonConnectSessionWalletClientId -> Bool
/= :: SetTonConnectSessionWalletClientId
-> SetTonConnectSessionWalletClientId -> Bool
Eq, Int -> SetTonConnectSessionWalletClientId -> ShowS
[SetTonConnectSessionWalletClientId] -> ShowS
SetTonConnectSessionWalletClientId -> String
(Int -> SetTonConnectSessionWalletClientId -> ShowS)
-> (SetTonConnectSessionWalletClientId -> String)
-> ([SetTonConnectSessionWalletClientId] -> ShowS)
-> Show SetTonConnectSessionWalletClientId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetTonConnectSessionWalletClientId -> ShowS
showsPrec :: Int -> SetTonConnectSessionWalletClientId -> ShowS
$cshow :: SetTonConnectSessionWalletClientId -> String
show :: SetTonConnectSessionWalletClientId -> String
$cshowList :: [SetTonConnectSessionWalletClientId] -> ShowS
showList :: [SetTonConnectSessionWalletClientId] -> ShowS
Show)

instance I.ShortShow SetTonConnectSessionWalletClientId where
  shortShow :: SetTonConnectSessionWalletClientId -> String
shortShow
    SetTonConnectSessionWalletClientId
      { session_id :: SetTonConnectSessionWalletClientId -> Maybe Int
session_id       = Maybe Int
session_id_
      , wallet_client_id :: SetTonConnectSessionWalletClientId -> Maybe Text
wallet_client_id = Maybe Text
wallet_client_id_
      }
        = String
"SetTonConnectSessionWalletClientId"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"session_id"       String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
session_id_
          , String
"wallet_client_id" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
wallet_client_id_
          ]

instance AT.ToJSON SetTonConnectSessionWalletClientId where
  toJSON :: SetTonConnectSessionWalletClientId -> Value
toJSON
    SetTonConnectSessionWalletClientId
      { session_id :: SetTonConnectSessionWalletClientId -> Maybe Int
session_id       = Maybe Int
session_id_
      , wallet_client_id :: SetTonConnectSessionWalletClientId -> Maybe Text
wallet_client_id = Maybe Text
wallet_client_id_
      }
        = [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
"setTonConnectSessionWalletClientId"
          , Key
"session_id"       Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (Int -> Value) -> Maybe Int -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Value
I.writeInt64  Maybe Int
session_id_
          , Key
"wallet_client_id" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
wallet_client_id_
          ]

defaultSetTonConnectSessionWalletClientId :: SetTonConnectSessionWalletClientId
defaultSetTonConnectSessionWalletClientId :: SetTonConnectSessionWalletClientId
defaultSetTonConnectSessionWalletClientId =
  SetTonConnectSessionWalletClientId
    { session_id :: Maybe Int
session_id       = Maybe Int
forall a. Maybe a
Nothing
    , wallet_client_id :: Maybe Text
wallet_client_id = Maybe Text
forall a. Maybe a
Nothing
    }