{-# 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.CreateBackendAuthResourceConfig
-- 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.CreateBackendAuthResourceConfig where

import Amazonka.AmplifyBackend.Types.AuthResources
import Amazonka.AmplifyBackend.Types.CreateBackendAuthIdentityPoolConfig
import Amazonka.AmplifyBackend.Types.CreateBackendAuthUserPoolConfig
import Amazonka.AmplifyBackend.Types.Service
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Defines the resource configuration when creating an auth resource in
-- your Amplify project.
--
-- /See:/ 'newCreateBackendAuthResourceConfig' smart constructor.
data CreateBackendAuthResourceConfig = CreateBackendAuthResourceConfig'
  { -- | Describes the authorization configuration for the Amazon Cognito
    -- identity pool, provisioned as a part of your auth resource in the
    -- Amplify project.
    CreateBackendAuthResourceConfig
-> Maybe CreateBackendAuthIdentityPoolConfig
identityPoolConfigs :: Prelude.Maybe CreateBackendAuthIdentityPoolConfig,
    -- | Defines whether you want to configure only authentication or both
    -- authentication and authorization settings.
    CreateBackendAuthResourceConfig -> AuthResources
authResources :: AuthResources,
    -- | Describes authentication configuration for the Amazon Cognito user pool,
    -- provisioned as a part of your auth resource in the Amplify project.
    CreateBackendAuthResourceConfig -> CreateBackendAuthUserPoolConfig
userPoolConfigs :: CreateBackendAuthUserPoolConfig,
    -- | Defines the service name to use when configuring an authentication
    -- resource in your Amplify project.
    CreateBackendAuthResourceConfig -> Service
service :: Service
  }
  deriving (CreateBackendAuthResourceConfig
-> CreateBackendAuthResourceConfig -> Bool
(CreateBackendAuthResourceConfig
 -> CreateBackendAuthResourceConfig -> Bool)
-> (CreateBackendAuthResourceConfig
    -> CreateBackendAuthResourceConfig -> Bool)
-> Eq CreateBackendAuthResourceConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateBackendAuthResourceConfig
-> CreateBackendAuthResourceConfig -> Bool
$c/= :: CreateBackendAuthResourceConfig
-> CreateBackendAuthResourceConfig -> Bool
== :: CreateBackendAuthResourceConfig
-> CreateBackendAuthResourceConfig -> Bool
$c== :: CreateBackendAuthResourceConfig
-> CreateBackendAuthResourceConfig -> Bool
Prelude.Eq, ReadPrec [CreateBackendAuthResourceConfig]
ReadPrec CreateBackendAuthResourceConfig
Int -> ReadS CreateBackendAuthResourceConfig
ReadS [CreateBackendAuthResourceConfig]
(Int -> ReadS CreateBackendAuthResourceConfig)
-> ReadS [CreateBackendAuthResourceConfig]
-> ReadPrec CreateBackendAuthResourceConfig
-> ReadPrec [CreateBackendAuthResourceConfig]
-> Read CreateBackendAuthResourceConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateBackendAuthResourceConfig]
$creadListPrec :: ReadPrec [CreateBackendAuthResourceConfig]
readPrec :: ReadPrec CreateBackendAuthResourceConfig
$creadPrec :: ReadPrec CreateBackendAuthResourceConfig
readList :: ReadS [CreateBackendAuthResourceConfig]
$creadList :: ReadS [CreateBackendAuthResourceConfig]
readsPrec :: Int -> ReadS CreateBackendAuthResourceConfig
$creadsPrec :: Int -> ReadS CreateBackendAuthResourceConfig
Prelude.Read, Int -> CreateBackendAuthResourceConfig -> ShowS
[CreateBackendAuthResourceConfig] -> ShowS
CreateBackendAuthResourceConfig -> String
(Int -> CreateBackendAuthResourceConfig -> ShowS)
-> (CreateBackendAuthResourceConfig -> String)
-> ([CreateBackendAuthResourceConfig] -> ShowS)
-> Show CreateBackendAuthResourceConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateBackendAuthResourceConfig] -> ShowS
$cshowList :: [CreateBackendAuthResourceConfig] -> ShowS
show :: CreateBackendAuthResourceConfig -> String
$cshow :: CreateBackendAuthResourceConfig -> String
showsPrec :: Int -> CreateBackendAuthResourceConfig -> ShowS
$cshowsPrec :: Int -> CreateBackendAuthResourceConfig -> ShowS
Prelude.Show, (forall x.
 CreateBackendAuthResourceConfig
 -> Rep CreateBackendAuthResourceConfig x)
