{-# 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.DynamoDB.Types.CreateGlobalSecondaryIndexAction
-- 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.DynamoDB.Types.CreateGlobalSecondaryIndexAction where

import qualified Amazonka.Core as Core
import Amazonka.DynamoDB.Types.KeySchemaElement
import Amazonka.DynamoDB.Types.Projection
import Amazonka.DynamoDB.Types.ProvisionedThroughput
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a new global secondary index to be added to an existing
-- table.
--
-- /See:/ 'newCreateGlobalSecondaryIndexAction' smart constructor.
data CreateGlobalSecondaryIndexAction = CreateGlobalSecondaryIndexAction'
  { -- | Represents the provisioned throughput settings for the specified global
    -- secondary index.
    --
    -- For current minimum and maximum provisioned throughput values, see
    -- <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html Service, Account, and Table Quotas>
    -- in the /Amazon DynamoDB Developer Guide/.
    CreateGlobalSecondaryIndexAction -> Maybe ProvisionedThroughput
provisionedThroughput :: Prelude.Maybe ProvisionedThroughput,
    -- | The name of the global secondary index to be created.
    CreateGlobalSecondaryIndexAction -> Text
indexName :: Prelude.Text,
    -- | The key schema for the global secondary index.
    CreateGlobalSecondaryIndexAction -> NonEmpty KeySchemaElement
keySchema :: Prelude.NonEmpty KeySchemaElement,
    -- | Represents attributes that are copied (projected) from the table into an
    -- index. These are in addition to the primary key attributes and index key
    -- attributes, which are automatically projected.
    CreateGlobalSecondaryIndexAction -> Projection
projection :: Projection
  }
  deriving (CreateGlobalSecondaryIndexAction
-> CreateGlobalSecondaryIndexAction -> Bool
(CreateGlobalSecondaryIndexAction
 -> CreateGlobalSecondaryIndexAction -> Bool)
-> (CreateGlobalSecondaryIndexAction
    -> CreateGlobalSecondaryIndexAction -> Bool)
-> Eq CreateGlobalSecondaryIndexAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateGlobalSecondaryIndexAction
-> CreateGlobalSecondaryIndexAction -> Bool
$c/= :: CreateGlobalSecondaryIndexAction
-> CreateGlobalSecondaryIndexAction -> Bool
== :: CreateGlobalSecondaryIndexAction
-> CreateGlobalSecondaryIndexAction -> Bool
$c== :: CreateGlobalSecondaryIndexAction
-> CreateGlobalSecondaryIndexAction -> Bool
Prelude.Eq, ReadPrec [CreateGlobalSecondaryIndexAction]
ReadPrec CreateGlobalSecondaryIndexAction
Int -> ReadS CreateGlobalSecondaryIndexAction
ReadS [CreateGlobalSecondaryIndexAction]
(Int -> ReadS CreateGlobalSecondaryIndexAction)
-> ReadS [CreateGlobalSecondaryIndexAction]
-> ReadPrec CreateGlobalSecondaryIndexAction
-> ReadPrec [CreateGlobalSecondaryIndexAction]
-> Read CreateGlobalSecondaryIndexAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateGlobalSecondaryIndexAction]
$creadListPrec :: ReadPrec [CreateGlobalSecondaryIndexAction]
readPrec :: ReadPrec CreateGlobalSecondaryIndexAction
$creadPrec :: ReadPrec CreateGlobalSecondaryIndexAction
readList :: ReadS [CreateGlobalSecondaryIndexAction]
$creadList :: ReadS [CreateGlobalSecondaryIndexAction]
readsPrec :: Int -> ReadS CreateGlobalSecondaryIndexAction
$creadsPrec :: Int -> ReadS CreateGlobalSecondaryIndexAction
Prelude.Read, Int -> CreateGlobalSecondaryIndexAction -> ShowS
[CreateGlobalSecondaryIndexAction] -> ShowS
CreateGlobalSecondaryIndexAction -> String
(Int -> CreateGlobalSecondaryIndexAction -> ShowS)
-> (CreateGlobalSecondaryIndexAction -> String)
-> ([CreateGlobalSecondaryIndexAction] -> ShowS)
-> Show CreateGlobalSecondaryIndexAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateGlobalSecondaryIndexAction] -> ShowS
$cshowList :: [CreateGlobalSecondaryIndexAction] -> ShowS
show :: CreateGlobalSecondaryIndexAction -> String
$cshow :: CreateGlobalSecondaryIndexAction -> String
showsPrec :: Int -> CreateGlobalSecondaryIndexAction -> ShowS
$cshowsPrec :: Int -> CreateGlobalSecondaryIndexAction -> ShowS
Prelude.Show, (forall x.
 CreateGlobalSecondaryIndexAction
 -> Rep CreateGlobalSecondaryIndexAction x)
