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

import Amazonka.AmplifyBackend.Types.BackendAPIAppSyncAuthSettings
import Amazonka.AmplifyBackend.Types.Mode
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes the auth types for your configured data models.
--
-- /See:/ 'newBackendAPIAuthType' smart constructor.
data BackendAPIAuthType = BackendAPIAuthType'
  { -- | Describes settings for the authentication mode.
    BackendAPIAuthType -> Maybe BackendAPIAppSyncAuthSettings
settings :: Prelude.Maybe BackendAPIAppSyncAuthSettings,
    -- | Describes the authentication mode.
    BackendAPIAuthType -> Maybe Mode
mode :: Prelude.Maybe Mode
  }
  deriving (BackendAPIAuthType -> BackendAPIAuthType -> Bool
(BackendAPIAuthType -> BackendAPIAuthType -> Bool)
-> (BackendAPIAuthType -> BackendAPIAuthType -> Bool)
-> Eq BackendAPIAuthType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BackendAPIAuthType -> BackendAPIAuthType -> Bool
$c/= :: BackendAPIAuthType -> BackendAPIAuthType -> Bool
== :: BackendAPIAuthType -> BackendAPIAuthType -> Bool
$c== :: BackendAPIAuthType -> BackendAPIAuthType -> Bool
Prelude.Eq, ReadPrec [BackendAPIAuthType]
ReadPrec BackendAPIAuthType
Int -> ReadS BackendAPIAuthType
ReadS [BackendAPIAuthType]
(Int -> ReadS BackendAPIAuthType)
-> ReadS [BackendAPIAuthType]
-> ReadPrec BackendAPIAuthType
-> ReadPrec [BackendAPIAuthType]
-> Read BackendAPIAuthType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BackendAPIAuthType]
$creadListPrec :: ReadPrec [BackendAPIAuthType]
readPrec :: ReadPrec BackendAPIAuthType
$creadPrec :: ReadPrec BackendAPIAuthType
readList :: ReadS [BackendAPIAuthType]
$creadList :: ReadS [BackendAPIAuthType]
readsPrec :: Int -> ReadS BackendAPIAuthType
$creadsPrec :: Int -> ReadS BackendAPIAuthType
Prelude.Read, Int -> BackendAPIAuthType -> ShowS
[BackendAPIAuthType] -> ShowS
BackendAPIAuthType -> String
(Int -> BackendAPIAuthType -> ShowS)
-> (BackendAPIAuthType -> String)
-> ([BackendAPIAuthType] -> ShowS)
-> Show BackendAPIAuthType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BackendAPIAuthType] -> ShowS
$cshowList :: [BackendAPIAuthType] -> ShowS
show :: BackendAPIAuthType -> String
$cshow :: BackendAPIAuthType -> String
showsPrec :: Int -> BackendAPIAuthType -> ShowS
$cshowsPrec :: Int -> BackendAPIAuthType -> ShowS
Prelude.Show, (forall x. BackendAPIAuthType -> Rep BackendAPIAuthType x)
-> (forall x. Rep BackendAPIAuthType x -> BackendAPIAuthType)
-> Generic BackendAPIAuthType
forall x. Rep BackendAPIAuthType x -> BackendAPIAuthType
forall x. BackendAPIAuthType -> Rep BackendAPIAuthType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BackendAPIAuthType x -> BackendAPIAuthType
$cfrom :: forall x. BackendAPIAuthType -> Rep BackendAPIAuthType x
Prelude.Generic)

-- |
-- Create a value of 'BackendAPIAuthType' 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:
--
-- 'settings', 'backendAPIAuthType_settings' - Describes settings for the authentication mode.
--
-- 'mode', 'backendAPIAuthType_mode' - Describes the authentication mode.
newBackendAPIAuthType ::
  BackendAPIAuthType
newBackendAPIAuthType :: BackendAPIAuthType
newBackendAPIAuthType =
  BackendAPIAuthType' :: Maybe BackendAPIAppSyncAuthSettings