-> (forall x.
    Rep CreateBackendAuthResourceConfig x
    -> CreateBackendAuthResourceConfig)
-> Generic CreateBackendAuthResourceConfig
forall x.
Rep CreateBackendAuthResourceConfig x
-> CreateBackendAuthResourceConfig
forall x.
CreateBackendAuthResourceConfig
-> Rep CreateBackendAuthResourceConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateBackendAuthResourceConfig x
-> CreateBackendAuthResourceConfig
$cfrom :: forall x.
CreateBackendAuthResourceConfig
-> Rep CreateBackendAuthResourceConfig x
Prelude.Generic)

-- |
-- Create a value of 'CreateBackendAuthResourceConfig' 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:
--
-- 'identityPoolConfigs', 'createBackendAuthResourceConfig_identityPoolConfigs' - Describes the authorization configuration for the Amazon Cognito
-- identity pool, provisioned as a part of your auth resource in the
-- Amplify project.
--
-- 'authResources', 'createBackendAuthResourceConfig_authResources' - Defines whether you want to configure only authentication or both
-- authentication and authorization settings.
--
-- 'userPoolConfigs', 'createBackendAuthResourceConfig_userPoolConfigs' - Describes authentication configuration for the Amazon Cognito user pool,
-- provisioned as a part of your auth resource in the Amplify project.
--
-- 'service', 'createBackendAuthResourceConfig_service' - Defines the service name to use when configuring an authentication
-- resource in your Amplify project.
newCreateBackendAuthResourceConfig ::
  -- | 'authResources'
  AuthResources ->
  -- | 'userPoolConfigs'
  CreateBackendAuthUserPoolConfig ->
  -- | 'service'
  Service ->
  CreateBackendAuthResourceConfig
newCreateBackendAuthResourceConfig :: AuthResources
-> CreateBackendAuthUserPoolConfig
-> Service
-> CreateBackendAuthResourceConfig
newCreateBackendAuthResourceConfig
  AuthResources
pAuthResources_
  CreateBackendAuthUserPoolConfig
pUserPoolConfigs_
  Service
pService_ =
    CreateBackendAuthResourceConfig' :: Maybe CreateBackendAuthIdentityPoolConfig
-> AuthResources
-> CreateBackendAuthUserPoolConfig
-> Service
-> CreateBackendAuthResourceConfig
CreateBackendAuthResourceConfig'
      { $sel:identityPoolConfigs:CreateBackendAuthResourceConfig' :: Maybe CreateBackendAuthIdentityPoolConfig
identityPoolConfigs =
          Maybe CreateBackendAuthIdentityPoolConfig
forall a. Maybe a
Prelude.Nothing,
        $sel:authResources:CreateBackendAuthResourceConfig' :: AuthResources
authResources = AuthResources
pAuthResources_,
        $sel:userPoolConfigs:CreateBackendAuthResourceConfig' :: CreateBackendAuthUserPoolConfig
userPoolConfigs = CreateBackendAuthUserPoolConfig
pUserPoolConfigs_,
        $sel:service:CreateBackendAuthResourceConfig' :: Service
service = Service
pService_
      }

-- | Describes the authorization configuration for the Amazon Cognito
-- identity pool, provisioned as a part of your auth resource in the
-- Amplify project.
createBackendAuthResourceConfig_identityPoolConfigs :: Lens.Lens' CreateBackendAuthResourceConfig (Prelude.Maybe CreateBackendAuthIdentityPoolConfig)
createBackendAuthResourceConfig_identityPoolConfigs :: (Maybe CreateBackendAuthIdentityPoolConfig
 -> f (Maybe CreateBackendAuthIdentityPoolConfig))
-> CreateBackendAuthResourceConfig
-> f CreateBackendAuthResourceConfig
createBackendAuthResourceConfig_identityPoolConfigs = (CreateBackendAuthResourceConfig
 -> Maybe CreateBackendAuthIdentityPoolConfig)
-> (CreateBackendAuthResourceConfig
    -> Maybe CreateBackendAuthIdentityPoolConfig
    -> CreateBackendAuthResourceConfig)
