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

import Amazonka.AppSync.Types.DeltaSyncConfig
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes an Amazon DynamoDB data source configuration.
--
-- /See:/ 'newDynamodbDataSourceConfig' smart constructor.
data DynamodbDataSourceConfig = DynamodbDataSourceConfig'
  { -- | Set to TRUE to use Conflict Detection and Resolution with this data
    -- source.
    DynamodbDataSourceConfig -> Maybe Bool
versioned :: Prelude.Maybe Prelude.Bool,
    -- | Set to TRUE to use Amazon Cognito credentials with this data source.
    DynamodbDataSourceConfig -> Maybe Bool
useCallerCredentials :: Prelude.Maybe Prelude.Bool,
    -- | The @DeltaSyncConfig@ for a versioned datasource.
    DynamodbDataSourceConfig -> Maybe DeltaSyncConfig
deltaSyncConfig :: Prelude.Maybe DeltaSyncConfig,
    -- | The table name.
    DynamodbDataSourceConfig -> Text
tableName :: Prelude.Text,
    -- | The Amazon Web Services Region.
    DynamodbDataSourceConfig -> Text
awsRegion :: Prelude.Text
  }
  deriving (DynamodbDataSourceConfig -> DynamodbDataSourceConfig -> Bool
(DynamodbDataSourceConfig -> DynamodbDataSourceConfig -> Bool)
-> (DynamodbDataSourceConfig -> DynamodbDataSourceConfig -> Bool)
-> Eq DynamodbDataSourceConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DynamodbDataSourceConfig -> DynamodbDataSourceConfig -> Bool
$c/= :: DynamodbDataSourceConfig -> DynamodbDataSourceConfig -> Bool
== :: DynamodbDataSourceConfig -> DynamodbDataSourceConfig -> Bool
$c== :: DynamodbDataSourceConfig -> DynamodbDataSourceConfig -> Bool
Prelude.Eq, ReadPrec [DynamodbDataSourceConfig]
ReadPrec DynamodbDataSourceConfig
Int -> ReadS DynamodbDataSourceConfig
ReadS [DynamodbDataSourceConfig]
(Int -> ReadS DynamodbDataSourceConfig)
-> ReadS [DynamodbDataSourceConfig]
-> ReadPrec DynamodbDataSourceConfig
-> ReadPrec [DynamodbDataSourceConfig]
-> Read DynamodbDataSourceConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DynamodbDataSourceConfig]
$creadListPrec :: ReadPrec [DynamodbDataSourceConfig]
readPrec :: ReadPrec DynamodbDataSourceConfig
$creadPrec :: ReadPrec DynamodbDataSourceConfig
readList :: ReadS [DynamodbDataSourceConfig]
$creadList :: ReadS [DynamodbDataSourceConfig]
readsPrec :: Int -> ReadS DynamodbDataSourceConfig
$creadsPrec :: Int -> ReadS DynamodbDataSourceConfig
Prelude.Read, Int -> DynamodbDataSourceConfig -> ShowS
[DynamodbDataSourceConfig] -> ShowS
DynamodbDataSourceConfig -> String
(Int -> DynamodbDataSourceConfig -> ShowS)
-> (DynamodbDataSourceConfig -> String)
-> ([DynamodbDataSourceConfig] -> ShowS)
-> Show DynamodbDataSourceConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DynamodbDataSourceConfig] -> ShowS
$cshowList :: [DynamodbDataSourceConfig] -> ShowS
show :: DynamodbDataSourceConfig -> String
$cshow :: DynamodbDataSourceConfig -> String
showsPrec :: Int -> DynamodbDataSourceConfig -> ShowS
$cshowsPrec :: Int -> DynamodbDataSourceConfig -> ShowS
Prelude.Show, (forall x.
 DynamodbDataSourceConfig -> Rep DynamodbDataSourceConfig x)
-> (forall x.
    Rep DynamodbDataSourceConfig x -> DynamodbDataSourceConfig)
