{-# 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.AmplifyBackend.Types.CreateBackendAuthForgotPasswordConfig
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.AmplifyBackend.Types.CreateBackendAuthForgotPasswordConfig where

import Amazonka.AmplifyBackend.Types.DeliveryMethod
import Amazonka.AmplifyBackend.Types.EmailSettings
import Amazonka.AmplifyBackend.Types.SmsSettings
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes the forgot password policy for authenticating into the Amplify
-- app.
--
-- /See:/ 'newCreateBackendAuthForgotPasswordConfig' smart constructor.
data CreateBackendAuthForgotPasswordConfig = CreateBackendAuthForgotPasswordConfig'
  { -- | The configuration for the email sent when an app user forgets their
    -- password.
    CreateBackendAuthForgotPasswordConfig -> Maybe EmailSettings
emailSettings :: Prelude.Maybe EmailSettings,
    -- | The configuration for the SMS message sent when an app user forgets
    -- their password.
    CreateBackendAuthForgotPasswordConfig -> Maybe SmsSettings
smsSettings :: Prelude.Maybe SmsSettings,
    -- | Describes which mode to use (either SMS or email) to deliver messages to
    -- app users who want to recover their password.
    CreateBackendAuthForgotPasswordConfig -> DeliveryMethod
deliveryMethod :: DeliveryMethod
  }
  deriving (CreateBackendAuthForgotPasswordConfig
-> CreateBackendAuthForgotPasswordConfig -> Bool
(CreateBackendAuthForgotPasswordConfig
 -> CreateBackendAuthForgotPasswordConfig -> Bool)
-> (CreateBackendAuthForgotPasswordConfig
    -> CreateBackendAuthForgotPasswordConfig -> Bool)
-> Eq CreateBackendAuthForgotPasswordConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateBackendAuthForgotPasswordConfig
-> CreateBackendAuthForgotPasswordConfig -> Bool
$c/= :: CreateBackendAuthForgotPasswordConfig
-> CreateBackendAuthForgotPasswordConfig -> Bool
== :: CreateBackendAuthForgotPasswordConfig
-> CreateBackendAuthForgotPasswordConfig -> Bool
$c== :: CreateBackendAuthForgotPasswordConfig
-> CreateBackendAuthForgotPasswordConfig -> Bool
Prelude.Eq, ReadPrec [CreateBackendAuthForgotPasswordConfig]
ReadPrec CreateBackendAuthForgotPasswordConfig
Int -> ReadS CreateBackendAuthForgotPasswordConfig
ReadS [CreateBackendAuthForgotPasswordConfig]
(Int -> ReadS CreateBackendAuthForgotPasswordConfig)
-> ReadS [CreateBackendAuthForgotPasswordConfig]
-> ReadPrec CreateBackendAuthForgotPasswordConfig
-> ReadPrec [CreateBackendAuthForgotPasswordConfig]
-> Read CreateBackendAuthForgotPasswordConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateBackendAuthForgotPasswordConfig]
$creadListPrec :: ReadPrec [CreateBackendAuthForgotPasswordConfig]
readPrec :: ReadPrec CreateBackendAuthForgotPasswordConfig
$creadPrec :: ReadPrec CreateBackendAuthForgotPasswordConfig
readList :: ReadS [CreateBackendAuthForgotPasswordConfig]
$creadList :: ReadS [CreateBackendAuthForgotPasswordConfig]
readsPrec :: Int -> ReadS CreateBackendAuthForgotPasswordConfig
$creadsPrec :: Int -> ReadS CreateBackendAuthForgotPasswordConfig
Prelude.Read, Int -> CreateBackendAuthForgotPasswordConfig -> ShowS
[CreateBackendAuthForgotPasswordConfig] -> ShowS
CreateBackendAuthForgotPasswordConfig -> String
(Int -> CreateBackendAuthForgotPasswordConfig -> ShowS)
-> (CreateBackendAuthForgotPasswordConfig -> String)
-> ([CreateBackendAuthForgotPasswordConfig] -> ShowS)
-> Show CreateBackendAuthForgotPasswordConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateBackendAuthForgotPasswordConfig] -> ShowS
$cshowList :: [CreateBackendAuthForgotPasswordConfig] -> ShowS
show :: CreateBackendAuthForgotPasswordConfig -> String
$cshow :: CreateBackendAuthForgotPasswordConfig -> String
showsPrec :: Int -> CreateBackendAuthForgotPasswordConfig -> ShowS
$cshowsPrec :: Int -> CreateBackendAuthForgotPasswordConfig -> ShowS
Prelude.Show, (forall x.
 CreateBackendAuthForgotPasswordConfig
 -> Rep CreateBackendAuthForgotPasswordConfig x)
