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

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

-- | Represents the properties of a local secondary index.
--
-- /See:/ 'newLocalSecondaryIndex' smart constructor.
data LocalSecondaryIndex = LocalSecondaryIndex'
  { -- | The name of the local secondary index. The name must be unique among all
    -- other indexes on this table.
    LocalSecondaryIndex -> Text
indexName :: Prelude.Text,
    -- | The complete key schema for the local secondary index, consisting 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.
    LocalSecondaryIndex -> NonEmpty KeySchemaElement
keySchema :: Prelude.NonEmpty KeySchemaElement,
    -- | Represents attributes that are copied (projected) from the table into
    -- the local secondary index. These are in addition to the primary key
    -- attributes and index key attributes, which are automatically projected.
    LocalSecondaryIndex -> Projection
projection :: Projection
  }
  deriving (LocalSecondaryIndex -> LocalSecondaryIndex -> Bool
(LocalSecondaryIndex -> LocalSecondaryIndex -> Bool)
-> (LocalSecondaryIndex -> LocalSecondaryIndex -> Bool)
-> Eq LocalSecondaryIndex
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LocalSecondaryIndex -> LocalSecondaryIndex -> Bool
$c/= :: LocalSecondaryIndex -> LocalSecondaryIndex -> Bool
== :: LocalSecondaryIndex -> LocalSecondaryIndex -> Bool
$c== :: LocalSecondaryIndex -> LocalSecondaryIndex -> Bool
Prelude.Eq, ReadPrec [LocalSecondaryIndex]
ReadPrec LocalSecondaryIndex
Int -> ReadS LocalSecondaryIndex
ReadS [LocalSecondaryIndex]
(Int -> ReadS LocalSecondaryIndex)
-> ReadS [LocalSecondaryIndex]
-> ReadPrec LocalSecondaryIndex
-> ReadPrec [LocalSecondaryIndex]
-> Read LocalSecondaryIndex
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LocalSecondaryIndex]
$creadListPrec :: ReadPrec [LocalSecondaryIndex]
readPrec :: ReadPrec LocalSecondaryIndex
$creadPrec :: ReadPrec LocalSecondaryIndex
readList :: ReadS [LocalSecondaryIndex]
$creadList :: ReadS [LocalSecondaryIndex]
readsPrec :: Int -> ReadS LocalSecondaryIndex
$creadsPrec :: Int -> ReadS LocalSecondaryIndex
Prelude.Read, Int -> LocalSecondaryIndex -> ShowS
[LocalSecondaryIndex] -> ShowS
LocalSecondaryIndex -> String
(Int -> LocalSecondaryIndex -> ShowS)
-> (LocalSecondaryIndex -> String)
-> ([LocalSecondaryIndex] -> ShowS)
-> Show LocalSecondaryIndex
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LocalSecondaryIndex] -> ShowS
$cshowList :: [LocalSecondaryIndex] -> ShowS
show :: LocalSecondaryIndex -> String
$cshow :: LocalSecondaryIndex -> String
showsPrec :: Int -> LocalSecondaryIndex -> ShowS
$cshowsPrec :: Int -> LocalSecondaryIndex -> ShowS
Prelude.Show, (forall x. LocalSecondaryIndex -> Rep LocalSecondaryIndex x)
-> (forall x. Rep LocalSecondaryIndex x -> LocalSecondaryIndex)
-> Generic LocalSecondaryIndex
forall x. Rep LocalSecondaryIndex x -> LocalSecondaryIndex
forall x. LocalSecondaryIndex -> Rep LocalSecondaryIndex x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LocalSecondaryIndex x -> LocalSecondaryIndex
$cfrom :: forall x. LocalSecondaryIndex -> Rep LocalSecondaryIndex x
Prelude.Generic)

-- |
-- Create a value of 'LocalSecondaryIndex' 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:
--
-- 'indexName', 'localSecondaryIndex_indexName' - The name of the local secondary index. The name must be unique among all
-- other indexes on this table.
--
-- 'keySchema', 'localSecondaryIndex_keySchema' - The complete key schema for the local secondary index, consisting 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', 'localSecondaryIndex_projection' - Represents attributes that are copied (projected) from the table into
-- the local secondary index. These are in addition to the primary key
-- attributes and index key attributes, which are automatically projected.
newLocalSecondaryIndex ::
  -- | 'indexName'
  Prelude.Text ->
  -- | 'keySchema'
  Prelude.NonEmpty KeySchemaElement ->
  -- | 'projection'
  Projection ->
  LocalSecondaryIndex