-> (forall x.
    Rep CreateGlobalSecondaryIndexAction x
    -> CreateGlobalSecondaryIndexAction)
-> Generic CreateGlobalSecondaryIndexAction
forall x.
Rep CreateGlobalSecondaryIndexAction x
-> CreateGlobalSecondaryIndexAction
forall x.
CreateGlobalSecondaryIndexAction
-> Rep CreateGlobalSecondaryIndexAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateGlobalSecondaryIndexAction x
-> CreateGlobalSecondaryIndexAction
$cfrom :: forall x.
CreateGlobalSecondaryIndexAction
-> Rep CreateGlobalSecondaryIndexAction x
Prelude.Generic)

-- |
-- Create a value of 'CreateGlobalSecondaryIndexAction' 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:
--
-- 'provisionedThroughput', 'createGlobalSecondaryIndexAction_provisionedThroughput' - Represents the provisioned throughput settings for the specified global
-- secondary index.
--
-- For current minimum and maximum provisioned throughput values, see
-- <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html Service, Account, and Table Quotas>
-- in the /Amazon DynamoDB Developer Guide/.
--
-- 'indexName', 'createGlobalSecondaryIndexAction_indexName' - The name of the global secondary index to be created.
--
-- 'keySchema', 'createGlobalSecondaryIndexAction_keySchema' - The key schema for the global secondary index.
--
-- 'projection', 'createGlobalSecondaryIndexAction_projection' - Represents attributes that are copied (projected) from the table into an
-- index. These are in addition to the primary key attributes and index key
-- attributes, which are automatically projected.
newCreateGlobalSecondaryIndexAction ::
  -- | 'indexName'
  Prelude.Text ->
  -- | 'keySchema'
  Prelude.NonEmpty KeySchemaElement ->
  -- | 'projection'
  Projection ->
  CreateGlobalSecondaryIndexAction
newCreateGlobalSecondaryIndexAction :: Text
-> NonEmpty KeySchemaElement
-> Projection
-> CreateGlobalSecondaryIndexAction
newCreateGlobalSecondaryIndexAction
  Text
pIndexName_
  NonEmpty KeySchemaElement
pKeySchema_
  Projection
pProjection_ =
    CreateGlobalSecondaryIndexAction' :: Maybe ProvisionedThroughput
-> Text
-> NonEmpty KeySchemaElement
-> Projection
-> CreateGlobalSecondaryIndexAction
CreateGlobalSecondaryIndexAction'
      { $sel:provisionedThroughput:CreateGlobalSecondaryIndexAction' :: Maybe ProvisionedThroughput
provisionedThroughput =
          Maybe ProvisionedThroughput
forall a. Maybe a
Prelude.Nothing,
        $sel:indexName:CreateGlobalSecondaryIndexAction' :: Text
indexName = Text
pIndexName_,
        $sel:keySchema:CreateGlobalSecondaryIndexAction' :: NonEmpty KeySchemaElement
keySchema =
          Tagged
  (NonEmpty KeySchemaElement) (Identity (NonEmpty KeySchemaElement))
-> Tagged
     (NonEmpty KeySchemaElement) (Identity (NonEmpty KeySchemaElement))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty KeySchemaElement) (Identity (NonEmpty KeySchemaElement))
 -> Tagged
      (NonEmpty KeySchemaElement) (Identity (NonEmpty KeySchemaElement)))
-> NonEmpty KeySchemaElement -> NonEmpty KeySchemaElement
forall t b. AReview t b -> b -> t
Lens.# NonEmpty KeySchemaElement
pKeySchema_,
        $sel:projection:CreateGlobalSecondaryIndexAction' :: Projection
