{-# 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.AppSync.Types.UserPoolConfig
-- 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.AppSync.Types.UserPoolConfig where

import Amazonka.AppSync.Types.DefaultAction
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

-- | Describes an Amazon Cognito user pool configuration.
--
-- /See:/ 'newUserPoolConfig' smart constructor.
data UserPoolConfig = UserPoolConfig'
  { -- | A regular expression for validating the incoming Amazon Cognito user
    -- pool app client ID. If this value isn\'t set, no filtering is applied.
    UserPoolConfig -> Maybe Text
appIdClientRegex :: Prelude.Maybe Prelude.Text,
    -- | The user pool ID.
    UserPoolConfig -> Text
userPoolId :: Prelude.Text,
    -- | The Amazon Web Services Region in which the user pool was created.
    UserPoolConfig -> Text
awsRegion :: Prelude.Text,
    -- | The action that you want your GraphQL API to take when a request that
    -- uses Amazon Cognito user pool authentication doesn\'t match the Amazon
    -- Cognito user pool configuration.
    UserPoolConfig -> DefaultAction
defaultAction :: DefaultAction
  }
  deriving (UserPoolConfig -> UserPoolConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UserPoolConfig -> UserPoolConfig -> Bool
$c/= :: UserPoolConfig -> UserPoolConfig -> Bool
== :: UserPoolConfig -> UserPoolConfig -> Bool
$c== :: UserPoolConfig -> UserPoolConfig -> Bool
Prelude.Eq, ReadPrec [UserPoolConfig]
ReadPrec UserPoolConfig
Int -> ReadS UserPoolConfig
ReadS [UserPoolConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UserPoolConfig]
$creadListPrec :: ReadPrec [UserPoolConfig]
readPrec :: ReadPrec UserPoolConfig
$creadPrec :: ReadPrec UserPoolConfig
readList :: ReadS [UserPoolConfig]
$creadList :: ReadS [UserPoolConfig]
readsPrec :: Int -> ReadS UserPoolConfig
$creadsPrec :: Int -> ReadS UserPoolConfig
Prelude.Read, Int -> UserPoolConfig -> ShowS
[UserPoolConfig] -> ShowS
UserPoolConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UserPoolConfig] -> ShowS
$cshowList :: [UserPoolConfig] -> ShowS
show :: UserPoolConfig -> String
$cshow :: UserPoolConfig -> String
showsPrec :: Int -> UserPoolConfig -> ShowS
$cshowsPrec :: Int -> UserPoolConfig -> ShowS
Prelude.Show, forall x. Rep UserPoolConfig x -> UserPoolConfig
forall x. UserPoolConfig -> Rep UserPoolConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UserPoolConfig x -> UserPoolConfig
$cfrom :: forall x. UserPoolConfig -> Rep UserPoolConfig x
Prelude.Generic)

-- |
-- Create a value of 'UserPoolConfig' 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:
--
-- 'appIdClientRegex', 'userPoolConfig_appIdClientRegex' - A regular expression for validating the incoming Amazon Cognito user
-- pool app client ID. If this value isn\'t set, no filtering is applied.
--
-- 'userPoolId', 'userPoolConfig_userPoolId' - The user pool ID.
--
-- 'awsRegion', 'userPoolConfig_awsRegion' - The Amazon Web Services Region in which the user pool was created.
--
-- 'defaultAction', 'userPoolConfig_defaultAction' - The action that you want your GraphQL API to take when a request that
-- uses Amazon Cognito user pool authentication doesn\'t match the Amazon
-- Cognito user pool configuration.
newUserPoolConfig ::
  -- | 'userPoolId'
  Prelude.Text ->
  -- | 'awsRegion'
  Prelude.Text ->
  -- | 'defaultAction'
  DefaultAction ->
  UserPoolConfig
newUserPoolConfig :: Text -> Text -> DefaultAction -> UserPoolConfig
newUserPoolConfig
  Text
pUserPoolId_
  Text
pAwsRegion_
  DefaultAction
pDefaultAction_ =
    UserPoolConfig'
      { $sel:appIdClientRegex:UserPoolConfig' :: Maybe Text
appIdClientRegex = forall a. Maybe a
Prelude.Nothing,
        $sel:userPoolId:UserPoolConfig' :: Text
userPoolId = Text
pUserPoolId_,
        $sel:awsRegion:UserPoolConfig' :: Text
awsRegion = Text
pAwsRegion_,
        $sel:defaultAction:UserPoolConfig' :: DefaultAction
defaultAction = DefaultAction
pDefaultAction_
      }

-- | A regular expression for validating the incoming Amazon Cognito user
-- pool app client ID. If this value isn\'t set, no filtering is applied.
userPoolConfig_appIdClientRegex :: Lens.Lens' UserPoolConfig (Prelude.Maybe Prelude.Text)
userPoolConfig_appIdClientRegex :: Lens' UserPoolConfig (Maybe Text)
userPoolConfig_appIdClientRegex = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserPoolConfig' {Maybe Text
appIdClientRegex :: Maybe Text
$sel:appIdClientRegex:UserPoolConfig' :: UserPoolConfig -> Maybe Text
appIdClientRegex} -> Maybe Text
appIdClientRegex) (\s :: UserPoolConfig
s@UserPoolConfig' {} Maybe Text
a -> UserPoolConfig
s {$sel:appIdClientRegex:UserPoolConfig' :: Maybe Text
appIdClientRegex = Maybe Text
a} :: UserPoolConfig)