-> Generic DynamodbDataSourceConfig
forall x.
Rep DynamodbDataSourceConfig x -> DynamodbDataSourceConfig
forall x.
DynamodbDataSourceConfig -> Rep DynamodbDataSourceConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DynamodbDataSourceConfig x -> DynamodbDataSourceConfig
$cfrom :: forall x.
DynamodbDataSourceConfig -> Rep DynamodbDataSourceConfig x
Prelude.Generic)

-- |
-- Create a value of 'DynamodbDataSourceConfig' 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:
--
-- 'versioned', 'dynamodbDataSourceConfig_versioned' - Set to TRUE to use Conflict Detection and Resolution with this data
-- source.
--
-- 'useCallerCredentials', 'dynamodbDataSourceConfig_useCallerCredentials' - Set to TRUE to use Amazon Cognito credentials with this data source.
--
-- 'deltaSyncConfig', 'dynamodbDataSourceConfig_deltaSyncConfig' - The @DeltaSyncConfig@ for a versioned datasource.
--
-- 'tableName', 'dynamodbDataSourceConfig_tableName' - The table name.
--
-- 'awsRegion', 'dynamodbDataSourceConfig_awsRegion' - The Amazon Web Services Region.
newDynamodbDataSourceConfig ::
  -- | 'tableName'
  Prelude.Text ->
  -- | 'awsRegion'
  Prelude.Text ->
  DynamodbDataSourceConfig
newDynamodbDataSourceConfig :: Text -> Text -> DynamodbDataSourceConfig
newDynamodbDataSourceConfig Text
pTableName_ Text
pAwsRegion_ =
  DynamodbDataSourceConfig' :: Maybe Bool
-> Maybe Bool
-> Maybe DeltaSyncConfig
-> Text
-> Text
-> DynamodbDataSourceConfig
DynamodbDataSourceConfig'
    { $sel:versioned:DynamodbDataSourceConfig' :: Maybe Bool
versioned =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:useCallerCredentials:DynamodbDataSourceConfig' :: Maybe Bool
useCallerCredentials = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:deltaSyncConfig:DynamodbDataSourceConfig' :: Maybe DeltaSyncConfig
deltaSyncConfig = Maybe DeltaSyncConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:tableName:DynamodbDataSourceConfig' :: Text
tableName = Text
pTableName_,
      $sel:awsRegion:DynamodbDataSourceConfig' :: Text
awsRegion = Text
pAwsRegion_
    }

-- | Set to TRUE to use Conflict Detection and Resolution with this data
-- source.
dynamodbDataSourceConfig_versioned :: Lens.Lens' DynamodbDataSourceConfig (Prelude.Maybe Prelude.Bool)
dynamodbDataSourceConfig_versioned :: (Maybe Bool -> f (Maybe Bool))
-> DynamodbDataSourceConfig -> f DynamodbDataSourceConfig
dynamodbDataSourceConfig_versioned = (DynamodbDataSourceConfig -> Maybe Bool)
-> (DynamodbDataSourceConfig
    -> Maybe Bool -> DynamodbDataSourceConfig)
-> Lens
     DynamodbDataSourceConfig
     DynamodbDataSourceConfig
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DynamodbDataSourceConfig' {Maybe Bool
versioned :: Maybe Bool
$sel:versioned:DynamodbDataSourceConfig' :: DynamodbDataSourceConfig -> Maybe Bool
versioned} -> Maybe Bool
versioned) (\s :: DynamodbDataSourceConfig
s@DynamodbDataSourceConfig' {} Maybe Bool
a -> DynamodbDataSourceConfig
s {$sel:versioned:DynamodbDataSourceConfig' :: Maybe Bool
versioned = Maybe Bool
a} :: DynamodbDataSourceConfig)

-- | Set to TRUE to use Amazon Cognito credentials with this data source.
dynamodbDataSourceConfig_useCallerCredentials :: Lens.Lens' DynamodbDataSourceConfig (Prelude.Maybe Prelude.Bool)
dynamodbDataSourceConfig_useCallerCredentials :: (Maybe Bool -> f (Maybe Bool))
-> DynamodbDataSourceConfig -> f DynamodbDataSourceConfig
dynamodbDataSourceConfig_useCallerCredentials = (DynamodbDataSourceConfig -> Maybe Bool)
-> (DynamodbDataSourceConfig
    -> Maybe Bool -> DynamodbDataSourceConfig)
