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

import qualified Amazonka.Core as Core
import Amazonka.DynamoDB.Types.ProjectionType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | 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.
--
-- /See:/ 'newProjection' smart constructor.
data Projection = Projection'
  { -- | The set of attributes that are projected into the index:
    --
    -- -   @KEYS_ONLY@ - Only the index and primary keys are projected into the
    --     index.
    --
    -- -   @INCLUDE@ - In addition to the attributes described in @KEYS_ONLY@,
    --     the secondary index will include other non-key attributes that you
    --     specify.
    --
    -- -   @ALL@ - All of the table attributes are projected into the index.
    Projection -> Maybe ProjectionType
projectionType :: Prelude.Maybe ProjectionType,
    -- | Represents the non-key attribute names which will be projected into the
    -- index.
    --
    -- For local secondary indexes, the total count of @NonKeyAttributes@
    -- summed across all of the local secondary indexes, must not exceed 20. If
    -- you project the same attribute into two different indexes, this counts
    -- as two distinct attributes when determining the total.
    Projection -> Maybe (NonEmpty Text)
nonKeyAttributes :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text)
  }
  deriving (Projection -> Projection -> Bool
(Projection -> Projection -> Bool)
-> (Projection -> Projection -> Bool) -> Eq Projection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Projection -> Projection -> Bool
$c/= :: Projection -> Projection -> Bool
== :: Projection -> Projection -> Bool
$c== :: Projection -> Projection -> Bool
Prelude.Eq, ReadPrec [Projection]
ReadPrec Projection
Int -> ReadS Projection
ReadS [Projection]
(Int -> ReadS Projection)
-> ReadS [Projection]
-> ReadPrec Projection
-> ReadPrec [Projection]
-> Read Projection
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Projection]
$creadListPrec :: ReadPrec [Projection]
readPrec :: ReadPrec Projection
$creadPrec :: ReadPrec Projection
readList :: ReadS [Projection]
$creadList :: ReadS [Projection]
readsPrec :: Int -> ReadS Projection
$creadsPrec :: Int -> ReadS Projection
Prelude.Read, Int -> Projection -> ShowS
[Projection] -> ShowS
Projection -> String
(Int -> Projection -> ShowS)
-> (Projection -> String)
-> ([Projection] -> ShowS)
-> Show Projection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Projection] -> ShowS
$cshowList :: [Projection] -> ShowS
show :: Projection -> String
$cshow :: Projection -> String
showsPrec :: Int -> Projection -> ShowS
$cshowsPrec :: Int -> Projection -> ShowS
Prelude.Show, (forall x. Projection -> Rep Projection x)
-> (forall x. Rep Projection x -> Projection) -> Generic Projection
forall x. Rep Projection x -> Projection
forall x. Projection -> Rep Projection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Projection x -> Projection
$cfrom :: forall x. Projection -> Rep Projection x
Prelude.Generic)

-- |
-- Create a value of 'Projection' 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:
--
-- 'projectionType', 'projection_projectionType' - The set of attributes that are projected into the index:
--
-- -   @KEYS_ONLY@ - Only the index and primary keys are projected into the
--     index.
--
-- -   @INCLUDE@ - In addition to the attributes described in @KEYS_ONLY@,
--     the secondary index will include other non-key attributes that you
--     specify.
--
-- -   @ALL@ - All of the table attributes are projected into the index.
--
-- 'nonKeyAttributes', 'projection_nonKeyAttributes' - Represents the non-key attribute names which will be projected into the
-- index.
--
-- For local secondary indexes, the total count of @NonKeyAttributes@
-- summed across all of the local secondary indexes, must not exceed 20. If
-- you project the same attribute into two different indexes, this counts
-- as two distinct attributes when determining the total.
newProjection ::
  Projection
newProjection :: Projection
newProjection =
  Projection' :: Maybe ProjectionType -> Maybe (NonEmpty Text) -> Projection
Projection'
    { $sel:projectionType:Projection' :: Maybe ProjectionType
projectionType = Maybe ProjectionType
forall a. Maybe a
Prelude.Nothing,
      $sel:nonKeyAttributes:Projection' :: Maybe (NonEmpty Text)
nonKeyAttributes = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing
    }

-- | The set of attributes that are projected into the index:
--
-- -   @KEYS_ONLY@ - Only the index and primary keys are projected into the
--     index.
--
-- -   @INCLUDE@ - In addition to the attributes described in @KEYS_ONLY@,
--     the secondary index will include other non-key attributes that you
--     specify.
--
-- -   @ALL@ - All of the table attributes are projected into the index.
projection_projectionType :: Lens.Lens' Projection (Prelude.Maybe ProjectionType)
projection_projectionType :: (Maybe ProjectionType -> f (Maybe ProjectionType))
-> Projection -> f Projection
projection_projectionType = (Projection -> Maybe ProjectionType)
-> (Projection -> Maybe ProjectionType -> Projection)
-> Lens
     Projection Projection (Maybe ProjectionType) (Maybe ProjectionType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Projection' {Maybe ProjectionType
projectionType :: Maybe ProjectionType
$sel:projectionType:Projection' :: Projection -> Maybe ProjectionType
projectionType} -> Maybe ProjectionType
projectionType) (\s :: Projection
s@Projection' {} Maybe ProjectionType
a -> Projection
s {$sel:projectionType:Projection' :: Maybe ProjectionType
projectionType = Maybe ProjectionType
a} :: Projection)

-- | Represents the non-key attribute names which will be projected into the
-- index.
--
-- For local secondary indexes, the total count of @NonKeyAttributes@
-- summed across all of the local secondary indexes, must not exceed 20. If
-- you project the same attribute into two different indexes, this counts
-- as two distinct attributes when determining the total.
projection_nonKeyAttributes :: Lens.Lens' Projection (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
projection_nonKeyAttributes :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> Projection -> f Projection
projection_nonKeyAttributes = (Projection -> Maybe (NonEmpty Text))
-> (Projection -> Maybe (NonEmpty Text) -> Projection)
-> Lens
     Projection
     Projection
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Projection' {Maybe (NonEmpty Text)
nonKeyAttributes :: Maybe (NonEmpty Text)
$sel:nonKeyAttributes:Projection' :: Projection -> Maybe (NonEmpty Text)
nonKeyAttributes} -> Maybe (NonEmpty Text)
nonKeyAttributes) (\s :: Projection
s@Projection' {} Maybe (NonEmpty Text)
a -> Projection
s {$sel:nonKeyAttributes:Projection' :: Maybe (NonEmpty Text)
nonKeyAttributes = Maybe (NonEmpty Text)
a} :: Projection) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> Projection -> f Projection)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> Projection
-> f Projection
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
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 Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable Projection

instance Prelude.NFData Projection

instance Core.ToJSON Projection where
  toJSON :: Projection -> Value
toJSON Projection' {Maybe (NonEmpty Text)
Maybe ProjectionType
nonKeyAttributes :: Maybe (NonEmpty Text)
projectionType :: Maybe ProjectionType
$sel:nonKeyAttributes:Projection' :: Projection -> Maybe (NonEmpty Text)
$sel:projectionType:Projection' :: Projection -> Maybe ProjectionType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ProjectionType" Text -> ProjectionType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ProjectionType -> Pair) -> Maybe ProjectionType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ProjectionType
projectionType,
            (Text
"NonKeyAttributes" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
nonKeyAttributes
          ]
      )