{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.DynamoDB.Types.CreateGlobalSecondaryIndexAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.DynamoDB.Types.AttributeValue
import Amazonka.DynamoDB.Types.KeySchemaElement
import Amazonka.DynamoDB.Types.Projection
import Amazonka.DynamoDB.Types.ProvisionedThroughput
import Amazonka.DynamoDB.Types.WriteRequest
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
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]
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
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.
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'
      { $sel:provisionedThroughput:CreateGlobalSecondaryIndexAction' :: Maybe ProvisionedThroughput
provisionedThroughput =
          forall a. Maybe a
Prelude.Nothing,
        $sel:indexName:CreateGlobalSecondaryIndexAction' :: Text
indexName = Text
pIndexName_,
        $sel:keySchema:CreateGlobalSecondaryIndexAction' :: NonEmpty KeySchemaElement
keySchema =
          forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced 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 :: Lens'
  CreateGlobalSecondaryIndexAction (Maybe ProvisionedThroughput)
createGlobalSecondaryIndexAction_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 :: Lens' CreateGlobalSecondaryIndexAction Text
createGlobalSecondaryIndexAction_indexName = 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 :: Lens' CreateGlobalSecondaryIndexAction (NonEmpty KeySchemaElement)
createGlobalSecondaryIndexAction_keySchema = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 :: Lens' CreateGlobalSecondaryIndexAction Projection
createGlobalSecondaryIndexAction_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
  where
  hashWithSalt :: Int -> CreateGlobalSecondaryIndexAction -> Int
hashWithSalt
    Int
_salt
    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
..} =
      Int
_salt
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ProvisionedThroughput
provisionedThroughput
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
indexName
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty KeySchemaElement
keySchema
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Projection
projection

instance
  Prelude.NFData
    CreateGlobalSecondaryIndexAction
  where
  rnf :: CreateGlobalSecondaryIndexAction -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ProvisionedThroughput
provisionedThroughput
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
indexName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty KeySchemaElement
keySchema
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Projection
projection

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ProvisionedThroughput" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ProvisionedThroughput
provisionedThroughput,
            forall a. a -> Maybe a
Prelude.Just (Key
"IndexName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
indexName),
            forall a. a -> Maybe a
Prelude.Just (Key
"KeySchema" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty KeySchemaElement
keySchema),
            forall a. a -> Maybe a
Prelude.Just (Key
"Projection" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Projection
projection)
          ]
      )