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

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

-- | Specifies an item and related attribute values to retrieve in a
-- @TransactGetItem@ object.
--
-- /See:/ 'newGet' smart constructor.
data Get = Get'
  { -- | A string that identifies one or more attributes of the specified item to
    -- retrieve from the table. The attributes in the expression must be
    -- separated by commas. If no attribute names are specified, then all
    -- attributes of the specified item are returned. If any of the requested
    -- attributes are not found, they do not appear in the result.
    Get -> Maybe Text
projectionExpression :: Prelude.Maybe Prelude.Text,
    -- | One or more substitution tokens for attribute names in the
    -- ProjectionExpression parameter.
    Get -> Maybe (HashMap Text Text)
expressionAttributeNames :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | A map of attribute names to @AttributeValue@ objects that specifies the
    -- primary key of the item to retrieve.
    Get -> HashMap Text AttributeValue
key :: Prelude.HashMap Prelude.Text AttributeValue,
    -- | The name of the table from which to retrieve the specified item.
    Get -> Text
tableName :: Prelude.Text
  }
  deriving (Get -> Get -> Bool
(Get -> Get -> Bool) -> (Get -> Get -> Bool) -> Eq Get
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Get -> Get -> Bool
$c/= :: Get -> Get -> Bool
== :: Get -> Get -> Bool
$c== :: Get -> Get -> Bool
Prelude.Eq, ReadPrec [Get]
ReadPrec Get
Int -> ReadS Get
ReadS [Get]
(Int -> ReadS Get)
-> ReadS [Get] -> ReadPrec Get -> ReadPrec [Get] -> Read Get
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Get]
$creadListPrec :: ReadPrec [Get]
readPrec :: ReadPrec Get
$creadPrec :: ReadPrec Get
readList :: ReadS [Get]
$creadList :: ReadS [Get]
readsPrec :: Int -> ReadS Get
$creadsPrec :: Int -> ReadS Get
Prelude.Read, Int -> Get -> ShowS
[Get] -> ShowS
Get -> String
(Int -> Get -> ShowS)
-> (Get -> String) -> ([Get] -> ShowS) -> Show Get
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Get] -> ShowS
$cshowList :: [Get] -> ShowS
show :: Get -> String
$cshow :: Get -> String
showsPrec :: Int -> Get -> ShowS
$cshowsPrec :: Int -> Get -> ShowS
Prelude.Show, (forall x. Get -> Rep Get x)
-> (forall x. Rep Get x -> Get) -> Generic Get
forall x. Rep Get x -> Get
forall x. Get -> Rep Get x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Get x -> Get
$cfrom :: forall x. Get -> Rep Get x
Prelude.Generic)

-- |
-- Create a value of 'Get' 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:
--
-- 'projectionExpression', 'get_projectionExpression' - A string that identifies one or more attributes of the specified item to
-- retrieve from the table. The attributes in the expression must be
-- separated by commas. If no attribute names are specified, then all
-- attributes of the specified item are returned. If any of the requested
-- attributes are not found, they do not appear in the result.
--
-- 'expressionAttributeNames', 'get_expressionAttributeNames' - One or more substitution tokens for attribute names in the
-- ProjectionExpression parameter.
--
-- 'key', 'get_key' - A map of attribute names to @AttributeValue@ objects that specifies the
-- primary key of the item to retrieve.
--
-- 'tableName', 'get_tableName' - The name of the table from which to retrieve the specified item.
newGet ::
  -- | 'tableName'
  Prelude.Text ->
  Get
newGet :: Text -> Get
newGet Text
pTableName_ =
  Get' :: Maybe Text
-> Maybe (HashMap Text Text)
-> HashMap Text AttributeValue
-> Text
-> Get
Get'
    { $sel:projectionExpression:Get' :: Maybe Text
projectionExpression = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:expressionAttributeNames:Get' :: Maybe (HashMap Text Text)
expressionAttributeNames = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:key:Get' :: HashMap Text AttributeValue
key = HashMap Text AttributeValue
forall a. Monoid a => a
Prelude.mempty,
      $sel:tableName:Get' :: Text
tableName = Text
pTableName_
    }

