{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CognitoIdentityProvider.Types.UserAttributeUpdateSettingsType
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CognitoIdentityProvider.Types.UserAttributeUpdateSettingsType where

import Amazonka.CognitoIdentityProvider.Types.VerifiedAttributeType
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | The settings for updates to user attributes. These settings include the
-- property @AttributesRequireVerificationBeforeUpdate@, a user-pool
-- setting that tells Amazon Cognito how to handle changes to the value of
-- your users\' email address and phone number attributes. For more
-- information, see
-- <https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-email-phone-verification.html#user-pool-settings-verifications-verify-attribute-updates Verifying updates to email addresses and phone numbers>.
--
-- /See:/ 'newUserAttributeUpdateSettingsType' smart constructor.
data UserAttributeUpdateSettingsType = UserAttributeUpdateSettingsType'
  { -- | Requires that your user verifies their email address, phone number, or
    -- both before Amazon Cognito updates the value of that attribute. When you
    -- update a user attribute that has this option activated, Amazon Cognito
    -- sends a verification message to the new phone number or email address.
    -- Amazon Cognito doesn’t change the value of the attribute until your user
    -- responds to the verification message and confirms the new value.
    --
    -- You can verify an updated email address or phone number with a
    -- <https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_VerifyUserAttribute.html VerifyUserAttribute>
    -- API request. You can also call the
    -- <https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UpdateUserAttributes.html UpdateUserAttributes>
    -- or
    -- <https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminUpdateUserAttributes.html AdminUpdateUserAttributes>
    -- API and set @email_verified@ or @phone_number_verified@ to true.
    --
    -- When @AttributesRequireVerificationBeforeUpdate@ is false, your user
    -- pool doesn\'t require that your users verify attribute changes before
    -- Amazon Cognito updates them. In a user pool where
    -- @AttributesRequireVerificationBeforeUpdate@ is false, API operations
    -- that change attribute values can immediately update a user’s @email@ or
    -- @phone_number@ attribute.
    UserAttributeUpdateSettingsType -> Maybe [VerifiedAttributeType]
attributesRequireVerificationBeforeUpdate :: Prelude.Maybe [VerifiedAttributeType]
  }
  deriving (UserAttributeUpdateSettingsType
-> UserAttributeUpdateSettingsType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UserAttributeUpdateSettingsType
-> UserAttributeUpdateSettingsType -> Bool
$c/= :: UserAttributeUpdateSettingsType
-> UserAttributeUpdateSettingsType -> Bool
== :: UserAttributeUpdateSettingsType
-> UserAttributeUpdateSettingsType -> Bool
$c== :: UserAttributeUpdateSettingsType
-> UserAttributeUpdateSettingsType -> Bool
Prelude.Eq, ReadPrec [UserAttributeUpdateSettingsType]
ReadPrec UserAttributeUpdateSettingsType
Int -> ReadS UserAttributeUpdateSettingsType
ReadS [UserAttributeUpdateSettingsType]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UserAttributeUpdateSettingsType]
$creadListPrec :: ReadPrec [UserAttributeUpdateSettingsType]
readPrec :: ReadPrec UserAttributeUpdateSettingsType
$creadPrec :: ReadPrec UserAttributeUpdateSettingsType
readList :: ReadS [UserAttributeUpdateSettingsType]
$creadList :: ReadS [UserAttributeUpdateSettingsType]
readsPrec :: Int -> ReadS UserAttributeUpdateSettingsType
$creadsPrec :: Int -> ReadS UserAttributeUpdateSettingsType
Prelude.Read, Int -> UserAttributeUpdateSettingsType -> ShowS
[UserAttributeUpdateSettingsType] -> ShowS
UserAttributeUpdateSettingsType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UserAttributeUpdateSettingsType] -> ShowS
$cshowList :: [UserAttributeUpdateSettingsType] -> ShowS
show :: UserAttributeUpdateSettingsType -> String
$cshow :: UserAttributeUpdateSettingsType -> String
showsPrec :: Int -> UserAttributeUpdateSettingsType -> ShowS
$cshowsPrec :: Int -> UserAttributeUpdateSettingsType -> ShowS
Prelude.Show, forall x.
Rep UserAttributeUpdateSettingsType x
-> UserAttributeUpdateSettingsType
forall x.
UserAttributeUpdateSettingsType
-> Rep UserAttributeUpdateSettingsType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UserAttributeUpdateSettingsType x
-> UserAttributeUpdateSettingsType
$cfrom :: forall x.
UserAttributeUpdateSettingsType
-> Rep UserAttributeUpdateSettingsType x
Prelude.Generic)

-- |
-- Create a value of 'UserAttributeUpdateSettingsType' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'attributesRequireVerificationBeforeUpdate', 'userAttributeUpdateSettingsType_attributesRequireVerificationBeforeUpdate' - Requires that your user verifies their email address, phone number, or
-- both before Amazon Cognito updates the value of that attribute. When you
-- update a user attribute that has this option activated, Amazon Cognito
-- sends a verification message to the new phone number or email address.
-- Amazon Cognito doesn’t change the value of the attribute until your user
-- responds to the verification message and confirms the new value.
--
-- You can verify an updated email address or phone number with a
-- <https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_VerifyUserAttribute.html VerifyUserAttribute>
-- API request. You can also call the
-- <https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UpdateUserAttributes.html UpdateUserAttributes>
-- or
-- <https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminUpdateUserAttributes.html AdminUpdateUserAttributes>
-- API and set @email_verified@ or @phone_number_verified@ to true.
--
-- When @AttributesRequireVerificationBeforeUpdate@ is false, your user
-- pool doesn\'t require that your users verify attribute changes before
-- Amazon Cognito updates them. In a user pool where
-- @AttributesRequireVerificationBeforeUpdate@ is false, API operations
-- that change attribute values can immediately update a user’s @email@ or
-- @phone_number@ attribute.
newUserAttributeUpdateSettingsType ::
  UserAttributeUpdateSettingsType
