module TD.Query.CheckAuthenticationWebToken
  (CheckAuthenticationWebToken(..)
  , defaultCheckAuthenticationWebToken
  ) 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

-- | Checks a web token to log in to the corresponding account; for official Telegram apps only. Works only when the current authorization state is authorizationStateWaitPhoneNumber or authorizationStateWaitOtherDeviceConfirmation. Returns 'TD.Data.Ok.Ok'
data CheckAuthenticationWebToken
  = CheckAuthenticationWebToken
    { CheckAuthenticationWebToken -> Maybe Text
token :: Maybe T.Text -- ^ The token to check
    , CheckAuthenticationWebToken -> Maybe Int
dc_id :: Maybe Int    -- ^ Identifier of the datacenter of the user
    }
  deriving (CheckAuthenticationWebToken -> CheckAuthenticationWebToken -> Bool
(CheckAuthenticationWebToken
 -> CheckAuthenticationWebToken -> Bool)
-> (CheckAuthenticationWebToken
    -> CheckAuthenticationWebToken -> Bool)
-> Eq CheckAuthenticationWebToken
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CheckAuthenticationWebToken -> CheckAuthenticationWebToken -> Bool
== :: CheckAuthenticationWebToken -> CheckAuthenticationWebToken -> Bool
$c/= :: CheckAuthenticationWebToken -> CheckAuthenticationWebToken -> Bool
/= :: CheckAuthenticationWebToken -> CheckAuthenticationWebToken -> Bool
Eq, Int -> CheckAuthenticationWebToken -> ShowS
[CheckAuthenticationWebToken] -> ShowS
CheckAuthenticationWebToken -> String
(Int -> CheckAuthenticationWebToken -> ShowS)
-> (CheckAuthenticationWebToken -> String)
-> ([CheckAuthenticationWebToken] -> ShowS)
-> Show CheckAuthenticationWebToken
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CheckAuthenticationWebToken -> ShowS
showsPrec :: Int -> CheckAuthenticationWebToken -> ShowS
$cshow :: CheckAuthenticationWebToken -> String
show :: CheckAuthenticationWebToken -> String
$cshowList :: [CheckAuthenticationWebToken] -> ShowS
showList :: [CheckAuthenticationWebToken] -> ShowS
Show)

instance I.ShortShow CheckAuthenticationWebToken where
  shortShow :: CheckAuthenticationWebToken -> String
shortShow
    CheckAuthenticationWebToken
      { token :: CheckAuthenticationWebToken -> Maybe Text
token = Maybe Text
token_
      , dc_id :: CheckAuthenticationWebToken -> Maybe Int
dc_id = Maybe Int
dc_id_
      }
        = String
"CheckAuthenticationWebToken"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"token" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
token_
          , String
"dc_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
dc_id_
          ]

instance AT.ToJSON CheckAuthenticationWebToken where
  toJSON :: CheckAuthenticationWebToken -> Value
toJSON
    CheckAuthenticationWebToken
      { token :: CheckAuthenticationWebToken -> Maybe Text
token = Maybe Text
token_
      , dc_id :: CheckAuthenticationWebToken -> Maybe Int
dc_id = Maybe Int
dc_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
"checkAuthenticationWebToken"
          , Key
"token" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
token_
          , Key
"dc_id" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
dc_id_
          ]

defaultCheckAuthenticationWebToken :: CheckAuthenticationWebToken
defaultCheckAuthenticationWebToken :: CheckAuthenticationWebToken
defaultCheckAuthenticationWebToken =
  CheckAuthenticationWebToken
    { token :: Maybe Text
token = Maybe Text
forall a. Maybe a
Nothing
    , dc_id :: Maybe Int
dc_id = Maybe Int
forall a. Maybe a
Nothing
    }