-- | A string that identifies one or more attributes of the specified item to
-- retrieve from the table. The attributes in the expression must be
-- separated by commas. If no attribute names are specified, then all
-- attributes of the specified item are returned. If any of the requested
-- attributes are not found, they do not appear in the result.
get_projectionExpression :: Lens.Lens' Get (Prelude.Maybe Prelude.Text)
get_projectionExpression :: (Maybe Text -> f (Maybe Text)) -> Get -> f Get
get_projectionExpression = (Get -> Maybe Text)
-> (Get -> Maybe Text -> Get)
-> Lens Get Get (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Get' {Maybe Text
projectionExpression :: Maybe Text
$sel:projectionExpression:Get' :: Get -> Maybe Text
projectionExpression} -> Maybe Text
projectionExpression) (\s :: Get
s@Get' {} Maybe Text
a -> Get
s {$sel:projectionExpression:Get' :: Maybe Text
projectionExpression = Maybe Text
a} :: Get)

-- | One or more substitution tokens for attribute names in the
-- ProjectionExpression parameter.
get_expressionAttributeNames :: Lens.Lens' Get (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
get_expressionAttributeNames :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> Get -> f Get
get_expressionAttributeNames = (Get -> Maybe (HashMap Text Text))
-> (Get -> Maybe (HashMap Text Text) -> Get)
-> Lens
     Get Get (Maybe (HashMap Text Text)) (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Get' {Maybe (HashMap Text Text)
expressionAttributeNames :: Maybe (HashMap Text Text)
$sel:expressionAttributeNames:Get' :: Get -> Maybe (HashMap Text Text)
expressionAttributeNames} -> Maybe (HashMap Text Text)
expressionAttributeNames) (\s :: Get
s@Get' {} Maybe (HashMap Text Text)
a -> Get
s {$sel:expressionAttributeNames:Get' :: Maybe (HashMap Text Text)
expressionAttributeNames = Maybe (HashMap Text Text)
a} :: Get) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> Get -> f Get)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> Get
-> f Get
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text 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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A map of attribute names to @AttributeValue@ objects that specifies the
-- primary key of the item to retrieve.
get_key :: Lens.Lens' Get (Prelude.HashMap Prelude.Text AttributeValue)
get_key :: (HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> Get -> f Get
get_key = (Get -> HashMap Text AttributeValue)
-> (Get -> HashMap Text AttributeValue -> Get)
-> Lens
     Get Get (HashMap Text AttributeValue) (HashMap Text AttributeValue)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Get' {HashMap Text AttributeValue
key :: HashMap Text AttributeValue
$sel:key:Get' :: Get -> HashMap Text AttributeValue
key} -> HashMap Text AttributeValue
key) (\s :: Get
s@Get' {} HashMap Text AttributeValue
a -> Get
s {$sel:key:Get' :: HashMap Text AttributeValue
key = HashMap Text AttributeValue
a} :: Get) ((HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
 -> Get -> f Get)
-> ((HashMap Text AttributeValue
     -> f (HashMap Text AttributeValue))
    -> HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> (HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> Get
-> f Get
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> HashMap Text AttributeValue -> f (HashMap Text AttributeValue)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the table from which to retrieve the specified item.
get_tableName :: Lens.Lens' Get Prelude.Text
get_tableName :: (Text -> f Text) -> Get -> f Get
get_tableName = (Get -> Text) -> (Get -> Text -> Get) -> Lens Get Get Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Get' {Text
tableName :: Text
$sel:tableName:Get' :: Get -> Text
tableName} -> Text
tableName) (\s :: Get
s@Get' {} Text
a -> Get
s {$sel:tableName:Get' :: Text
tableName = Text
a} :: Get)

instance Prelude.Hashable Get

instance Prelude.NFData Get

instance Core.ToJSON Get where
  toJSON :: Get -> Value
toJSON Get' {Maybe Text
Maybe (HashMap Text Text)
Text
HashMap Text AttributeValue
tableName :: Text
key :: HashMap Text AttributeValue
expressionAttributeNames :: Maybe (HashMap Text Text)
projectionExpression :: Maybe Text
$sel:tableName:Get' :: Get -> Text
$sel:key:Get' :: Get -> HashMap Text AttributeValue
$sel:expressionAttributeNames:Get' :: Get -> Maybe (HashMap Text Text)
$sel:projectionExpression:Get' :: Get -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ProjectionExpression" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
projectionExpression,
            (Text
"ExpressionAttributeNames" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
expressionAttributeNames,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Key" Text -> HashMap Text AttributeValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text AttributeValue
key),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"TableName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
tableName)
          ]
      )