-> (forall x.
    Rep CreateBackendAuthForgotPasswordConfig x
    -> CreateBackendAuthForgotPasswordConfig)
-> Generic CreateBackendAuthForgotPasswordConfig
forall x.
Rep CreateBackendAuthForgotPasswordConfig x
-> CreateBackendAuthForgotPasswordConfig
forall x.
CreateBackendAuthForgotPasswordConfig
-> Rep CreateBackendAuthForgotPasswordConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateBackendAuthForgotPasswordConfig x
-> CreateBackendAuthForgotPasswordConfig
$cfrom :: forall x.
CreateBackendAuthForgotPasswordConfig
-> Rep CreateBackendAuthForgotPasswordConfig x
Prelude.Generic)

-- |
-- Create a value of 'CreateBackendAuthForgotPasswordConfig' 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:
--
-- 'emailSettings', 'createBackendAuthForgotPasswordConfig_emailSettings' - The configuration for the email sent when an app user forgets their
-- password.
--
-- 'smsSettings', 'createBackendAuthForgotPasswordConfig_smsSettings' - The configuration for the SMS message sent when an app user forgets
-- their password.
--
-- 'deliveryMethod', 'createBackendAuthForgotPasswordConfig_deliveryMethod' - Describes which mode to use (either SMS or email) to deliver messages to
-- app users who want to recover their password.
newCreateBackendAuthForgotPasswordConfig ::
  -- | 'deliveryMethod'
  DeliveryMethod ->
  CreateBackendAuthForgotPasswordConfig
newCreateBackendAuthForgotPasswordConfig :: DeliveryMethod -> CreateBackendAuthForgotPasswordConfig
newCreateBackendAuthForgotPasswordConfig
  DeliveryMethod
pDeliveryMethod_ =
    CreateBackendAuthForgotPasswordConfig' :: Maybe EmailSettings
-> Maybe SmsSettings
-> DeliveryMethod
-> CreateBackendAuthForgotPasswordConfig
CreateBackendAuthForgotPasswordConfig'
      { $sel:emailSettings:CreateBackendAuthForgotPasswordConfig' :: Maybe EmailSettings
emailSettings =
          Maybe EmailSettings
forall a. Maybe a
Prelude.Nothing,
        $sel:smsSettings:CreateBackendAuthForgotPasswordConfig' :: Maybe SmsSettings
smsSettings = Maybe SmsSettings
forall a. Maybe a
Prelude.Nothing,
        $sel:deliveryMethod:CreateBackendAuthForgotPasswordConfig' :: DeliveryMethod
deliveryMethod = DeliveryMethod
pDeliveryMethod_
      }

-- | The configuration for the email sent when an app user forgets their
-- password.
createBackendAuthForgotPasswordConfig_emailSettings :: Lens.Lens' CreateBackendAuthForgotPasswordConfig (Prelude.Maybe EmailSettings)
createBackendAuthForgotPasswordConfig_emailSettings :: (Maybe EmailSettings -> f (Maybe EmailSettings))
-> CreateBackendAuthForgotPasswordConfig
-> f CreateBackendAuthForgotPasswordConfig
createBackendAuthForgotPasswordConfig_emailSettings = (CreateBackendAuthForgotPasswordConfig -> Maybe EmailSettings)
-> (CreateBackendAuthForgotPasswordConfig
    -> Maybe EmailSettings -> CreateBackendAuthForgotPasswordConfig)