-> Maybe Mode -> BackendAPIAuthType
BackendAPIAuthType'
    { $sel:settings:BackendAPIAuthType' :: Maybe BackendAPIAppSyncAuthSettings
settings = Maybe BackendAPIAppSyncAuthSettings
forall a. Maybe a
Prelude.Nothing,
      $sel:mode:BackendAPIAuthType' :: Maybe Mode
mode = Maybe Mode
forall a. Maybe a
Prelude.Nothing
    }

-- | Describes settings for the authentication mode.
backendAPIAuthType_settings :: Lens.Lens' BackendAPIAuthType (Prelude.Maybe BackendAPIAppSyncAuthSettings)
backendAPIAuthType_settings :: (Maybe BackendAPIAppSyncAuthSettings
 -> f (Maybe BackendAPIAppSyncAuthSettings))
-> BackendAPIAuthType -> f BackendAPIAuthType
backendAPIAuthType_settings = (BackendAPIAuthType -> Maybe BackendAPIAppSyncAuthSettings)
-> (BackendAPIAuthType
    -> Maybe BackendAPIAppSyncAuthSettings -> BackendAPIAuthType)
-> Lens
     BackendAPIAuthType
     BackendAPIAuthType
     (Maybe BackendAPIAppSyncAuthSettings)
     (Maybe BackendAPIAppSyncAuthSettings)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BackendAPIAuthType' {Maybe BackendAPIAppSyncAuthSettings
settings :: Maybe BackendAPIAppSyncAuthSettings
$sel:settings:BackendAPIAuthType' :: BackendAPIAuthType -> Maybe BackendAPIAppSyncAuthSettings
settings} -> Maybe BackendAPIAppSyncAuthSettings
settings) (\s :: BackendAPIAuthType
s@BackendAPIAuthType' {} Maybe BackendAPIAppSyncAuthSettings
a -> BackendAPIAuthType
s {$sel:settings:BackendAPIAuthType' :: Maybe BackendAPIAppSyncAuthSettings
settings = Maybe BackendAPIAppSyncAuthSettings
a} :: BackendAPIAuthType)

-- | Describes the authentication mode.
backendAPIAuthType_mode :: Lens.Lens' BackendAPIAuthType (Prelude.Maybe Mode)
backendAPIAuthType_mode :: (Maybe Mode -> f (Maybe Mode))
-> BackendAPIAuthType -> f BackendAPIAuthType
backendAPIAuthType_mode = (BackendAPIAuthType -> Maybe Mode)
-> (BackendAPIAuthType -> Maybe Mode -> BackendAPIAuthType)
-> Lens
     BackendAPIAuthType BackendAPIAuthType (Maybe Mode) (Maybe Mode)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BackendAPIAuthType' {Maybe Mode
mode :: Maybe Mode
$sel:mode:BackendAPIAuthType' :: BackendAPIAuthType -> Maybe Mode
mode} -> Maybe Mode
mode) (\s :: BackendAPIAuthType
s@BackendAPIAuthType' {} Maybe Mode
a -> BackendAPIAuthType
s {$sel:mode:BackendAPIAuthType' :: Maybe Mode
mode = Maybe Mode
a} :: BackendAPIAuthType)

instance Core.FromJSON BackendAPIAuthType where
  parseJSON :: Value -> Parser BackendAPIAuthType
parseJSON =
    String
-> (Object -> Parser BackendAPIAuthType)
-> Value
-> Parser BackendAPIAuthType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"BackendAPIAuthType"
      ( \Object
x ->
          Maybe BackendAPIAppSyncAuthSettings
-> Maybe Mode -> BackendAPIAuthType
BackendAPIAuthType'
            (Maybe BackendAPIAppSyncAuthSettings
 -> Maybe Mode -> BackendAPIAuthType)
-> Parser (Maybe BackendAPIAppSyncAuthSettings)
-> Parser (Maybe Mode -> BackendAPIAuthType)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe BackendAPIAppSyncAuthSettings)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"settings")
            Parser (Maybe Mode -> BackendAPIAuthType)
-> Parser (Maybe Mode) -> Parser BackendAPIAuthType
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Mode)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"mode")
      )

instance Prelude.Hashable BackendAPIAuthType

instance Prelude.NFData BackendAPIAuthType

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