-> Lens
     CreateBackendAuthResourceConfig
     CreateBackendAuthResourceConfig
     (Maybe CreateBackendAuthIdentityPoolConfig)
     (Maybe CreateBackendAuthIdentityPoolConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBackendAuthResourceConfig' {Maybe CreateBackendAuthIdentityPoolConfig
identityPoolConfigs :: Maybe CreateBackendAuthIdentityPoolConfig
$sel:identityPoolConfigs:CreateBackendAuthResourceConfig' :: CreateBackendAuthResourceConfig
-> Maybe CreateBackendAuthIdentityPoolConfig
identityPoolConfigs} -> Maybe CreateBackendAuthIdentityPoolConfig
identityPoolConfigs) (\s :: CreateBackendAuthResourceConfig
s@CreateBackendAuthResourceConfig' {} Maybe CreateBackendAuthIdentityPoolConfig
a -> CreateBackendAuthResourceConfig
s {$sel:identityPoolConfigs:CreateBackendAuthResourceConfig' :: Maybe CreateBackendAuthIdentityPoolConfig
identityPoolConfigs = Maybe CreateBackendAuthIdentityPoolConfig
a} :: CreateBackendAuthResourceConfig)

-- | Defines whether you want to configure only authentication or both
-- authentication and authorization settings.
createBackendAuthResourceConfig_authResources :: Lens.Lens' CreateBackendAuthResourceConfig AuthResources
createBackendAuthResourceConfig_authResources :: (AuthResources -> f AuthResources)
-> CreateBackendAuthResourceConfig
-> f CreateBackendAuthResourceConfig
createBackendAuthResourceConfig_authResources = (CreateBackendAuthResourceConfig -> AuthResources)
-> (CreateBackendAuthResourceConfig
    -> AuthResources -> CreateBackendAuthResourceConfig)
-> Lens
     CreateBackendAuthResourceConfig
     CreateBackendAuthResourceConfig
     AuthResources
     AuthResources
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBackendAuthResourceConfig' {AuthResources
authResources :: AuthResources
$sel:authResources:CreateBackendAuthResourceConfig' :: CreateBackendAuthResourceConfig -> AuthResources
authResources} -> AuthResources
authResources) (\s :: CreateBackendAuthResourceConfig
s@CreateBackendAuthResourceConfig' {} AuthResources
a -> CreateBackendAuthResourceConfig
s {$sel:authResources:CreateBackendAuthResourceConfig' :: AuthResources
authResources = AuthResources
a} :: CreateBackendAuthResourceConfig)

-- | Describes authentication configuration for the Amazon Cognito user pool,
-- provisioned as a part of your auth resource in the Amplify project.
createBackendAuthResourceConfig_userPoolConfigs :: Lens.Lens' CreateBackendAuthResourceConfig CreateBackendAuthUserPoolConfig
createBackendAuthResourceConfig_userPoolConfigs :: (CreateBackendAuthUserPoolConfig
 -> f CreateBackendAuthUserPoolConfig)
-> CreateBackendAuthResourceConfig
-> f CreateBackendAuthResourceConfig
createBackendAuthResourceConfig_userPoolConfigs = (CreateBackendAuthResourceConfig
 -> CreateBackendAuthUserPoolConfig)
-> (CreateBackendAuthResourceConfig
    -> CreateBackendAuthUserPoolConfig
    -> CreateBackendAuthResourceConfig)
-> Lens
     CreateBackendAuthResourceConfig
     CreateBackendAuthResourceConfig
     CreateBackendAuthUserPoolConfig
     CreateBackendAuthUserPoolConfig
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBackendAuthResourceConfig' {CreateBackendAuthUserPoolConfig
userPoolConfigs :: CreateBackendAuthUserPoolConfig
$sel:userPoolConfigs:CreateBackendAuthResourceConfig' :: CreateBackendAuthResourceConfig -> CreateBackendAuthUserPoolConfig
userPoolConfigs} -> CreateBackendAuthUserPoolConfig
userPoolConfigs) (\s :: CreateBackendAuthResourceConfig
s@CreateBackendAuthResourceConfig' {} CreateBackendAuthUserPoolConfig
a -> CreateBackendAuthResourceConfig
s {$sel:userPoolConfigs:CreateBackendAuthResourceConfig' :: CreateBackendAuthUserPoolConfig
userPoolConfigs = CreateBackendAuthUserPoolConfig
a} :: CreateBackendAuthResourceConfig)

-- | Defines the service name to use when configuring an authentication
-- resource in your Amplify project.
createBackendAuthResourceConfig_service :: Lens.Lens' CreateBackendAuthResourceConfig Service
createBackendAuthResourceConfig_service :: (Service -> f Service)
-> CreateBackendAuthResourceConfig
-> f CreateBackendAuthResourceConfig
createBackendAuthResourceConfig_service = (CreateBackendAuthResourceConfig -> Service)
-> (CreateBackendAuthResourceConfig
    -> Service -> CreateBackendAuthResourceConfig)
