module TD.Query.RecoverAuthenticationPassword
  (RecoverAuthenticationPassword(..)
  , defaultRecoverAuthenticationPassword
  ) 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

-- | Recovers the 2-step verification password with a password recovery code sent to an email address that was previously set up. Works only when the current authorization state is authorizationStateWaitPassword. Returns 'TD.Data.Ok.Ok'
data RecoverAuthenticationPassword
  = RecoverAuthenticationPassword
    { RecoverAuthenticationPassword -> Maybe Text
recovery_code :: Maybe T.Text -- ^ Recovery code to check
    , RecoverAuthenticationPassword -> Maybe Text
new_password  :: Maybe T.Text -- ^ New 2-step verification password of the user; may be empty to remove the password
    , RecoverAuthenticationPassword -> Maybe Text
new_hint      :: Maybe T.Text -- ^ New password hint; may be empty
    }
  deriving (RecoverAuthenticationPassword
-> RecoverAuthenticationPassword -> Bool
(RecoverAuthenticationPassword
 -> RecoverAuthenticationPassword -> Bool)
-> (RecoverAuthenticationPassword
    -> RecoverAuthenticationPassword -> Bool)
-> Eq RecoverAuthenticationPassword
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RecoverAuthenticationPassword
-> RecoverAuthenticationPassword -> Bool
== :: RecoverAuthenticationPassword
-> RecoverAuthenticationPassword -> Bool
$c/= :: RecoverAuthenticationPassword
-> RecoverAuthenticationPassword -> Bool
/= :: RecoverAuthenticationPassword
-> RecoverAuthenticationPassword -> Bool
Eq, Int -> RecoverAuthenticationPassword -> ShowS
[RecoverAuthenticationPassword] -> ShowS
RecoverAuthenticationPassword -> String
(Int -> RecoverAuthenticationPassword -> ShowS)
-> (RecoverAuthenticationPassword -> String)
-> ([RecoverAuthenticationPassword] -> ShowS)
-> Show RecoverAuthenticationPassword
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RecoverAuthenticationPassword -> ShowS
showsPrec :: Int -> RecoverAuthenticationPassword -> ShowS
$cshow :: RecoverAuthenticationPassword -> String
show :: RecoverAuthenticationPassword -> String
$cshowList :: [RecoverAuthenticationPassword] -> ShowS
showList :: [RecoverAuthenticationPassword] -> ShowS
Show)

instance I.ShortShow RecoverAuthenticationPassword where
  shortShow :: RecoverAuthenticationPassword -> String
shortShow
    RecoverAuthenticationPassword
      { recovery_code :: RecoverAuthenticationPassword -> Maybe Text
recovery_code = Maybe Text
recovery_code_
      , new_password :: RecoverAuthenticationPassword -> Maybe Text
new_password  = Maybe Text
new_password_
      , new_hint :: RecoverAuthenticationPassword -> Maybe Text
new_hint      = Maybe Text
new_hint_
      }
        = String
"RecoverAuthenticationPassword"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"recovery_code" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
recovery_code_
          , String
"new_password"  String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
new_password_
          , String
"new_hint"      String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
new_hint_
          ]

instance AT.ToJSON RecoverAuthenticationPassword where
  toJSON :: RecoverAuthenticationPassword -> Value
toJSON
    RecoverAuthenticationPassword
      { recovery_code :: RecoverAuthenticationPassword -> Maybe Text
recovery_code = Maybe Text
recovery_code_
      , new_password :: RecoverAuthenticationPassword -> Maybe Text
new_password  = Maybe Text
new_password_
      , new_hint :: RecoverAuthenticationPassword -> Maybe Text
new_hint      = Maybe Text
new_hint_
      }
        = [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
"recoverAuthenticationPassword"
          , Key
"recovery_code" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
recovery_code_
          , Key
"new_password"  Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
new_password_
          , Key
"new_hint"      Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
new_hint_
          ]

defaultRecoverAuthenticationPassword :: RecoverAuthenticationPassword
defaultRecoverAuthenticationPassword :: RecoverAuthenticationPassword
defaultRecoverAuthenticationPassword =
  RecoverAuthenticationPassword
    { recovery_code :: Maybe Text
recovery_code = Maybe Text
forall a. Maybe a
Nothing
    , new_password :: Maybe Text
new_password  = Maybe Text
forall a. Maybe a
Nothing
    , new_hint :: Maybe Text
new_hint      = Maybe Text
forall a. Maybe a
Nothing
    }