-> Lens
     DynamodbDataSourceConfig
     DynamodbDataSourceConfig
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DynamodbDataSourceConfig' {Maybe Bool
useCallerCredentials :: Maybe Bool
$sel:useCallerCredentials:DynamodbDataSourceConfig' :: DynamodbDataSourceConfig -> Maybe Bool
useCallerCredentials} -> Maybe Bool
useCallerCredentials) (\s :: DynamodbDataSourceConfig
s@DynamodbDataSourceConfig' {} Maybe Bool
a -> DynamodbDataSourceConfig
s {$sel:useCallerCredentials:DynamodbDataSourceConfig' :: Maybe Bool
useCallerCredentials = Maybe Bool
a} :: DynamodbDataSourceConfig)

-- | The @DeltaSyncConfig@ for a versioned datasource.
dynamodbDataSourceConfig_deltaSyncConfig :: Lens.Lens' DynamodbDataSourceConfig (Prelude.Maybe DeltaSyncConfig)
dynamodbDataSourceConfig_deltaSyncConfig :: (Maybe DeltaSyncConfig -> f (Maybe DeltaSyncConfig))
-> DynamodbDataSourceConfig -> f DynamodbDataSourceConfig
dynamodbDataSourceConfig_deltaSyncConfig = (DynamodbDataSourceConfig -> Maybe DeltaSyncConfig)
-> (DynamodbDataSourceConfig
    -> Maybe DeltaSyncConfig -> DynamodbDataSourceConfig)
-> Lens
     DynamodbDataSourceConfig
     DynamodbDataSourceConfig
     (Maybe DeltaSyncConfig)
     (Maybe DeltaSyncConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DynamodbDataSourceConfig' {Maybe DeltaSyncConfig
deltaSyncConfig :: Maybe DeltaSyncConfig
$sel:deltaSyncConfig:DynamodbDataSourceConfig' :: DynamodbDataSourceConfig -> Maybe DeltaSyncConfig
deltaSyncConfig} -> Maybe DeltaSyncConfig
deltaSyncConfig) (\s :: DynamodbDataSourceConfig
s@DynamodbDataSourceConfig' {} Maybe DeltaSyncConfig
a -> DynamodbDataSourceConfig
s {$sel:deltaSyncConfig:DynamodbDataSourceConfig' :: Maybe DeltaSyncConfig
deltaSyncConfig = Maybe DeltaSyncConfig
a} :: DynamodbDataSourceConfig)

-- | The table name.
dynamodbDataSourceConfig_tableName :: Lens.Lens' DynamodbDataSourceConfig Prelude.Text
dynamodbDataSourceConfig_tableName :: (Text -> f Text)
-> DynamodbDataSourceConfig -> f DynamodbDataSourceConfig
dynamodbDataSourceConfig_tableName = (DynamodbDataSourceConfig -> Text)
-> (DynamodbDataSourceConfig -> Text -> DynamodbDataSourceConfig)
-> Lens DynamodbDataSourceConfig DynamodbDataSourceConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DynamodbDataSourceConfig' {Text
tableName :: Text
$sel:tableName:DynamodbDataSourceConfig' :: DynamodbDataSourceConfig -> Text
tableName} -> Text
tableName) (\s :: DynamodbDataSourceConfig
s@DynamodbDataSourceConfig' {} Text
a -> DynamodbDataSourceConfig
s {$sel:tableName:DynamodbDataSourceConfig' :: Text
tableName = Text
a} :: DynamodbDataSourceConfig)