-- | The user pool ID.
userPoolConfig_userPoolId :: Lens.Lens' UserPoolConfig Prelude.Text
userPoolConfig_userPoolId :: Lens' UserPoolConfig Text
userPoolConfig_userPoolId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserPoolConfig' {Text
userPoolId :: Text
$sel:userPoolId:UserPoolConfig' :: UserPoolConfig -> Text
userPoolId} -> Text
userPoolId) (\s :: UserPoolConfig
s@UserPoolConfig' {} Text
a -> UserPoolConfig
s {$sel:userPoolId:UserPoolConfig' :: Text
userPoolId = Text
a} :: UserPoolConfig)

-- | The Amazon Web Services Region in which the user pool was created.
userPoolConfig_awsRegion :: Lens.Lens' UserPoolConfig Prelude.Text
userPoolConfig_awsRegion :: Lens' UserPoolConfig Text
userPoolConfig_awsRegion = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserPoolConfig' {Text
awsRegion :: Text
$sel:awsRegion:UserPoolConfig' :: UserPoolConfig -> Text
awsRegion} -> Text
awsRegion) (\s :: UserPoolConfig
s@UserPoolConfig' {} Text
a -> UserPoolConfig
s {$sel:awsRegion:UserPoolConfig' :: Text
awsRegion = Text
a} :: UserPoolConfig)

-- | The action that you want your GraphQL API to take when a request that
-- uses Amazon Cognito user pool authentication doesn\'t match the Amazon
-- Cognito user pool configuration.
userPoolConfig_defaultAction :: Lens.Lens' UserPoolConfig DefaultAction
userPoolConfig_defaultAction :: Lens' UserPoolConfig DefaultAction
userPoolConfig_defaultAction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserPoolConfig' {DefaultAction
defaultAction :: DefaultAction
$sel:defaultAction:UserPoolConfig' :: UserPoolConfig -> DefaultAction
defaultAction} -> DefaultAction
defaultAction) (\s :: UserPoolConfig
s@UserPoolConfig' {} DefaultAction
a -> UserPoolConfig
s {$sel:defaultAction:UserPoolConfig' :: DefaultAction
defaultAction = DefaultAction
a} :: UserPoolConfig)

instance Data.FromJSON UserPoolConfig where
  parseJSON :: Value -> Parser UserPoolConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"UserPoolConfig"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> DefaultAction -> UserPoolConfig
UserPoolConfig'
            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
"appIdClientRegex")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"userPoolId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"awsRegion")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"defaultAction")
      )

instance Prelude.Hashable UserPoolConfig where
  hashWithSalt :: Int -> UserPoolConfig -> Int
hashWithSalt Int
_salt UserPoolConfig' {Maybe Text
Text
DefaultAction
defaultAction :: DefaultAction
awsRegion :: Text
userPoolId :: Text
appIdClientRegex :: Maybe Text
$sel:defaultAction:UserPoolConfig' :: UserPoolConfig -> DefaultAction
$sel:awsRegion:UserPoolConfig' :: UserPoolConfig -> Text
$sel:userPoolId:UserPoolConfig' :: UserPoolConfig -> Text
$sel:appIdClientRegex:UserPoolConfig' :: UserPoolConfig -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
appIdClientRegex
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
userPoolId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
awsRegion
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` DefaultAction
defaultAction

instance Prelude.NFData UserPoolConfig where
  rnf :: UserPoolConfig -> ()
rnf UserPoolConfig' {Maybe Text
Text
DefaultAction
defaultAction :: DefaultAction
awsRegion :: Text
userPoolId :: Text
appIdClientRegex :: Maybe Text
$sel:defaultAction:UserPoolConfig' :: UserPoolConfig -> DefaultAction
$sel:awsRegion:UserPoolConfig' :: UserPoolConfig -> Text
$sel:userPoolId:UserPoolConfig' :: UserPoolConfig -> Text
$sel:appIdClientRegex:UserPoolConfig' :: UserPoolConfig -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
appIdClientRegex
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
userPoolId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
awsRegion
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf DefaultAction
defaultAction

instance Data.ToJSON UserPoolConfig where
  toJSON :: UserPoolConfig -> Value
toJSON UserPoolConfig' {Maybe Text
Text
DefaultAction
defaultAction :: DefaultAction
awsRegion :: Text
userPoolId :: Text
appIdClientRegex :: Maybe Text
$sel:defaultAction:UserPoolConfig' :: UserPoolConfig -> DefaultAction
$sel:awsRegion:UserPoolConfig' :: UserPoolConfig -> Text
$sel:userPoolId:UserPoolConfig' :: UserPoolConfig -> Text
$sel:appIdClientRegex:UserPoolConfig' :: UserPoolConfig -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"appIdClientRegex" 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 Text
appIdClientRegex,
            forall a. a -> Maybe a
Prelude.Just (Key
"userPoolId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
userPoolId),
            forall a. a -> Maybe a
Prelude.Just (Key
"awsRegion" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
awsRegion),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"defaultAction" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= DefaultAction
defaultAction)
          ]
      )