{-# 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.GlobalSecondaryIndex
-- 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.GlobalSecondaryIndex 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 the properties of a global secondary index.
--
-- /See:/ 'newGlobalSecondaryIndex' smart constructor.
data GlobalSecondaryIndex = GlobalSecondaryIndex'
  { -- | 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/.
    GlobalSecondaryIndex -> Maybe ProvisionedThroughput
provisionedThroughput :: Prelude.Maybe ProvisionedThroughput,
    -- | The name of the global secondary index. The name must be unique among
    -- all other indexes on this table.
    GlobalSecondaryIndex -> Text
indexName :: Prelude.Text,
    -- | The complete key schema for a global secondary index, which consists of
    -- one or more pairs of attribute names and key types:
    --
    -- -   @HASH@ - partition key
    --
    -- -   @RANGE@ - sort key
    --
    -- The partition key of an item is also known as its /hash attribute/. The
    -- term \"hash attribute\" derives from DynamoDB\'s usage of an internal
    -- hash function to evenly distribute data items across partitions, based
    -- on their partition key values.
    --
    -- The sort key of an item is also known as its /range attribute/. The term
    -- \"range attribute\" derives from the way DynamoDB stores items with the
    -- same partition key physically close together, in sorted order by the
    -- sort key value.
    GlobalSecondaryIndex -> NonEmpty KeySchemaElement
keySchema :: Prelude.NonEmpty KeySchemaElement,
    -- | Represents attributes that are copied (projected) from the table into
    -- the global secondary index. These are in addition to the primary key
    -- attributes and index key attributes, which are automatically projected.
    GlobalSecondaryIndex -> Projection
projection :: Projection
  }
  deriving (GlobalSecondaryIndex -> GlobalSecondaryIndex -> Bool
(GlobalSecondaryIndex -> GlobalSecondaryIndex -> Bool)
-> (GlobalSecondaryIndex -> GlobalSecondaryIndex -> Bool)
-> Eq GlobalSecondaryIndex
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GlobalSecondaryIndex -> GlobalSecondaryIndex -> Bool
$c/= :: GlobalSecondaryIndex -> GlobalSecondaryIndex -> Bool
== :: GlobalSecondaryIndex -> GlobalSecondaryIndex -> Bool
$c== :: GlobalSecondaryIndex -> GlobalSecondaryIndex -> Bool
Prelude.Eq, ReadPrec [GlobalSecondaryIndex]
ReadPrec GlobalSecondaryIndex
Int -> ReadS GlobalSecondaryIndex
ReadS [GlobalSecondaryIndex]
(Int -> ReadS GlobalSecondaryIndex)
-> ReadS [GlobalSecondaryIndex]
-> ReadPrec GlobalSecondaryIndex
-> ReadPrec [GlobalSecondaryIndex]
-> Read GlobalSecondaryIndex
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GlobalSecondaryIndex]
$creadListPrec :: ReadPrec [GlobalSecondaryIndex]
readPrec :: ReadPrec GlobalSecondaryIndex
$creadPrec :: ReadPrec GlobalSecondaryIndex
readList :: ReadS [GlobalSecondaryIndex]
$creadList :: ReadS [GlobalSecondaryIndex]
readsPrec :: Int -> ReadS GlobalSecondaryIndex
$creadsPrec :: Int -> ReadS GlobalSecondaryIndex
Prelude.Read, Int -> GlobalSecondaryIndex -> ShowS
[GlobalSecondaryIndex] -> ShowS
GlobalSecondaryIndex -> String
(Int -> GlobalSecondaryIndex -> ShowS)
-> (GlobalSecondaryIndex -> String)
-> ([GlobalSecondaryIndex] -> ShowS)
-> Show GlobalSecondaryIndex
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GlobalSecondaryIndex] -> ShowS
$cshowList :: [GlobalSecondaryIndex] -> ShowS
show :: GlobalSecondaryIndex -> String
$cshow :: GlobalSecondaryIndex -> String
showsPrec :: Int -> GlobalSecondaryIndex -> ShowS
$cshowsPrec :: Int -> GlobalSecondaryIndex -> ShowS
Prelude.Show, (forall x. GlobalSecondaryIndex -> Rep GlobalSecondaryIndex x)
-> (forall x. Rep GlobalSecondaryIndex x -> GlobalSecondaryIndex)
-> Generic GlobalSecondaryIndex
forall x. Rep GlobalSecondaryIndex x -> GlobalSecondaryIndex
forall x. GlobalSecondaryIndex -> Rep GlobalSecondaryIndex x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GlobalSecondaryIndex x -> GlobalSecondaryIndex
$cfrom :: forall x. GlobalSecondaryIndex -> Rep GlobalSecondaryIndex x
Prelude.Generic)

