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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes an Amazon Cognito user pool configuration.
--
-- /See:/ 'newCognitoUserPoolConfig' smart constructor.
data CognitoUserPoolConfig = CognitoUserPoolConfig'
  { -- | A regular expression for validating the incoming Amazon Cognito user
    -- pool app client ID.
    CognitoUserPoolConfig -> Maybe Text
appIdClientRegex :: Prelude.Maybe Prelude.Text,
    -- | The user pool ID.
    CognitoUserPoolConfig -> Text
userPoolId :: Prelude.Text,
    -- | The Amazon Web Services Region in which the user pool was created.
    CognitoUserPoolConfig -> Text
awsRegion :: Prelude.Text
  }
  deriving (CognitoUserPoolConfig -> CognitoUserPoolConfig -> Bool
(CognitoUserPoolConfig -> CognitoUserPoolConfig -> Bool)
-> (CognitoUserPoolConfig -> CognitoUserPoolConfig -> Bool)
-> Eq CognitoUserPoolConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CognitoUserPoolConfig -> CognitoUserPoolConfig -> Bool
$c/= :: CognitoUserPoolConfig -> CognitoUserPoolConfig -> Bool
== :: CognitoUserPoolConfig -> CognitoUserPoolConfig -> Bool
$c== :: CognitoUserPoolConfig -> CognitoUserPoolConfig -> Bool
Prelude.Eq, ReadPrec [CognitoUserPoolConfig]
ReadPrec CognitoUserPoolConfig
Int -> ReadS CognitoUserPoolConfig
ReadS [CognitoUserPoolConfig]
(Int -> ReadS CognitoUserPoolConfig)
-> ReadS [CognitoUserPoolConfig]
-> ReadPrec CognitoUserPoolConfig
-> ReadPrec [CognitoUserPoolConfig]
-> Read CognitoUserPoolConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CognitoUserPoolConfig]
$creadListPrec :: ReadPrec [CognitoUserPoolConfig]
readPrec :: ReadPrec CognitoUserPoolConfig
$creadPrec :: ReadPrec CognitoUserPoolConfig
readList :: ReadS [CognitoUserPoolConfig]
$creadList :: ReadS [CognitoUserPoolConfig]
readsPrec :: Int -> ReadS CognitoUserPoolConfig
$creadsPrec :: Int -> ReadS CognitoUserPoolConfig
Prelude.Read, Int -> CognitoUserPoolConfig -> ShowS
[CognitoUserPoolConfig] -> ShowS
CognitoUserPoolConfig -> String
(Int -> CognitoUserPoolConfig -> ShowS)
-> (CognitoUserPoolConfig -> String)
-> ([CognitoUserPoolConfig] -> ShowS)
-> Show CognitoUserPoolConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CognitoUserPoolConfig] -> ShowS
$cshowList :: [CognitoUserPoolConfig] -> ShowS
show :: CognitoUserPoolConfig -> String
$cshow :: CognitoUserPoolConfig -> String
showsPrec :: Int -> CognitoUserPoolConfig -> ShowS
$cshowsPrec :: Int -> CognitoUserPoolConfig -> ShowS
Prelude.Show, (forall x. CognitoUserPoolConfig -> Rep CognitoUserPoolConfig x)
-> (forall x. Rep CognitoUserPoolConfig x -> CognitoUserPoolConfig)
-> Generic CognitoUserPoolConfig
forall x. Rep CognitoUserPoolConfig x -> CognitoUserPoolConfig
forall x. CognitoUserPoolConfig -> Rep CognitoUserPoolConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CognitoUserPoolConfig x -> CognitoUserPoolConfig
$cfrom :: forall x. CognitoUserPoolConfig -> Rep CognitoUserPoolConfig x
Prelude.Generic)

-- |
-- Create a value of 'CognitoUserPoolConfig' 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', 'cognitoUserPoolConfig_appIdClientRegex' - A regular expression for validating the incoming Amazon Cognito user
-- pool app client ID.
--
-- 'userPoolId', 'cognitoUserPoolConfig_userPoolId' - The user pool ID.
--
-- 'awsRegion', 'cognitoUserPoolConfig_awsRegion' - The Amazon Web Services Region in which the user pool was created.
newCognitoUserPoolConfig ::
  -- | 'userPoolId'
  Prelude.Text ->
  -- | 'awsRegion'
  Prelude.Text ->
  CognitoUserPoolConfig
newCognitoUserPoolConfig :: Text -> Text -> CognitoUserPoolConfig
newCognitoUserPoolConfig Text
pUserPoolId_ Text
pAwsRegion_ =
  CognitoUserPoolConfig' :: Maybe Text -> Text -> Text -> CognitoUserPoolConfig
CognitoUserPoolConfig'
    { $sel:appIdClientRegex:CognitoUserPoolConfig' :: Maybe Text
appIdClientRegex =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:userPoolId:CognitoUserPoolConfig' :: Text
userPoolId = Text
pUserPoolId_,
      $sel:awsRegion:CognitoUserPoolConfig' :: Text
awsRegion = Text
pAwsRegion_
    }

-- | A regular expression for validating the incoming Amazon Cognito user
-- pool app client ID.
cognitoUserPoolConfig_appIdClientRegex :: Lens.Lens' CognitoUserPoolConfig (Prelude.Maybe Prelude.Text)
cognitoUserPoolConfig_appIdClientRegex :: (Maybe Text -> f (Maybe Text))
-> CognitoUserPoolConfig -> f CognitoUserPoolConfig
cognitoUserPoolConfig_appIdClientRegex = (CognitoUserPoolConfig -> Maybe Text)
-> (CognitoUserPoolConfig -> Maybe Text -> CognitoUserPoolConfig)
-> Lens
     CognitoUserPoolConfig
     CognitoUserPoolConfig
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CognitoUserPoolConfig' {Maybe Text
appIdClientRegex :: Maybe Text
$sel:appIdClientRegex:CognitoUserPoolConfig' :: CognitoUserPoolConfig -> Maybe Text
appIdClientRegex} -> Maybe Text
appIdClientRegex) (\s :: CognitoUserPoolConfig
s@CognitoUserPoolConfig' {} Maybe Text
a -> CognitoUserPoolConfig
s {$sel:appIdClientRegex:CognitoUserPoolConfig' :: Maybe Text
appIdClientRegex = Maybe Text
a} :: CognitoUserPoolConfig)

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

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

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

instance Prelude.Hashable CognitoUserPoolConfig

instance Prelude.NFData CognitoUserPoolConfig

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