{-# 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.LocalSecondaryIndexInfo
-- 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.LocalSecondaryIndexInfo 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 for the table when
-- the backup was created.
--
-- /See:/ 'newLocalSecondaryIndexInfo' smart constructor.
data LocalSecondaryIndexInfo = LocalSecondaryIndexInfo'
  { -- | The complete key schema for a local 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.
    LocalSecondaryIndexInfo -> Maybe (NonEmpty KeySchemaElement)
keySchema :: Prelude.Maybe (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.
    LocalSecondaryIndexInfo -> Maybe Projection
projection :: Prelude.Maybe Projection,
    -- | Represents the name of the local secondary index.
    LocalSecondaryIndexInfo -> Maybe Text
indexName :: Prelude.Maybe Prelude.Text
  }
  deriving (LocalSecondaryIndexInfo -> LocalSecondaryIndexInfo -> Bool
(LocalSecondaryIndexInfo -> LocalSecondaryIndexInfo -> Bool)
-> (LocalSecondaryIndexInfo -> LocalSecondaryIndexInfo -> Bool)
-> Eq LocalSecondaryIndexInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LocalSecondaryIndexInfo -> LocalSecondaryIndexInfo -> Bool
$c/= :: LocalSecondaryIndexInfo -> LocalSecondaryIndexInfo -> Bool
== :: LocalSecondaryIndexInfo -> LocalSecondaryIndexInfo -> Bool
$c== :: LocalSecondaryIndexInfo -> LocalSecondaryIndexInfo -> Bool
Prelude.Eq, ReadPrec [LocalSecondaryIndexInfo]
ReadPrec LocalSecondaryIndexInfo
Int -> ReadS LocalSecondaryIndexInfo
ReadS [LocalSecondaryIndexInfo]
(Int -> ReadS LocalSecondaryIndexInfo)
-> ReadS [LocalSecondaryIndexInfo]
-> ReadPrec LocalSecondaryIndexInfo
-> ReadPrec [LocalSecondaryIndexInfo]
-> Read LocalSecondaryIndexInfo
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LocalSecondaryIndexInfo]
$creadListPrec :: ReadPrec [LocalSecondaryIndexInfo]
readPrec :: ReadPrec LocalSecondaryIndexInfo
$creadPrec :: ReadPrec LocalSecondaryIndexInfo
readList :: ReadS [LocalSecondaryIndexInfo]
$creadList :: ReadS [LocalSecondaryIndexInfo]
readsPrec :: Int -> ReadS LocalSecondaryIndexInfo
$creadsPrec :: Int -> ReadS LocalSecondaryIndexInfo
Prelude.Read, Int -> LocalSecondaryIndexInfo -> ShowS
[LocalSecondaryIndexInfo] -> ShowS
LocalSecondaryIndexInfo -> String
(Int -> LocalSecondaryIndexInfo -> ShowS)
-> (LocalSecondaryIndexInfo -> String)
-> ([LocalSecondaryIndexInfo] -> ShowS)
-> Show LocalSecondaryIndexInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LocalSecondaryIndexInfo] -> ShowS
$cshowList :: [LocalSecondaryIndexInfo] -> ShowS
show :: LocalSecondaryIndexInfo -> String
$cshow :: LocalSecondaryIndexInfo -> String
showsPrec :: Int -> LocalSecondaryIndexInfo -> ShowS
$cshowsPrec :: Int -> LocalSecondaryIndexInfo -> ShowS
Prelude.Show, (forall x.
 LocalSecondaryIndexInfo -> Rep LocalSecondaryIndexInfo x)
-> (forall x.
    Rep LocalSecondaryIndexInfo x -> LocalSecondaryIndexInfo)
-> Generic LocalSecondaryIndexInfo
forall x. Rep LocalSecondaryIndexInfo x -> LocalSecondaryIndexInfo
forall x. LocalSecondaryIndexInfo -> Rep LocalSecondaryIndexInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LocalSecondaryIndexInfo x -> LocalSecondaryIndexInfo
$cfrom :: forall x. LocalSecondaryIndexInfo -> Rep LocalSecondaryIndexInfo x
Prelude.Generic)