-- |
-- Create a value of 'GlobalSecondaryIndex' 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', 'globalSecondaryIndex_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', 'globalSecondaryIndex_indexName' - The name of the global secondary index. The name must be unique among
-- all other indexes on this table.
--
-- 'keySchema', 'globalSecondaryIndex_keySchema' - The complete key schema for a global secondary index, which consists of
-- one or more pairs of attribute names and key types:
--
-- -   @HASH@ - partition key
--
-- -   @RANGE@ - sort key
--
-- The partition key of an item is also known as its /hash attribute/. The
-- term \"hash attribute\" derives from DynamoDB\'s usage of an internal
-- hash function to evenly distribute data items across partitions, based
-- on their partition key values.
--
-- The sort key of an item is also known as its /range attribute/. The term
-- \"range attribute\" derives from the way DynamoDB stores items with the
-- same partition key physically close together, in sorted order by the
-- sort key value.
--
-- 'projection', 'globalSecondaryIndex_projection' - Represents attributes that are copied (projected) from the table into
-- the global secondary index. These are in addition to the primary key
-- attributes and index key attributes, which are automatically projected.
newGlobalSecondaryIndex ::
  -- | 'indexName'
  Prelude.Text ->
  -- | 'keySchema'
  Prelude.NonEmpty KeySchemaElement ->
  -- | 'projection'
  Projection ->
  GlobalSecondaryIndex
newGlobalSecondaryIndex :: Text
-> NonEmpty KeySchemaElement -> Projection -> GlobalSecondaryIndex
newGlobalSecondaryIndex
  Text
pIndexName_
  NonEmpty KeySchemaElement
pKeySchema_
  Projection
pProjection_ =
    GlobalSecondaryIndex' :: Maybe ProvisionedThroughput
-> Text
-> NonEmpty KeySchemaElement
-> Projection
-> GlobalSecondaryIndex
GlobalSecondaryIndex'
      { $sel:provisionedThroughput:GlobalSecondaryIndex' :: Maybe ProvisionedThroughput
provisionedThroughput =
          Maybe ProvisionedThroughput
forall a. Maybe a
Prelude.Nothing,
        $sel:indexName:GlobalSecondaryIndex' :: Text
indexName = Text
pIndexName_,
        $sel:keySchema:GlobalSecondaryIndex' :: 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:GlobalSecondaryIndex' :: 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/.
globalSecondaryIndex_provisionedThroughput :: Lens.Lens' GlobalSecondaryIndex (Prelude.Maybe ProvisionedThroughput)
globalSecondaryIndex_provisionedThroughput :: (Maybe ProvisionedThroughput -> f (Maybe ProvisionedThroughput))
-> GlobalSecondaryIndex -> f GlobalSecondaryIndex
globalSecondaryIndex_provisionedThroughput = (GlobalSecondaryIndex -> Maybe ProvisionedThroughput)
-> (GlobalSecondaryIndex
    -> Maybe ProvisionedThroughput -> GlobalSecondaryIndex)
-> Lens
     GlobalSecondaryIndex
     GlobalSecondaryIndex
     (Maybe ProvisionedThroughput)
     (Maybe ProvisionedThroughput)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GlobalSecondaryIndex' {Maybe ProvisionedThroughput
provisionedThroughput :: Maybe ProvisionedThroughput
$sel:provisionedThroughput:GlobalSecondaryIndex' :: GlobalSecondaryIndex -> Maybe ProvisionedThroughput
provisionedThroughput} -> Maybe ProvisionedThroughput
provisionedThroughput) (\s :: GlobalSecondaryIndex
s@GlobalSecondaryIndex' {} Maybe ProvisionedThroughput
a -> GlobalSecondaryIndex
s {$sel:provisionedThroughput:GlobalSecondaryIndex' :: Maybe ProvisionedThroughput
provisionedThroughput = Maybe ProvisionedThroughput
a} :: GlobalSecondaryIndex)

-- | The name of the global secondary index. The name must be unique among
-- all other indexes on this table.
globalSecondaryIndex_indexName :: Lens.Lens' GlobalSecondaryIndex Prelude.Text
globalSecondaryIndex_indexName :: (Text -> f Text) -> GlobalSecondaryIndex -> f GlobalSecondaryIndex
globalSecondaryIndex_indexName = (GlobalSecondaryIndex -> Text)
-> (GlobalSecondaryIndex -> Text -> GlobalSecondaryIndex)
-> Lens GlobalSecondaryIndex GlobalSecondaryIndex Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GlobalSecondaryIndex' {Text
indexName :: Text
$sel:indexName:GlobalSecondaryIndex' :: GlobalSecondaryIndex -> Text
indexName} -> Text
indexName) (\s :: GlobalSecondaryIndex
s@GlobalSecondaryIndex' {} Text
a -> GlobalSecondaryIndex
s {$sel:indexName:GlobalSecondaryIndex' :: Text
indexName = Text
a} :: GlobalSecondaryIndex)

