{-# 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.UserPoolPolicyType
-- 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.CognitoIdentityProvider.Types.UserPoolPolicyType where

import Amazonka.CognitoIdentityProvider.Types.PasswordPolicyType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The policy associated with a user pool.
--
-- /See:/ 'newUserPoolPolicyType' smart constructor.
data UserPoolPolicyType = UserPoolPolicyType'
  { -- | The password policy.
    UserPoolPolicyType -> Maybe PasswordPolicyType
passwordPolicy :: Prelude.Maybe PasswordPolicyType
  }
  deriving (UserPoolPolicyType -> UserPoolPolicyType -> Bool
(UserPoolPolicyType -> UserPoolPolicyType -> Bool)
-> (UserPoolPolicyType -> UserPoolPolicyType -> Bool)
-> Eq UserPoolPolicyType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UserPoolPolicyType -> UserPoolPolicyType -> Bool
$c/= :: UserPoolPolicyType -> UserPoolPolicyType -> Bool
== :: UserPoolPolicyType -> UserPoolPolicyType -> Bool
$c== :: UserPoolPolicyType -> UserPoolPolicyType -> Bool
Prelude.Eq, ReadPrec [UserPoolPolicyType]
ReadPrec UserPoolPolicyType
Int -> ReadS UserPoolPolicyType
ReadS [UserPoolPolicyType]
(Int -> ReadS UserPoolPolicyType)
-> ReadS [UserPoolPolicyType]
-> ReadPrec UserPoolPolicyType
-> ReadPrec [UserPoolPolicyType]
-> Read UserPoolPolicyType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UserPoolPolicyType]
$creadListPrec :: ReadPrec [UserPoolPolicyType]
readPrec :: ReadPrec UserPoolPolicyType
$creadPrec :: ReadPrec UserPoolPolicyType
readList :: ReadS [UserPoolPolicyType]
$creadList :: ReadS [UserPoolPolicyType]
readsPrec :: Int -> ReadS UserPoolPolicyType
$creadsPrec :: Int -> ReadS UserPoolPolicyType
Prelude.Read, Int -> UserPoolPolicyType -> ShowS
[UserPoolPolicyType] -> ShowS
UserPoolPolicyType -> String
(Int -> UserPoolPolicyType -> ShowS)
-> (UserPoolPolicyType -> String)
-> ([UserPoolPolicyType] -> ShowS)
-> Show UserPoolPolicyType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UserPoolPolicyType] -> ShowS
$cshowList :: [UserPoolPolicyType] -> ShowS
show :: UserPoolPolicyType -> String
$cshow :: UserPoolPolicyType -> String
showsPrec :: Int -> UserPoolPolicyType -> ShowS
$cshowsPrec :: Int -> UserPoolPolicyType -> ShowS
Prelude.Show, (forall x. UserPoolPolicyType -> Rep UserPoolPolicyType x)
-> (forall x. Rep UserPoolPolicyType x -> UserPoolPolicyType)
-> Generic UserPoolPolicyType
forall x. Rep UserPoolPolicyType x -> UserPoolPolicyType
forall x. UserPoolPolicyType -> Rep UserPoolPolicyType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UserPoolPolicyType x -> UserPoolPolicyType
$cfrom :: forall x. UserPoolPolicyType -> Rep UserPoolPolicyType x
Prelude.Generic)

-- |
-- Create a value of 'UserPoolPolicyType' 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:
--
-- 'passwordPolicy', 'userPoolPolicyType_passwordPolicy' - The password policy.
newUserPoolPolicyType ::
  UserPoolPolicyType
newUserPoolPolicyType :: UserPoolPolicyType
newUserPoolPolicyType =
  UserPoolPolicyType' :: Maybe PasswordPolicyType -> UserPoolPolicyType
UserPoolPolicyType'
    { $sel:passwordPolicy:UserPoolPolicyType' :: Maybe PasswordPolicyType
passwordPolicy =
        Maybe PasswordPolicyType
forall a. Maybe a
Prelude.Nothing
    }

-- | The password policy.
userPoolPolicyType_passwordPolicy :: Lens.Lens' UserPoolPolicyType (Prelude.Maybe PasswordPolicyType)
userPoolPolicyType_passwordPolicy :: (Maybe PasswordPolicyType -> f (Maybe PasswordPolicyType))
-> UserPoolPolicyType -> f UserPoolPolicyType
userPoolPolicyType_passwordPolicy = (UserPoolPolicyType -> Maybe PasswordPolicyType)
-> (UserPoolPolicyType
    -> Maybe PasswordPolicyType -> UserPoolPolicyType)
-> Lens
     UserPoolPolicyType
     UserPoolPolicyType
     (Maybe PasswordPolicyType)
     (Maybe PasswordPolicyType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserPoolPolicyType' {Maybe PasswordPolicyType
passwordPolicy :: Maybe PasswordPolicyType
$sel:passwordPolicy:UserPoolPolicyType' :: UserPoolPolicyType -> Maybe PasswordPolicyType
passwordPolicy} -> Maybe PasswordPolicyType
passwordPolicy) (\s :: UserPoolPolicyType
s@UserPoolPolicyType' {} Maybe PasswordPolicyType
a -> UserPoolPolicyType
s {$sel:passwordPolicy:UserPoolPolicyType' :: Maybe PasswordPolicyType
passwordPolicy = Maybe PasswordPolicyType
a} :: UserPoolPolicyType)

instance Core.FromJSON UserPoolPolicyType where
  parseJSON :: Value -> Parser UserPoolPolicyType
parseJSON =
    String
-> (Object -> Parser UserPoolPolicyType)
-> Value
-> Parser UserPoolPolicyType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"UserPoolPolicyType"
      ( \Object
x ->
          Maybe PasswordPolicyType -> UserPoolPolicyType
UserPoolPolicyType'
            (Maybe PasswordPolicyType -> UserPoolPolicyType)
-> Parser (Maybe PasswordPolicyType) -> Parser UserPoolPolicyType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe PasswordPolicyType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PasswordPolicy")
      )

instance Prelude.Hashable UserPoolPolicyType

instance Prelude.NFData UserPoolPolicyType

instance Core.ToJSON UserPoolPolicyType where
  toJSON :: UserPoolPolicyType -> Value
toJSON UserPoolPolicyType' {Maybe PasswordPolicyType
passwordPolicy :: Maybe PasswordPolicyType
$sel:passwordPolicy:UserPoolPolicyType' :: UserPoolPolicyType -> Maybe PasswordPolicyType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"PasswordPolicy" Text -> PasswordPolicyType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (PasswordPolicyType -> Pair)
-> Maybe PasswordPolicyType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe PasswordPolicyType
passwordPolicy
          ]
      )