-- |
-- Create a value of 'LocalSecondaryIndexInfo' 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:
--
-- 'keySchema', 'localSecondaryIndexInfo_keySchema' - The complete key schema for a local 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', 'localSecondaryIndexInfo_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.
--
-- 'indexName', 'localSecondaryIndexInfo_indexName' - Represents the name of the local secondary index.
newLocalSecondaryIndexInfo ::
  LocalSecondaryIndexInfo
newLocalSecondaryIndexInfo :: LocalSecondaryIndexInfo
newLocalSecondaryIndexInfo =
  LocalSecondaryIndexInfo' :: Maybe (NonEmpty KeySchemaElement)
-> Maybe Projection -> Maybe Text -> LocalSecondaryIndexInfo
LocalSecondaryIndexInfo'
    { $sel:keySchema:LocalSecondaryIndexInfo' :: Maybe (NonEmpty KeySchemaElement)
keySchema =
        Maybe (NonEmpty KeySchemaElement)
forall a. Maybe a
Prelude.Nothing,
      $sel:projection:LocalSecondaryIndexInfo' :: Maybe Projection
projection = Maybe Projection
forall a. Maybe a
Prelude.Nothing,
      $sel:indexName:LocalSecondaryIndexInfo' :: Maybe Text
indexName = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The complete key schema for a local 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.
localSecondaryIndexInfo_keySchema :: Lens.Lens' LocalSecondaryIndexInfo (Prelude.Maybe (Prelude.NonEmpty KeySchemaElement))
localSecondaryIndexInfo_keySchema :: (Maybe (NonEmpty KeySchemaElement)
 -> f (Maybe (NonEmpty KeySchemaElement)))
-> LocalSecondaryIndexInfo -> f LocalSecondaryIndexInfo
localSecondaryIndexInfo_keySchema = (LocalSecondaryIndexInfo -> Maybe (NonEmpty KeySchemaElement))
-> (LocalSecondaryIndexInfo
    -> Maybe (NonEmpty KeySchemaElement) -> LocalSecondaryIndexInfo)
-> Lens
     LocalSecondaryIndexInfo
     LocalSecondaryIndexInfo
     (Maybe (NonEmpty KeySchemaElement))
     (Maybe (NonEmpty KeySchemaElement))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LocalSecondaryIndexInfo' {Maybe (NonEmpty KeySchemaElement)
keySchema :: Maybe (NonEmpty KeySchemaElement)
$sel:keySchema:LocalSecondaryIndexInfo' :: LocalSecondaryIndexInfo -> Maybe (NonEmpty KeySchemaElement)
keySchema} -> Maybe (NonEmpty KeySchemaElement)
keySchema) (\s :: LocalSecondaryIndexInfo
s@LocalSecondaryIndexInfo' {} Maybe (NonEmpty KeySchemaElement)
a -> LocalSecondaryIndexInfo
s {$sel:keySchema:LocalSecondaryIndexInfo' :: Maybe (NonEmpty KeySchemaElement)
keySchema = Maybe (NonEmpty KeySchemaElement)
a} :: LocalSecondaryIndexInfo) ((Maybe (NonEmpty KeySchemaElement)
  -> f (Maybe (NonEmpty KeySchemaElement)))
 -> LocalSecondaryIndexInfo -> f LocalSecondaryIndexInfo)
-> ((Maybe (NonEmpty KeySchemaElement)
     -> f (Maybe (NonEmpty KeySchemaElement)))
    -> Maybe (NonEmpty KeySchemaElement)
    -> f (Maybe (NonEmpty KeySchemaElement)))
-> (Maybe (NonEmpty KeySchemaElement)
    -> f (Maybe (NonEmpty KeySchemaElement)))
-> LocalSecondaryIndexInfo
-> f LocalSecondaryIndexInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty KeySchemaElement)
  (NonEmpty KeySchemaElement)
  (NonEmpty KeySchemaElement)
  (NonEmpty KeySchemaElement)