-- | The complete key schema for a global secondary index, which consists of
-- one or more pairs of attribute names and key types:
--
-- -   @HASH@ - partition key
--
-- -   @RANGE@ - sort key
--
-- The partition key of an item is also known as its /hash attribute/. The
-- term \"hash attribute\" derives from DynamoDB\'s usage of an internal
-- hash function to evenly distribute data items across partitions, based
-- on their partition key values.
--
-- The sort key of an item is also known as its /range attribute/. The term
-- \"range attribute\" derives from the way DynamoDB stores items with the
-- same partition key physically close together, in sorted order by the
-- sort key value.
globalSecondaryIndex_keySchema :: Lens.Lens' GlobalSecondaryIndex (Prelude.NonEmpty KeySchemaElement)
globalSecondaryIndex_keySchema :: (NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
-> GlobalSecondaryIndex -> f GlobalSecondaryIndex
globalSecondaryIndex_keySchema = (GlobalSecondaryIndex -> NonEmpty KeySchemaElement)
-> (GlobalSecondaryIndex
    -> NonEmpty KeySchemaElement -> GlobalSecondaryIndex)
-> Lens
     GlobalSecondaryIndex
     GlobalSecondaryIndex
     (NonEmpty KeySchemaElement)
     (NonEmpty KeySchemaElement)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GlobalSecondaryIndex' {NonEmpty KeySchemaElement
keySchema :: NonEmpty KeySchemaElement
$sel:keySchema:GlobalSecondaryIndex' :: GlobalSecondaryIndex -> NonEmpty KeySchemaElement
keySchema} -> NonEmpty KeySchemaElement
keySchema) (\s :: GlobalSecondaryIndex
s@GlobalSecondaryIndex' {} NonEmpty KeySchemaElement
a -> GlobalSecondaryIndex
s {$sel:keySchema:GlobalSecondaryIndex' :: NonEmpty KeySchemaElement
keySchema = NonEmpty KeySchemaElement
a} :: GlobalSecondaryIndex) ((NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
 -> GlobalSecondaryIndex -> f GlobalSecondaryIndex)
-> ((NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
    -> NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
-> (NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
-> GlobalSecondaryIndex
-> f GlobalSecondaryIndex
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
-- the global secondary index. These are in addition to the primary key
-- attributes and index key attributes, which are automatically projected.
globalSecondaryIndex_projection :: Lens.Lens' GlobalSecondaryIndex Projection
globalSecondaryIndex_projection :: (Projection -> f Projection)
-> GlobalSecondaryIndex -> f GlobalSecondaryIndex
globalSecondaryIndex_projection = (GlobalSecondaryIndex -> Projection)
-> (GlobalSecondaryIndex -> Projection -> GlobalSecondaryIndex)
-> Lens
     GlobalSecondaryIndex GlobalSecondaryIndex Projection Projection
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GlobalSecondaryIndex' {Projection
projection :: Projection
$sel:projection:GlobalSecondaryIndex' :: GlobalSecondaryIndex -> Projection
projection} -> Projection
projection) (\s :: GlobalSecondaryIndex
s@GlobalSecondaryIndex' {} Projection
a -> GlobalSecondaryIndex
s {$sel:projection:GlobalSecondaryIndex' :: Projection
projection = Projection
a} :: GlobalSecondaryIndex)

instance Prelude.Hashable GlobalSecondaryIndex

instance Prelude.NFData GlobalSecondaryIndex

instance Core.ToJSON GlobalSecondaryIndex where
  toJSON :: GlobalSecondaryIndex -> Value
toJSON GlobalSecondaryIndex' {Maybe ProvisionedThroughput
NonEmpty KeySchemaElement
Text
Projection
projection :: Projection
keySchema :: NonEmpty KeySchemaElement
indexName :: Text
provisionedThroughput :: Maybe ProvisionedThroughput
$sel:projection:GlobalSecondaryIndex' :: GlobalSecondaryIndex -> Projection
$sel:keySchema:GlobalSecondaryIndex' :: GlobalSecondaryIndex -> NonEmpty KeySchemaElement
$sel:indexName:GlobalSecondaryIndex' :: GlobalSecondaryIndex -> Text
$sel:provisionedThroughput:GlobalSecondaryIndex' :: GlobalSecondaryIndex -> 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)
          ]
      )