projection = Projection
pProjection_
      }

-- | Represents the provisioned throughput settings for the specified global
-- secondary index.
--
-- For current minimum and maximum provisioned throughput values, see
-- <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html Service, Account, and Table Quotas>
-- in the /Amazon DynamoDB Developer Guide/.
createGlobalSecondaryIndexAction_provisionedThroughput :: Lens.Lens' CreateGlobalSecondaryIndexAction (Prelude.Maybe ProvisionedThroughput)
createGlobalSecondaryIndexAction_provisionedThroughput :: (Maybe ProvisionedThroughput -> f (Maybe ProvisionedThroughput))
-> CreateGlobalSecondaryIndexAction
-> f CreateGlobalSecondaryIndexAction
createGlobalSecondaryIndexAction_provisionedThroughput = (CreateGlobalSecondaryIndexAction -> Maybe ProvisionedThroughput)
-> (CreateGlobalSecondaryIndexAction
    -> Maybe ProvisionedThroughput -> CreateGlobalSecondaryIndexAction)
-> Lens
     CreateGlobalSecondaryIndexAction
     CreateGlobalSecondaryIndexAction
     (Maybe ProvisionedThroughput)
     (Maybe ProvisionedThroughput)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateGlobalSecondaryIndexAction' {Maybe ProvisionedThroughput
provisionedThroughput :: Maybe ProvisionedThroughput
$sel:provisionedThroughput:CreateGlobalSecondaryIndexAction' :: CreateGlobalSecondaryIndexAction -> Maybe ProvisionedThroughput
provisionedThroughput} -> Maybe ProvisionedThroughput
provisionedThroughput) (\s :: CreateGlobalSecondaryIndexAction
s@CreateGlobalSecondaryIndexAction' {} Maybe ProvisionedThroughput
a -> CreateGlobalSecondaryIndexAction
s {$sel:provisionedThroughput:CreateGlobalSecondaryIndexAction' :: Maybe ProvisionedThroughput
provisionedThroughput = Maybe ProvisionedThroughput
a} :: CreateGlobalSecondaryIndexAction)

-- | The name of the global secondary index to be created.
createGlobalSecondaryIndexAction_indexName :: Lens.Lens' CreateGlobalSecondaryIndexAction Prelude.Text
createGlobalSecondaryIndexAction_indexName :: (Text -> f Text)
-> CreateGlobalSecondaryIndexAction
-> f CreateGlobalSecondaryIndexAction
createGlobalSecondaryIndexAction_indexName = (CreateGlobalSecondaryIndexAction -> Text)
-> (CreateGlobalSecondaryIndexAction
    -> Text -> CreateGlobalSecondaryIndexAction)
-> Lens
     CreateGlobalSecondaryIndexAction
     CreateGlobalSecondaryIndexAction
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateGlobalSecondaryIndexAction' {Text
indexName :: Text
$sel:indexName:CreateGlobalSecondaryIndexAction' :: CreateGlobalSecondaryIndexAction -> Text
indexName} -> Text
indexName) (\s :: CreateGlobalSecondaryIndexAction
s@CreateGlobalSecondaryIndexAction' {} Text
a -> CreateGlobalSecondaryIndexAction
s {$sel:indexName:CreateGlobalSecondaryIndexAction' :: Text
indexName = Text
a} :: CreateGlobalSecondaryIndexAction)

