module TD.Data.TonConnectSession
(TonConnectSession(..)) 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.TonConnectManifest as TonConnectManifest
import qualified Data.ByteString as BS
import qualified TD.Data.TonConnectSessionState as TonConnectSessionState
data TonConnectSession
= TonConnectSession
{ TonConnectSession -> Maybe Int
_id :: Maybe Int
, TonConnectSession -> Maybe Text
dapp_client_id :: Maybe T.Text
, TonConnectSession -> Maybe Text
wallet_client_id :: Maybe T.Text
, TonConnectSession -> Maybe Int
creation_date :: Maybe Int
, TonConnectSession -> Maybe TonConnectManifest
manifest :: Maybe TonConnectManifest.TonConnectManifest
, TonConnectSession -> Maybe ByteString
nonce :: Maybe BS.ByteString
, TonConnectSession -> Maybe TonConnectSessionState
state :: Maybe TonConnectSessionState.TonConnectSessionState
}
deriving (TonConnectSession -> TonConnectSession -> Bool
(TonConnectSession -> TonConnectSession -> Bool)
-> (TonConnectSession -> TonConnectSession -> Bool)
-> Eq TonConnectSession
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TonConnectSession -> TonConnectSession -> Bool
== :: TonConnectSession -> TonConnectSession -> Bool
$c/= :: TonConnectSession -> TonConnectSession -> Bool
/= :: TonConnectSession -> TonConnectSession -> Bool
Eq, Int -> TonConnectSession -> ShowS
[TonConnectSession] -> ShowS
TonConnectSession -> String
(Int -> TonConnectSession -> ShowS)
-> (TonConnectSession -> String)
-> ([TonConnectSession] -> ShowS)
-> Show TonConnectSession
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TonConnectSession -> ShowS
showsPrec :: Int -> TonConnectSession -> ShowS
$cshow :: TonConnectSession -> String
show :: TonConnectSession -> String
$cshowList :: [TonConnectSession] -> ShowS
showList :: [TonConnectSession] -> ShowS
Show)
instance I.ShortShow TonConnectSession where
shortShow :: TonConnectSession -> String
shortShow TonConnectSession
{ _id :: TonConnectSession -> Maybe Int
_id = Maybe Int
_id_
, dapp_client_id :: TonConnectSession -> Maybe Text
dapp_client_id = Maybe Text
dapp_client_id_
, wallet_client_id :: TonConnectSession -> Maybe Text
wallet_client_id = Maybe Text
wallet_client_id_
, creation_date :: TonConnectSession -> Maybe Int
creation_date = Maybe Int
creation_date_
, manifest :: TonConnectSession -> Maybe TonConnectManifest
manifest = Maybe TonConnectManifest
manifest_
, nonce :: TonConnectSession -> Maybe ByteString
nonce = Maybe ByteString
nonce_
, state :: TonConnectSession -> Maybe TonConnectSessionState
state = Maybe TonConnectSessionState
state_
}
= String
"TonConnectSession"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
, String
"dapp_client_id" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
dapp_client_id_
, String
"wallet_client_id" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
wallet_client_id_
, String
"creation_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
creation_date_
, String
"manifest" String -> Maybe TonConnectManifest -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe TonConnectManifest
manifest_
, String
"nonce" String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
nonce_
, String
"state" String -> Maybe TonConnectSessionState -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe TonConnectSessionState
state_
]
instance AT.FromJSON TonConnectSession where
parseJSON :: Value -> Parser TonConnectSession
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"tonConnectSession" -> Value -> Parser TonConnectSession
parseTonConnectSession Value
v
String
_ -> Parser TonConnectSession
forall a. Monoid a => a
mempty
where
parseTonConnectSession :: A.Value -> AT.Parser TonConnectSession
parseTonConnectSession :: Value -> Parser TonConnectSession
parseTonConnectSession = String
-> (Object -> Parser TonConnectSession)
-> Value
-> Parser TonConnectSession
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TonConnectSession" ((Object -> Parser TonConnectSession)
-> Value -> Parser TonConnectSession)
-> (Object -> Parser TonConnectSession)
-> Value
-> Parser TonConnectSession
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
_id_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"id"
Maybe Text
dapp_client_id_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"dapp_client_id"
Maybe Text
wallet_client_id_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"wallet_client_id"
Maybe Int
creation_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"creation_date"
Maybe TonConnectManifest
manifest_ <- Object
o Object -> Key -> Parser (Maybe TonConnectManifest)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"manifest"
Maybe ByteString
nonce_ <- (String -> ByteString) -> Maybe String -> Maybe ByteString
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> ByteString
I.readBytes (Maybe String -> Maybe ByteString)
-> Parser (Maybe String) -> Parser (Maybe ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"nonce"
Maybe TonConnectSessionState
state_ <- Object
o Object -> Key -> Parser (Maybe TonConnectSessionState)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"state"
TonConnectSession -> Parser TonConnectSession
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TonConnectSession -> Parser TonConnectSession)
-> TonConnectSession -> Parser TonConnectSession
forall a b. (a -> b) -> a -> b
$ TonConnectSession
{ _id :: Maybe Int
_id = Maybe Int
_id_
, dapp_client_id :: Maybe Text
dapp_client_id = Maybe Text
dapp_client_id_
, wallet_client_id :: Maybe Text
wallet_client_id = Maybe Text
wallet_client_id_
, creation_date :: Maybe Int
creation_date = Maybe Int
creation_date_
, manifest :: Maybe TonConnectManifest
manifest = Maybe TonConnectManifest
manifest_
, nonce :: Maybe ByteString
nonce = Maybe ByteString
nonce_
, state :: Maybe TonConnectSessionState
state = Maybe TonConnectSessionState
state_
}
parseJSON Value
_ = Parser TonConnectSession
forall a. Monoid a => a
mempty