module TD.Query.DisconnectTonConnectSession
  (DisconnectTonConnectSession(..)
  , defaultDisconnectTonConnectSession
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.ByteString as BS

-- | Closes a TON Connect session. Returns 'TD.Data.Ok.Ok'
data DisconnectTonConnectSession
  = DisconnectTonConnectSession
    { DisconnectTonConnectSession -> Maybe Int
session_id :: Maybe Int           -- ^ Unique identifier of the TON Connect session to close
    , DisconnectTonConnectSession -> Maybe ByteString
body       :: Maybe BS.ByteString -- ^ Encrypted body of the disconnect event; may be empty if the session has already been closed. Use getTonConnectSessionNextEventId to get event identifier for the event
    }
  deriving (DisconnectTonConnectSession -> DisconnectTonConnectSession -> Bool
(DisconnectTonConnectSession
 -> DisconnectTonConnectSession -> Bool)
-> (DisconnectTonConnectSession
    -> DisconnectTonConnectSession -> Bool)
-> Eq DisconnectTonConnectSession
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DisconnectTonConnectSession -> DisconnectTonConnectSession -> Bool
== :: DisconnectTonConnectSession -> DisconnectTonConnectSession -> Bool
$c/= :: DisconnectTonConnectSession -> DisconnectTonConnectSession -> Bool
/= :: DisconnectTonConnectSession -> DisconnectTonConnectSession -> Bool
Eq, Int -> DisconnectTonConnectSession -> ShowS
[DisconnectTonConnectSession] -> ShowS
DisconnectTonConnectSession -> String
(Int -> DisconnectTonConnectSession -> ShowS)
-> (DisconnectTonConnectSession -> String)
-> ([DisconnectTonConnectSession] -> ShowS)
-> Show DisconnectTonConnectSession
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DisconnectTonConnectSession -> ShowS
showsPrec :: Int -> DisconnectTonConnectSession -> ShowS
$cshow :: DisconnectTonConnectSession -> String
show :: DisconnectTonConnectSession -> String
$cshowList :: [DisconnectTonConnectSession] -> ShowS
showList :: [DisconnectTonConnectSession] -> ShowS
Show)

instance I.ShortShow DisconnectTonConnectSession where
  shortShow :: DisconnectTonConnectSession -> String
shortShow
    DisconnectTonConnectSession
      { session_id :: DisconnectTonConnectSession -> Maybe Int
session_id = Maybe Int
session_id_
      , body :: DisconnectTonConnectSession -> Maybe ByteString
body       = Maybe ByteString
body_
      }
        = String
"DisconnectTonConnectSession"
          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
"body"       String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
body_
          ]

instance AT.ToJSON DisconnectTonConnectSession where
  toJSON :: DisconnectTonConnectSession -> Value
toJSON
    DisconnectTonConnectSession
      { session_id :: DisconnectTonConnectSession -> Maybe Int
session_id = Maybe Int
session_id_
      , body :: DisconnectTonConnectSession -> Maybe ByteString
body       = Maybe ByteString
body_
      }
        = [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
"disconnectTonConnectSession"
          , 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
"body"       Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (ByteString -> Value) -> Maybe ByteString -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Value
I.writeBytes  Maybe ByteString
body_
          ]

defaultDisconnectTonConnectSession :: DisconnectTonConnectSession
defaultDisconnectTonConnectSession :: DisconnectTonConnectSession
defaultDisconnectTonConnectSession =
  DisconnectTonConnectSession
    { session_id :: Maybe Int
session_id = Maybe Int
forall a. Maybe a
Nothing
    , body :: Maybe ByteString
body       = Maybe ByteString
forall a. Maybe a
Nothing
    }