-> Iso
     (Maybe (NonEmpty KeySchemaElement))
     (Maybe (NonEmpty KeySchemaElement))
     (Maybe (NonEmpty KeySchemaElement))
     (Maybe (NonEmpty KeySchemaElement))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (NonEmpty KeySchemaElement)
  (NonEmpty KeySchemaElement)
  (NonEmpty KeySchemaElement)
  (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.
localSecondaryIndexInfo_projection :: Lens.Lens' LocalSecondaryIndexInfo (Prelude.Maybe Projection)
localSecondaryIndexInfo_projection :: (Maybe Projection -> f (Maybe Projection))
-> LocalSecondaryIndexInfo -> f LocalSecondaryIndexInfo
localSecondaryIndexInfo_projection = (LocalSecondaryIndexInfo -> Maybe Projection)
-> (LocalSecondaryIndexInfo
    -> Maybe Projection -> LocalSecondaryIndexInfo)
-> Lens
     LocalSecondaryIndexInfo
     LocalSecondaryIndexInfo
     (Maybe Projection)
     (Maybe Projection)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LocalSecondaryIndexInfo' {Maybe Projection
projection :: Maybe Projection
$sel:projection:LocalSecondaryIndexInfo' :: LocalSecondaryIndexInfo -> Maybe Projection
projection} -> Maybe Projection
projection) (\s :: LocalSecondaryIndexInfo
s@LocalSecondaryIndexInfo' {} Maybe Projection
a -> LocalSecondaryIndexInfo
s {$sel:projection:LocalSecondaryIndexInfo' :: Maybe Projection
projection = Maybe Projection
a} :: LocalSecondaryIndexInfo)

-- | Represents the name of the local secondary index.
localSecondaryIndexInfo_indexName :: Lens.Lens' LocalSecondaryIndexInfo (Prelude.Maybe Prelude.Text)
localSecondaryIndexInfo_indexName :: (Maybe Text -> f (Maybe Text))
-> LocalSecondaryIndexInfo -> f LocalSecondaryIndexInfo
localSecondaryIndexInfo_indexName = (LocalSecondaryIndexInfo -> Maybe Text)
-> (LocalSecondaryIndexInfo
    -> Maybe Text -> LocalSecondaryIndexInfo)
-> Lens
     LocalSecondaryIndexInfo
     LocalSecondaryIndexInfo
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LocalSecondaryIndexInfo' {Maybe Text
indexName :: Maybe Text
$sel:indexName:LocalSecondaryIndexInfo' :: LocalSecondaryIndexInfo -> Maybe Text
indexName} -> Maybe Text
indexName) (\s :: LocalSecondaryIndexInfo
s@LocalSecondaryIndexInfo' {} Maybe Text
a -> LocalSecondaryIndexInfo
s {$sel:indexName:LocalSecondaryIndexInfo' :: Maybe Text
indexName = Maybe Text
a} :: LocalSecondaryIndexInfo)

instance Core.FromJSON LocalSecondaryIndexInfo where
  parseJSON :: Value -> Parser LocalSecondaryIndexInfo
parseJSON =
    String
-> (Object -> Parser LocalSecondaryIndexInfo)
-> Value
-> Parser LocalSecondaryIndexInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"LocalSecondaryIndexInfo"
      ( \Object
x ->
          Maybe (NonEmpty KeySchemaElement)
-> Maybe Projection -> Maybe Text -> LocalSecondaryIndexInfo
LocalSecondaryIndexInfo'
            (Maybe (NonEmpty KeySchemaElement)
 -> Maybe Projection -> Maybe Text -> LocalSecondaryIndexInfo)
-> Parser (Maybe (NonEmpty KeySchemaElement))
-> Parser
     (Maybe Projection -> Maybe Text -> LocalSecondaryIndexInfo)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (NonEmpty KeySchemaElement))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"KeySchema")
            Parser (Maybe Projection -> Maybe Text -> LocalSecondaryIndexInfo)
-> Parser (Maybe Projection)
-> Parser (Maybe Text -> LocalSecondaryIndexInfo)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Projection)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Projection")
            Parser (Maybe Text -> LocalSecondaryIndexInfo)
-> Parser (Maybe Text) -> Parser LocalSecondaryIndexInfo
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"IndexName")
      )

instance Prelude.Hashable LocalSecondaryIndexInfo

instance Prelude.NFData LocalSecondaryIndexInfo