-> Lens
     CreateBackendAuthForgotPasswordConfig
     CreateBackendAuthForgotPasswordConfig
     (Maybe EmailSettings)
     (Maybe EmailSettings)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBackendAuthForgotPasswordConfig' {Maybe EmailSettings
emailSettings :: Maybe EmailSettings
$sel:emailSettings:CreateBackendAuthForgotPasswordConfig' :: CreateBackendAuthForgotPasswordConfig -> Maybe EmailSettings
emailSettings} -> Maybe EmailSettings
emailSettings) (\s :: CreateBackendAuthForgotPasswordConfig
s@CreateBackendAuthForgotPasswordConfig' {} Maybe EmailSettings
a -> CreateBackendAuthForgotPasswordConfig
s {$sel:emailSettings:CreateBackendAuthForgotPasswordConfig' :: Maybe EmailSettings
emailSettings = Maybe EmailSettings
a} :: CreateBackendAuthForgotPasswordConfig)

-- | The configuration for the SMS message sent when an app user forgets
-- their password.
createBackendAuthForgotPasswordConfig_smsSettings :: Lens.Lens' CreateBackendAuthForgotPasswordConfig (Prelude.Maybe SmsSettings)
createBackendAuthForgotPasswordConfig_smsSettings :: (Maybe SmsSettings -> f (Maybe SmsSettings))
-> CreateBackendAuthForgotPasswordConfig
-> f CreateBackendAuthForgotPasswordConfig
createBackendAuthForgotPasswordConfig_smsSettings = (CreateBackendAuthForgotPasswordConfig -> Maybe SmsSettings)
-> (CreateBackendAuthForgotPasswordConfig
    -> Maybe SmsSettings -> CreateBackendAuthForgotPasswordConfig)
-> Lens
     CreateBackendAuthForgotPasswordConfig
     CreateBackendAuthForgotPasswordConfig
     (Maybe SmsSettings)
     (Maybe SmsSettings)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBackendAuthForgotPasswordConfig' {Maybe SmsSettings
smsSettings :: Maybe SmsSettings
$sel:smsSettings:CreateBackendAuthForgotPasswordConfig' :: CreateBackendAuthForgotPasswordConfig -> Maybe SmsSettings
smsSettings} -> Maybe SmsSettings
smsSettings) (\s :: CreateBackendAuthForgotPasswordConfig
s@CreateBackendAuthForgotPasswordConfig' {} Maybe SmsSettings
a -> CreateBackendAuthForgotPasswordConfig
s {$sel:smsSettings:CreateBackendAuthForgotPasswordConfig' :: Maybe SmsSettings
smsSettings = Maybe SmsSettings
a} :: CreateBackendAuthForgotPasswordConfig)

-- | Describes which mode to use (either SMS or email) to deliver messages to
-- app users who want to recover their password.
createBackendAuthForgotPasswordConfig_deliveryMethod :: Lens.Lens' CreateBackendAuthForgotPasswordConfig DeliveryMethod
createBackendAuthForgotPasswordConfig_deliveryMethod :: (DeliveryMethod -> f DeliveryMethod)
-> CreateBackendAuthForgotPasswordConfig
-> f CreateBackendAuthForgotPasswordConfig
createBackendAuthForgotPasswordConfig_deliveryMethod = (CreateBackendAuthForgotPasswordConfig -> DeliveryMethod)
-> (CreateBackendAuthForgotPasswordConfig
    -> DeliveryMethod -> CreateBackendAuthForgotPasswordConfig)