newUserAttributeUpdateSettingsType :: UserAttributeUpdateSettingsType
newUserAttributeUpdateSettingsType =
  UserAttributeUpdateSettingsType'
    { $sel:attributesRequireVerificationBeforeUpdate:UserAttributeUpdateSettingsType' :: Maybe [VerifiedAttributeType]
attributesRequireVerificationBeforeUpdate =
        forall a. Maybe a
Prelude.Nothing
    }

-- | Requires that your user verifies their email address, phone number, or
-- both before Amazon Cognito updates the value of that attribute. When you
-- update a user attribute that has this option activated, Amazon Cognito
-- sends a verification message to the new phone number or email address.
-- Amazon Cognito doesn’t change the value of the attribute until your user
-- responds to the verification message and confirms the new value.
--
-- You can verify an updated email address or phone number with a
-- <https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_VerifyUserAttribute.html VerifyUserAttribute>
-- API request. You can also call the
-- <https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UpdateUserAttributes.html UpdateUserAttributes>
-- or
-- <https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminUpdateUserAttributes.html AdminUpdateUserAttributes>
-- API and set @email_verified@ or @phone_number_verified@ to true.
--
-- When @AttributesRequireVerificationBeforeUpdate@ is false, your user
-- pool doesn\'t require that your users verify attribute changes before
-- Amazon Cognito updates them. In a user pool where
-- @AttributesRequireVerificationBeforeUpdate@ is false, API operations
-- that change attribute values can immediately update a user’s @email@ or
-- @phone_number@ attribute.
userAttributeUpdateSettingsType_attributesRequireVerificationBeforeUpdate :: Lens.Lens' UserAttributeUpdateSettingsType (Prelude.Maybe [VerifiedAttributeType])
userAttributeUpdateSettingsType_attributesRequireVerificationBeforeUpdate :: Lens'
  UserAttributeUpdateSettingsType (Maybe [VerifiedAttributeType])
userAttributeUpdateSettingsType_attributesRequireVerificationBeforeUpdate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserAttributeUpdateSettingsType' {Maybe [VerifiedAttributeType]
attributesRequireVerificationBeforeUpdate :: Maybe [VerifiedAttributeType]
$sel:attributesRequireVerificationBeforeUpdate:UserAttributeUpdateSettingsType' :: UserAttributeUpdateSettingsType -> Maybe [VerifiedAttributeType]
attributesRequireVerificationBeforeUpdate} -> Maybe [VerifiedAttributeType]
attributesRequireVerificationBeforeUpdate) (\s :: UserAttributeUpdateSettingsType
s@UserAttributeUpdateSettingsType' {} Maybe [VerifiedAttributeType]
a -> UserAttributeUpdateSettingsType
s {$sel:attributesRequireVerificationBeforeUpdate:UserAttributeUpdateSettingsType' :: Maybe [VerifiedAttributeType]
attributesRequireVerificationBeforeUpdate = Maybe [VerifiedAttributeType]
a} :: UserAttributeUpdateSettingsType) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance
  Data.FromJSON
    UserAttributeUpdateSettingsType
  where
  parseJSON :: Value -> Parser UserAttributeUpdateSettingsType
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"UserAttributeUpdateSettingsType"
      ( \Object
x ->
          Maybe [VerifiedAttributeType] -> UserAttributeUpdateSettingsType
UserAttributeUpdateSettingsType'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"AttributesRequireVerificationBeforeUpdate"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance
  Prelude.Hashable
    UserAttributeUpdateSettingsType
  where
  hashWithSalt :: Int -> UserAttributeUpdateSettingsType -> Int
hashWithSalt
    Int
_salt
    UserAttributeUpdateSettingsType' {Maybe [VerifiedAttributeType]
attributesRequireVerificationBeforeUpdate :: Maybe [VerifiedAttributeType]
$sel:attributesRequireVerificationBeforeUpdate:UserAttributeUpdateSettingsType' :: UserAttributeUpdateSettingsType -> Maybe [VerifiedAttributeType]
..} =
      Int
_salt
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [VerifiedAttributeType]
attributesRequireVerificationBeforeUpdate

instance
  Prelude.NFData
    UserAttributeUpdateSettingsType
  where
  rnf :: UserAttributeUpdateSettingsType -> ()
rnf UserAttributeUpdateSettingsType' {Maybe [VerifiedAttributeType]
attributesRequireVerificationBeforeUpdate :: Maybe [VerifiedAttributeType]
$sel:attributesRequireVerificationBeforeUpdate:UserAttributeUpdateSettingsType' :: UserAttributeUpdateSettingsType -> Maybe [VerifiedAttributeType]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf
      Maybe [VerifiedAttributeType]
attributesRequireVerificationBeforeUpdate

instance Data.ToJSON UserAttributeUpdateSettingsType where
  toJSON :: UserAttributeUpdateSettingsType -> Value
toJSON UserAttributeUpdateSettingsType' {Maybe [VerifiedAttributeType]
attributesRequireVerificationBeforeUpdate :: Maybe [VerifiedAttributeType]
$sel:attributesRequireVerificationBeforeUpdate:UserAttributeUpdateSettingsType' :: UserAttributeUpdateSettingsType -> Maybe [VerifiedAttributeType]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ ( Key
"AttributesRequireVerificationBeforeUpdate"
                forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=
            )
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [VerifiedAttributeType]
attributesRequireVerificationBeforeUpdate
          ]
      )