module TD.Query.SetRecoveryEmailAddress
  (SetRecoveryEmailAddress(..)
  , defaultSetRecoveryEmailAddress
  ) 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

-- | Changes the 2-step verification recovery email address of the user. If a new recovery email address is specified, then the change will not be applied until the new recovery email address is confirmed. If new_recovery_email_address is the same as the email address that is currently set up, this call succeeds immediately and aborts all other requests waiting for an email confirmation. Returns 'TD.Data.PasswordState.PasswordState'
data SetRecoveryEmailAddress
  = SetRecoveryEmailAddress
    { SetRecoveryEmailAddress -> Maybe Text
password                   :: Maybe T.Text -- ^ The 2-step verification password of the current user
    , SetRecoveryEmailAddress -> Maybe Text
new_recovery_email_address :: Maybe T.Text -- ^ New recovery email address
    }
  deriving (SetRecoveryEmailAddress -> SetRecoveryEmailAddress -> Bool
(SetRecoveryEmailAddress -> SetRecoveryEmailAddress -> Bool)
-> (SetRecoveryEmailAddress -> SetRecoveryEmailAddress -> Bool)
-> Eq SetRecoveryEmailAddress
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetRecoveryEmailAddress -> SetRecoveryEmailAddress -> Bool
== :: SetRecoveryEmailAddress -> SetRecoveryEmailAddress -> Bool
$c/= :: SetRecoveryEmailAddress -> SetRecoveryEmailAddress -> Bool
/= :: SetRecoveryEmailAddress -> SetRecoveryEmailAddress -> Bool
Eq, Int -> SetRecoveryEmailAddress -> ShowS
[SetRecoveryEmailAddress] -> ShowS
SetRecoveryEmailAddress -> String
(Int -> SetRecoveryEmailAddress -> ShowS)
-> (SetRecoveryEmailAddress -> String)
-> ([SetRecoveryEmailAddress] -> ShowS)
-> Show SetRecoveryEmailAddress
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetRecoveryEmailAddress -> ShowS
showsPrec :: Int -> SetRecoveryEmailAddress -> ShowS
$cshow :: SetRecoveryEmailAddress -> String
show :: SetRecoveryEmailAddress -> String
$cshowList :: [SetRecoveryEmailAddress] -> ShowS
showList :: [SetRecoveryEmailAddress] -> ShowS
Show)

instance I.ShortShow SetRecoveryEmailAddress where
  shortShow :: SetRecoveryEmailAddress -> String
shortShow
    SetRecoveryEmailAddress
      { password :: SetRecoveryEmailAddress -> Maybe Text
password                   = Maybe Text
password_
      , new_recovery_email_address :: SetRecoveryEmailAddress -> Maybe Text
new_recovery_email_address = Maybe Text
new_recovery_email_address_
      }
        = String
"SetRecoveryEmailAddress"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"password"                   String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
password_
          , String
"new_recovery_email_address" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
new_recovery_email_address_
          ]

instance AT.ToJSON SetRecoveryEmailAddress where
  toJSON :: SetRecoveryEmailAddress -> Value
toJSON
    SetRecoveryEmailAddress
      { password :: SetRecoveryEmailAddress -> Maybe Text
password                   = Maybe Text
password_
      , new_recovery_email_address :: SetRecoveryEmailAddress -> Maybe Text
new_recovery_email_address = Maybe Text
new_recovery_email_address_
      }
        = [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
"setRecoveryEmailAddress"
          , Key
"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
password_
          , Key
"new_recovery_email_address" 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_recovery_email_address_
          ]

defaultSetRecoveryEmailAddress :: SetRecoveryEmailAddress
defaultSetRecoveryEmailAddress :: SetRecoveryEmailAddress
defaultSetRecoveryEmailAddress =
  SetRecoveryEmailAddress
    { password :: Maybe Text
password                   = Maybe Text
forall a. Maybe a
Nothing
    , new_recovery_email_address :: Maybe Text
new_recovery_email_address = Maybe Text
forall a. Maybe a
Nothing
    }