-- | The Amazon Web Services Region.
dynamodbDataSourceConfig_awsRegion :: Lens.Lens' DynamodbDataSourceConfig Prelude.Text
dynamodbDataSourceConfig_awsRegion :: (Text -> f Text)
-> DynamodbDataSourceConfig -> f DynamodbDataSourceConfig
dynamodbDataSourceConfig_awsRegion = (DynamodbDataSourceConfig -> Text)
-> (DynamodbDataSourceConfig -> Text -> DynamodbDataSourceConfig)
-> Lens DynamodbDataSourceConfig DynamodbDataSourceConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DynamodbDataSourceConfig' {Text
awsRegion :: Text
$sel:awsRegion:DynamodbDataSourceConfig' :: DynamodbDataSourceConfig -> Text
awsRegion} -> Text
awsRegion) (\s :: DynamodbDataSourceConfig
s@DynamodbDataSourceConfig' {} Text
a -> DynamodbDataSourceConfig
s {$sel:awsRegion:DynamodbDataSourceConfig' :: Text
awsRegion = Text
a} :: DynamodbDataSourceConfig)

instance Core.FromJSON DynamodbDataSourceConfig where
  parseJSON :: Value -> Parser DynamodbDataSourceConfig
parseJSON =
    String
-> (Object -> Parser DynamodbDataSourceConfig)
-> Value
-> Parser DynamodbDataSourceConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DynamodbDataSourceConfig"
      ( \Object
x ->
          Maybe Bool
-> Maybe Bool
-> Maybe DeltaSyncConfig
-> Text
-> Text
-> DynamodbDataSourceConfig
DynamodbDataSourceConfig'
            (Maybe Bool
 -> Maybe Bool
 -> Maybe DeltaSyncConfig
 -> Text
 -> Text
 -> DynamodbDataSourceConfig)
-> Parser (Maybe Bool)
-> Parser
     (Maybe Bool
      -> Maybe DeltaSyncConfig
      -> Text
      -> Text
      -> DynamodbDataSourceConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"versioned")
            Parser
  (Maybe Bool
   -> Maybe DeltaSyncConfig
   -> Text
   -> Text
   -> DynamodbDataSourceConfig)
-> Parser (Maybe Bool)
-> Parser
     (Maybe DeltaSyncConfig -> Text -> Text -> DynamodbDataSourceConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"useCallerCredentials")
            Parser
  (Maybe DeltaSyncConfig -> Text -> Text -> DynamodbDataSourceConfig)
-> Parser (Maybe DeltaSyncConfig)
-> Parser (Text -> Text -> DynamodbDataSourceConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe DeltaSyncConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"deltaSyncConfig")
            Parser (Text -> Text -> DynamodbDataSourceConfig)
-> Parser Text -> Parser (Text -> DynamodbDataSourceConfig)
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
"tableName")
            Parser (Text -> DynamodbDataSourceConfig)
-> Parser Text -> Parser DynamodbDataSourceConfig
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 DynamodbDataSourceConfig

instance Prelude.NFData DynamodbDataSourceConfig

instance Core.ToJSON DynamodbDataSourceConfig where
  toJSON :: DynamodbDataSourceConfig -> Value
toJSON DynamodbDataSourceConfig' {Maybe Bool
Maybe DeltaSyncConfig
Text
awsRegion :: Text
tableName :: Text
deltaSyncConfig :: Maybe DeltaSyncConfig
useCallerCredentials :: Maybe Bool
versioned :: Maybe Bool
$sel:awsRegion:DynamodbDataSourceConfig' :: DynamodbDataSourceConfig -> Text
$sel:tableName:DynamodbDataSourceConfig' :: DynamodbDataSourceConfig -> Text
$sel:deltaSyncConfig:DynamodbDataSourceConfig' :: DynamodbDataSourceConfig -> Maybe DeltaSyncConfig
$sel:useCallerCredentials:DynamodbDataSourceConfig' :: DynamodbDataSourceConfig -> Maybe Bool
$sel:versioned:DynamodbDataSourceConfig' :: DynamodbDataSourceConfig -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"versioned" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
versioned,
            (Text
"useCallerCredentials" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
useCallerCredentials,
            (Text
"deltaSyncConfig" Text -> DeltaSyncConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (DeltaSyncConfig -> Pair) -> Maybe DeltaSyncConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DeltaSyncConfig
deltaSyncConfig,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"tableName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
tableName),
            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)
          ]
      )