-- | The key schema for the global secondary index.
createGlobalSecondaryIndexAction_keySchema :: Lens.Lens' CreateGlobalSecondaryIndexAction (Prelude.NonEmpty KeySchemaElement)
createGlobalSecondaryIndexAction_keySchema :: (NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
-> CreateGlobalSecondaryIndexAction
-> f CreateGlobalSecondaryIndexAction
createGlobalSecondaryIndexAction_keySchema = (CreateGlobalSecondaryIndexAction -> NonEmpty KeySchemaElement)
-> (CreateGlobalSecondaryIndexAction
    -> NonEmpty KeySchemaElement -> CreateGlobalSecondaryIndexAction)
-> Lens
     CreateGlobalSecondaryIndexAction
     CreateGlobalSecondaryIndexAction
     (NonEmpty KeySchemaElement)
     (NonEmpty KeySchemaElement)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateGlobalSecondaryIndexAction' {NonEmpty KeySchemaElement
keySchema :: NonEmpty KeySchemaElement
$sel:keySchema:CreateGlobalSecondaryIndexAction' :: CreateGlobalSecondaryIndexAction -> NonEmpty KeySchemaElement
keySchema} -> NonEmpty KeySchemaElement
keySchema) (\s :: CreateGlobalSecondaryIndexAction
s@CreateGlobalSecondaryIndexAction' {} NonEmpty KeySchemaElement
a -> CreateGlobalSecondaryIndexAction
s {$sel:keySchema:CreateGlobalSecondaryIndexAction' :: NonEmpty KeySchemaElement
keySchema = NonEmpty KeySchemaElement
a} :: CreateGlobalSecondaryIndexAction) ((NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
 -> CreateGlobalSecondaryIndexAction
 -> f CreateGlobalSecondaryIndexAction)
-> ((NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
    -> NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
-> (NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
-> CreateGlobalSecondaryIndexAction
-> f CreateGlobalSecondaryIndexAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
-> NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Represents attributes that are copied (projected) from the table into an
-- index. These are in addition to the primary key attributes and index key
-- attributes, which are automatically projected.
createGlobalSecondaryIndexAction_projection :: Lens.Lens' CreateGlobalSecondaryIndexAction Projection
createGlobalSecondaryIndexAction_projection :: (Projection -> f Projection)
-> CreateGlobalSecondaryIndexAction
-> f CreateGlobalSecondaryIndexAction
createGlobalSecondaryIndexAction_projection = (CreateGlobalSecondaryIndexAction -> Projection)
-> (CreateGlobalSecondaryIndexAction
    -> Projection -> CreateGlobalSecondaryIndexAction)
-> Lens
     CreateGlobalSecondaryIndexAction
     CreateGlobalSecondaryIndexAction
     Projection
     Projection
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateGlobalSecondaryIndexAction' {Projection
projection :: Projection
$sel:projection:CreateGlobalSecondaryIndexAction' :: CreateGlobalSecondaryIndexAction -> Projection
projection} -> Projection
projection) (\s :: CreateGlobalSecondaryIndexAction
s@CreateGlobalSecondaryIndexAction' {} Projection
a -> CreateGlobalSecondaryIndexAction
s {$sel:projection:CreateGlobalSecondaryIndexAction' :: Projection
projection = Projection
a} :: CreateGlobalSecondaryIndexAction)

instance
  Prelude.Hashable
    CreateGlobalSecondaryIndexAction

instance
  Prelude.NFData
    CreateGlobalSecondaryIndexAction

instance Core.ToJSON CreateGlobalSecondaryIndexAction where
  toJSON :: CreateGlobalSecondaryIndexAction -> Value
toJSON CreateGlobalSecondaryIndexAction' {Maybe ProvisionedThroughput
NonEmpty KeySchemaElement
Text
Projection
projection :: Projection
keySchema :: NonEmpty KeySchemaElement
indexName :: Text
provisionedThroughput :: Maybe ProvisionedThroughput
$sel:projection:CreateGlobalSecondaryIndexAction' :: CreateGlobalSecondaryIndexAction -> Projection
$sel:keySchema:CreateGlobalSecondaryIndexAction' :: CreateGlobalSecondaryIndexAction -> NonEmpty KeySchemaElement
$sel:indexName:CreateGlobalSecondaryIndexAction' :: CreateGlobalSecondaryIndexAction -> Text
$sel:provisionedThroughput:CreateGlobalSecondaryIndexAction' :: CreateGlobalSecondaryIndexAction -> Maybe ProvisionedThroughput
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ProvisionedThroughput" Text -> ProvisionedThroughput -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ProvisionedThroughput -> Pair)
-> Maybe ProvisionedThroughput -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ProvisionedThroughput
provisionedThroughput,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"IndexName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
indexName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"KeySchema" Text -> NonEmpty KeySchemaElement -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty KeySchemaElement
keySchema),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Projection" Text -> Projection -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Projection
projection)
          ]
      )