module TD.Query.SetPassword
  (SetPassword(..)
  , defaultSetPassword
  ) 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 password for the current user. If a new recovery email address is specified, then the change will not be applied until the new recovery email address is confirmed. Returns 'TD.Data.PasswordState.PasswordState'
data SetPassword
  = SetPassword
    { SetPassword -> Maybe Text
old_password               :: Maybe T.Text -- ^ Previous 2-step verification password of the user
    , SetPassword -> Maybe Text
new_password               :: Maybe T.Text -- ^ New 2-step verification password of the user; may be empty to remove the password
    , SetPassword -> Maybe Text
new_hint                   :: Maybe T.Text -- ^ New password hint; may be empty
    , SetPassword -> Maybe Bool
set_recovery_email_address :: Maybe Bool   -- ^ Pass true to change also the recovery email address
    , SetPassword -> Maybe Text
new_recovery_email_address :: Maybe T.Text -- ^ New recovery email address; may be empty
    }
  deriving (SetPassword -> SetPassword -> Bool
(SetPassword -> SetPassword -> Bool)
-> (SetPassword -> SetPassword -> Bool) -> Eq SetPassword
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetPassword -> SetPassword -> Bool
== :: SetPassword -> SetPassword -> Bool
$c/= :: SetPassword -> SetPassword -> Bool
/= :: SetPassword -> SetPassword -> Bool
Eq, Int -> SetPassword -> ShowS
[SetPassword] -> ShowS
SetPassword -> String
(Int -> SetPassword -> ShowS)
-> (SetPassword -> String)
-> ([SetPassword] -> ShowS)
-> Show SetPassword
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetPassword -> ShowS
showsPrec :: Int -> SetPassword -> ShowS
$cshow :: SetPassword -> String
show :: SetPassword -> String
$cshowList :: [SetPassword] -> ShowS
showList :: [SetPassword] -> ShowS
Show)

instance I.ShortShow SetPassword where
  shortShow :: SetPassword -> String
shortShow
    SetPassword
      { old_password :: SetPassword -> Maybe Text
old_password               = Maybe Text
old_password_
      , new_password :: SetPassword -> Maybe Text
new_password               = Maybe Text
new_password_
      , new_hint :: SetPassword -> Maybe Text
new_hint                   = Maybe Text
new_hint_
      , set_recovery_email_address :: SetPassword -> Maybe Bool
set_recovery_email_address = Maybe Bool
set_recovery_email_address_
      , new_recovery_email_address :: SetPassword -> Maybe Text
new_recovery_email_address = Maybe Text
new_recovery_email_address_
      }
        = String
"SetPassword"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"old_password"               String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
old_password_
          , 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_
          , String
"set_recovery_email_address" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
set_recovery_email_address_
          , 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 SetPassword where
  toJSON :: SetPassword -> Value
toJSON
    SetPassword
      { old_password :: SetPassword -> Maybe Text
old_password               = Maybe Text
old_password_
      , new_password :: SetPassword -> Maybe Text
new_password               = Maybe Text
new_password_
      , new_hint :: SetPassword -> Maybe Text
new_hint                   = Maybe Text
new_hint_
      , set_recovery_email_address :: SetPassword -> Maybe Bool
set_recovery_email_address = Maybe Bool
set_recovery_email_address_
      , new_recovery_email_address :: SetPassword -> 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
"setPassword"
          , Key
"old_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
old_password_
          , 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_
          , Key
"set_recovery_email_address" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
set_recovery_email_address_
          , 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_
          ]

defaultSetPassword :: SetPassword
defaultSetPassword :: SetPassword
defaultSetPassword =
  SetPassword
    { old_password :: Maybe Text
old_password               = 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
    , set_recovery_email_address :: Maybe Bool
set_recovery_email_address = Maybe Bool
forall a. Maybe a
Nothing
    , new_recovery_email_address :: Maybe Text
new_recovery_email_address = Maybe Text
forall a. Maybe a
Nothing
    }