module TD.Query.CheckAuthenticationPasskey
  (CheckAuthenticationPasskey(..)
  , defaultCheckAuthenticationPasskey
  ) 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 Data.ByteString as BS

-- | Checks a passkey to log in to the corresponding account. Call getAuthenticationPasskeyParameters to get parameters for the passkey. Works only when the current authorization state is authorizationStateWaitPhoneNumber or authorizationStateWaitOtherDeviceConfirmation, or if there is no pending authentication query and the current authorization state is authorizationStateWaitPremiumPurchase, authorizationStateWaitEmailAddress, authorizationStateWaitEmailCode, authorizationStateWaitCode, authorizationStateWaitRegistration, or authorizationStateWaitPassword. Returns 'TD.Data.Ok.Ok'
data CheckAuthenticationPasskey
  = CheckAuthenticationPasskey
    { CheckAuthenticationPasskey -> Maybe Text
credential_id      :: Maybe T.Text        -- ^ Base64url-encoded identifier of the credential
    , CheckAuthenticationPasskey -> Maybe Text
client_data        :: Maybe T.Text        -- ^ JSON-encoded client data
    , CheckAuthenticationPasskey -> Maybe ByteString
authenticator_data :: Maybe BS.ByteString -- ^ Authenticator data of the application that created the credential
    , CheckAuthenticationPasskey -> Maybe ByteString
signature          :: Maybe BS.ByteString -- ^ Cryptographic signature of the credential
    , CheckAuthenticationPasskey -> Maybe ByteString
user_handle        :: Maybe BS.ByteString -- ^ User handle of the passkey
    }
  deriving (CheckAuthenticationPasskey -> CheckAuthenticationPasskey -> Bool
(CheckAuthenticationPasskey -> CheckAuthenticationPasskey -> Bool)
-> (CheckAuthenticationPasskey
    -> CheckAuthenticationPasskey -> Bool)
-> Eq CheckAuthenticationPasskey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CheckAuthenticationPasskey -> CheckAuthenticationPasskey -> Bool
== :: CheckAuthenticationPasskey -> CheckAuthenticationPasskey -> Bool
$c/= :: CheckAuthenticationPasskey -> CheckAuthenticationPasskey -> Bool
/= :: CheckAuthenticationPasskey -> CheckAuthenticationPasskey -> Bool
Eq, Int -> CheckAuthenticationPasskey -> ShowS
[CheckAuthenticationPasskey] -> ShowS
CheckAuthenticationPasskey -> String
(Int -> CheckAuthenticationPasskey -> ShowS)
-> (CheckAuthenticationPasskey -> String)
-> ([CheckAuthenticationPasskey] -> ShowS)
-> Show CheckAuthenticationPasskey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CheckAuthenticationPasskey -> ShowS
showsPrec :: Int -> CheckAuthenticationPasskey -> ShowS
$cshow :: CheckAuthenticationPasskey -> String
show :: CheckAuthenticationPasskey -> String
$cshowList :: [CheckAuthenticationPasskey] -> ShowS
showList :: [CheckAuthenticationPasskey] -> ShowS
Show)

instance I.ShortShow CheckAuthenticationPasskey where
  shortShow :: CheckAuthenticationPasskey -> String
shortShow
    CheckAuthenticationPasskey
      { credential_id :: CheckAuthenticationPasskey -> Maybe Text
credential_id      = Maybe Text
credential_id_
      , client_data :: CheckAuthenticationPasskey -> Maybe Text
client_data        = Maybe Text
client_data_
      , authenticator_data :: CheckAuthenticationPasskey -> Maybe ByteString
authenticator_data = Maybe ByteString
authenticator_data_
      , signature :: CheckAuthenticationPasskey -> Maybe ByteString
signature          = Maybe ByteString
signature_
      , user_handle :: CheckAuthenticationPasskey -> Maybe ByteString
user_handle        = Maybe ByteString
user_handle_
      }
        = String
"CheckAuthenticationPasskey"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"credential_id"      String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
credential_id_
          , String
"client_data"        String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
client_data_
          , String
"authenticator_data" String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
authenticator_data_
          , String
"signature"          String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
signature_
          , String
"user_handle"        String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
user_handle_
          ]

instance AT.ToJSON CheckAuthenticationPasskey where
  toJSON :: CheckAuthenticationPasskey -> Value
toJSON
    CheckAuthenticationPasskey
      { credential_id :: CheckAuthenticationPasskey -> Maybe Text
credential_id      = Maybe Text
credential_id_
      , client_data :: CheckAuthenticationPasskey -> Maybe Text
client_data        = Maybe Text
client_data_
      , authenticator_data :: CheckAuthenticationPasskey -> Maybe ByteString
authenticator_data = Maybe ByteString
authenticator_data_
      , signature :: CheckAuthenticationPasskey -> Maybe ByteString
signature          = Maybe ByteString
signature_
      , user_handle :: CheckAuthenticationPasskey -> Maybe ByteString
user_handle        = Maybe ByteString
user_handle_
      }
        = [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
"checkAuthenticationPasskey"
          , Key
"credential_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
credential_id_
          , Key
"client_data"        Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
client_data_
          , Key
"authenticator_data" 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
authenticator_data_
          , Key
"signature"          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
signature_
          , Key
"user_handle"        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
user_handle_
          ]

defaultCheckAuthenticationPasskey :: CheckAuthenticationPasskey
defaultCheckAuthenticationPasskey :: CheckAuthenticationPasskey
defaultCheckAuthenticationPasskey =
  CheckAuthenticationPasskey
    { credential_id :: Maybe Text
credential_id      = Maybe Text
forall a. Maybe a
Nothing
    , client_data :: Maybe Text
client_data        = Maybe Text
forall a. Maybe a
Nothing
    , authenticator_data :: Maybe ByteString
authenticator_data = Maybe ByteString
forall a. Maybe a
Nothing
    , signature :: Maybe ByteString
signature          = Maybe ByteString
forall a. Maybe a
Nothing
    , user_handle :: Maybe ByteString
user_handle        = Maybe ByteString
forall a. Maybe a
Nothing
    }