newLocalSecondaryIndex :: Text
-> NonEmpty KeySchemaElement -> Projection -> LocalSecondaryIndex
newLocalSecondaryIndex
  Text
pIndexName_
  NonEmpty KeySchemaElement
pKeySchema_
  Projection
pProjection_ =
    LocalSecondaryIndex' :: Text
-> NonEmpty KeySchemaElement -> Projection -> LocalSecondaryIndex
LocalSecondaryIndex'
      { $sel:indexName:LocalSecondaryIndex' :: Text
indexName = Text
pIndexName_,
        $sel:keySchema:LocalSecondaryIndex' :: 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:LocalSecondaryIndex' :: Projection
projection = Projection
pProjection_
      }

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

-- | The complete key schema for the local secondary index, consisting 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.
localSecondaryIndex_keySchema :: Lens.Lens' LocalSecondaryIndex (Prelude.NonEmpty KeySchemaElement)
localSecondaryIndex_keySchema :: (NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
-> LocalSecondaryIndex -> f LocalSecondaryIndex
localSecondaryIndex_keySchema = (LocalSecondaryIndex -> NonEmpty KeySchemaElement)
-> (LocalSecondaryIndex
    -> NonEmpty KeySchemaElement -> LocalSecondaryIndex)
-> Lens
     LocalSecondaryIndex
     LocalSecondaryIndex
     (NonEmpty KeySchemaElement)
     (NonEmpty KeySchemaElement)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LocalSecondaryIndex' {NonEmpty KeySchemaElement
keySchema :: NonEmpty KeySchemaElement
$sel:keySchema:LocalSecondaryIndex' :: LocalSecondaryIndex -> NonEmpty KeySchemaElement
keySchema} -> NonEmpty KeySchemaElement
keySchema) (\s :: LocalSecondaryIndex
s@LocalSecondaryIndex' {} NonEmpty KeySchemaElement
a -> LocalSecondaryIndex
s {$sel:keySchema:LocalSecondaryIndex' :: NonEmpty KeySchemaElement
keySchema = NonEmpty KeySchemaElement
a} :: LocalSecondaryIndex) ((NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
 -> LocalSecondaryIndex -> f LocalSecondaryIndex)
-> ((NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
    -> NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
-> (NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
-> LocalSecondaryIndex
-> f LocalSecondaryIndex
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 local secondary index. These are in addition to the primary key
-- attributes and index key attributes, which are automatically projected.
localSecondaryIndex_projection :: Lens.Lens' LocalSecondaryIndex Projection
localSecondaryIndex_projection :: (Projection -> f Projection)
-> LocalSecondaryIndex -> f LocalSecondaryIndex
localSecondaryIndex_projection = (LocalSecondaryIndex -> Projection)
-> (LocalSecondaryIndex -> Projection -> LocalSecondaryIndex)
-> Lens
     LocalSecondaryIndex LocalSecondaryIndex Projection Projection
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LocalSecondaryIndex' {Projection
projection :: Projection
$sel:projection:LocalSecondaryIndex' :: LocalSecondaryIndex -> Projection
projection} -> Projection
projection) (\s :: LocalSecondaryIndex
s@LocalSecondaryIndex' {} Projection
a -> LocalSecondaryIndex
s {$sel:projection:LocalSecondaryIndex' :: Projection
projection = Projection
a} :: LocalSecondaryIndex)

instance Prelude.Hashable LocalSecondaryIndex

instance Prelude.NFData LocalSecondaryIndex

instance Core.ToJSON LocalSecondaryIndex where
  toJSON :: LocalSecondaryIndex -> Value
toJSON LocalSecondaryIndex' {NonEmpty KeySchemaElement
Text
Projection
projection :: Projection
keySchema :: NonEmpty KeySchemaElement
indexName :: Text
$sel:projection:LocalSecondaryIndex' :: LocalSecondaryIndex -> Projection
$sel:keySchema:LocalSecondaryIndex' :: LocalSecondaryIndex -> NonEmpty KeySchemaElement
$sel:indexName:LocalSecondaryIndex' :: LocalSecondaryIndex -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ 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)
          ]
      )