module TD.Query.ResendAuthenticationCode
  (ResendAuthenticationCode(..)
  ) where

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

-- | Resends an authentication code to the user. Works only when the current authorization state is authorizationStateWaitCode, the next_code_type of the result is not null and the server-specified timeout has passed, or when the current authorization state is authorizationStateWaitEmailCode. Returns 'TD.Data.Ok.Ok'
data ResendAuthenticationCode
  = ResendAuthenticationCode
    { ResendAuthenticationCode -> Maybe ResendCodeReason
reason :: Maybe ResendCodeReason.ResendCodeReason -- ^ Reason of code resending; pass null if unknown
    }
  deriving (ResendAuthenticationCode -> ResendAuthenticationCode -> Bool
(ResendAuthenticationCode -> ResendAuthenticationCode -> Bool)
-> (ResendAuthenticationCode -> ResendAuthenticationCode -> Bool)
-> Eq ResendAuthenticationCode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ResendAuthenticationCode -> ResendAuthenticationCode -> Bool
== :: ResendAuthenticationCode -> ResendAuthenticationCode -> Bool
$c/= :: ResendAuthenticationCode -> ResendAuthenticationCode -> Bool
/= :: ResendAuthenticationCode -> ResendAuthenticationCode -> Bool
Eq, Int -> ResendAuthenticationCode -> ShowS
[ResendAuthenticationCode] -> ShowS
ResendAuthenticationCode -> String
(Int -> ResendAuthenticationCode -> ShowS)
-> (ResendAuthenticationCode -> String)
-> ([ResendAuthenticationCode] -> ShowS)
-> Show ResendAuthenticationCode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ResendAuthenticationCode -> ShowS
showsPrec :: Int -> ResendAuthenticationCode -> ShowS
$cshow :: ResendAuthenticationCode -> String
show :: ResendAuthenticationCode -> String
$cshowList :: [ResendAuthenticationCode] -> ShowS
showList :: [ResendAuthenticationCode] -> ShowS
Show)

instance I.ShortShow ResendAuthenticationCode where
  shortShow :: ResendAuthenticationCode -> String
shortShow
    ResendAuthenticationCode
      { reason :: ResendAuthenticationCode -> Maybe ResendCodeReason
reason = Maybe ResendCodeReason
reason_
      }
        = String
"ResendAuthenticationCode"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"reason" String -> Maybe ResendCodeReason -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ResendCodeReason
reason_
          ]

instance AT.ToJSON ResendAuthenticationCode where
  toJSON :: ResendAuthenticationCode -> Value
toJSON
    ResendAuthenticationCode
      { reason :: ResendAuthenticationCode -> Maybe ResendCodeReason
reason = Maybe ResendCodeReason
reason_
      }
        = [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
"resendAuthenticationCode"
          , Key
"reason" Key -> Maybe ResendCodeReason -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe ResendCodeReason
reason_
          ]