-> Lens
     CreateBackendAuthResourceConfig
     CreateBackendAuthResourceConfig
     Service
     Service
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBackendAuthResourceConfig' {Service
service :: Service
$sel:service:CreateBackendAuthResourceConfig' :: CreateBackendAuthResourceConfig -> Service
service} -> Service
service) (\s :: CreateBackendAuthResourceConfig
s@CreateBackendAuthResourceConfig' {} Service
a -> CreateBackendAuthResourceConfig
s {$sel:service:CreateBackendAuthResourceConfig' :: Service
service = Service
a} :: CreateBackendAuthResourceConfig)

instance
  Core.FromJSON
    CreateBackendAuthResourceConfig
  where
  parseJSON :: Value -> Parser CreateBackendAuthResourceConfig
parseJSON =
    String
-> (Object -> Parser CreateBackendAuthResourceConfig)
-> Value
-> Parser CreateBackendAuthResourceConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CreateBackendAuthResourceConfig"
      ( \Object
x ->
          Maybe CreateBackendAuthIdentityPoolConfig
-> AuthResources
-> CreateBackendAuthUserPoolConfig
-> Service
-> CreateBackendAuthResourceConfig
CreateBackendAuthResourceConfig'
            (Maybe CreateBackendAuthIdentityPoolConfig
 -> AuthResources
 -> CreateBackendAuthUserPoolConfig
 -> Service
 -> CreateBackendAuthResourceConfig)
-> Parser (Maybe CreateBackendAuthIdentityPoolConfig)
-> Parser
     (AuthResources
      -> CreateBackendAuthUserPoolConfig
      -> Service
      -> CreateBackendAuthResourceConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object
-> Text -> Parser (Maybe CreateBackendAuthIdentityPoolConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"identityPoolConfigs")
            Parser
  (AuthResources
   -> CreateBackendAuthUserPoolConfig
   -> Service
   -> CreateBackendAuthResourceConfig)
-> Parser AuthResources
-> Parser
     (CreateBackendAuthUserPoolConfig
      -> Service -> CreateBackendAuthResourceConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser AuthResources
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"authResources")
            Parser
  (CreateBackendAuthUserPoolConfig
   -> Service -> CreateBackendAuthResourceConfig)
-> Parser CreateBackendAuthUserPoolConfig
-> Parser (Service -> CreateBackendAuthResourceConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser CreateBackendAuthUserPoolConfig
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"userPoolConfigs")
            Parser (Service -> CreateBackendAuthResourceConfig)
-> Parser Service -> Parser CreateBackendAuthResourceConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Service
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"service")
      )

instance
  Prelude.Hashable
    CreateBackendAuthResourceConfig

instance
  Prelude.NFData
    CreateBackendAuthResourceConfig

instance Core.ToJSON CreateBackendAuthResourceConfig where
  toJSON :: CreateBackendAuthResourceConfig -> Value
toJSON CreateBackendAuthResourceConfig' {Maybe CreateBackendAuthIdentityPoolConfig
AuthResources
Service
CreateBackendAuthUserPoolConfig
service :: Service
userPoolConfigs :: CreateBackendAuthUserPoolConfig
authResources :: AuthResources
identityPoolConfigs :: Maybe CreateBackendAuthIdentityPoolConfig
$sel:service:CreateBackendAuthResourceConfig' :: CreateBackendAuthResourceConfig -> Service
$sel:userPoolConfigs:CreateBackendAuthResourceConfig' :: CreateBackendAuthResourceConfig -> CreateBackendAuthUserPoolConfig
$sel:authResources:CreateBackendAuthResourceConfig' :: CreateBackendAuthResourceConfig -> AuthResources
$sel:identityPoolConfigs:CreateBackendAuthResourceConfig' :: CreateBackendAuthResourceConfig
-> Maybe CreateBackendAuthIdentityPoolConfig
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"identityPoolConfigs" Text -> CreateBackendAuthIdentityPoolConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (CreateBackendAuthIdentityPoolConfig -> Pair)
-> Maybe CreateBackendAuthIdentityPoolConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CreateBackendAuthIdentityPoolConfig
identityPoolConfigs,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"authResources" Text -> AuthResources -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AuthResources
authResources),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"userPoolConfigs" Text -> CreateBackendAuthUserPoolConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= CreateBackendAuthUserPoolConfig
userPoolConfigs),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"service" Text -> Service -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Service
service)
          ]
      )