-> Lens
     CreateBackendAuthForgotPasswordConfig
     CreateBackendAuthForgotPasswordConfig
     DeliveryMethod
     DeliveryMethod
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBackendAuthForgotPasswordConfig' {DeliveryMethod
deliveryMethod :: DeliveryMethod
$sel:deliveryMethod:CreateBackendAuthForgotPasswordConfig' :: CreateBackendAuthForgotPasswordConfig -> DeliveryMethod
deliveryMethod} -> DeliveryMethod
deliveryMethod) (\s :: CreateBackendAuthForgotPasswordConfig
s@CreateBackendAuthForgotPasswordConfig' {} DeliveryMethod
a -> CreateBackendAuthForgotPasswordConfig
s {$sel:deliveryMethod:CreateBackendAuthForgotPasswordConfig' :: DeliveryMethod
deliveryMethod = DeliveryMethod
a} :: CreateBackendAuthForgotPasswordConfig)

instance
  Core.FromJSON
    CreateBackendAuthForgotPasswordConfig
  where
  parseJSON :: Value -> Parser CreateBackendAuthForgotPasswordConfig
parseJSON =
    String
-> (Object -> Parser CreateBackendAuthForgotPasswordConfig)
-> Value
-> Parser CreateBackendAuthForgotPasswordConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CreateBackendAuthForgotPasswordConfig"
      ( \Object
x ->
          Maybe EmailSettings
-> Maybe SmsSettings
-> DeliveryMethod
-> CreateBackendAuthForgotPasswordConfig
CreateBackendAuthForgotPasswordConfig'
            (Maybe EmailSettings
 -> Maybe SmsSettings
 -> DeliveryMethod
 -> CreateBackendAuthForgotPasswordConfig)
-> Parser (Maybe EmailSettings)
-> Parser
     (Maybe SmsSettings
      -> DeliveryMethod -> CreateBackendAuthForgotPasswordConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe EmailSettings)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"emailSettings")
            Parser
  (Maybe SmsSettings
   -> DeliveryMethod -> CreateBackendAuthForgotPasswordConfig)
-> Parser (Maybe SmsSettings)
-> Parser (DeliveryMethod -> CreateBackendAuthForgotPasswordConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe SmsSettings)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"smsSettings")
            Parser (DeliveryMethod -> CreateBackendAuthForgotPasswordConfig)
-> Parser DeliveryMethod
-> Parser CreateBackendAuthForgotPasswordConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser DeliveryMethod
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"deliveryMethod")
      )

instance
  Prelude.Hashable
    CreateBackendAuthForgotPasswordConfig

instance
  Prelude.NFData
    CreateBackendAuthForgotPasswordConfig

instance
  Core.ToJSON
    CreateBackendAuthForgotPasswordConfig
  where
  toJSON :: CreateBackendAuthForgotPasswordConfig -> Value
toJSON CreateBackendAuthForgotPasswordConfig' {Maybe EmailSettings
Maybe SmsSettings
DeliveryMethod
deliveryMethod :: DeliveryMethod
smsSettings :: Maybe SmsSettings
emailSettings :: Maybe EmailSettings
$sel:deliveryMethod:CreateBackendAuthForgotPasswordConfig' :: CreateBackendAuthForgotPasswordConfig -> DeliveryMethod
$sel:smsSettings:CreateBackendAuthForgotPasswordConfig' :: CreateBackendAuthForgotPasswordConfig -> Maybe SmsSettings
$sel:emailSettings:CreateBackendAuthForgotPasswordConfig' :: CreateBackendAuthForgotPasswordConfig -> Maybe EmailSettings
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"emailSettings" Text -> EmailSettings -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (EmailSettings -> Pair) -> Maybe EmailSettings -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EmailSettings
emailSettings,
            (Text
"smsSettings" Text -> SmsSettings -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SmsSettings -> Pair) -> Maybe SmsSettings -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SmsSettings
smsSettings,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"deliveryMethod" Text -> DeliveryMethod -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= DeliveryMethod
deliveryMethod)
          ]
      )