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

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

-- | Represents a request to perform a @PutItem@ operation.
--
-- /See:/ 'newPut' smart constructor.
data Put = Put'
  { -- | One or more substitution tokens for attribute names in an expression.
    Put -> Maybe (HashMap Text Text)
expressionAttributeNames :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | One or more values that can be substituted in an expression.
    Put -> Maybe (HashMap Text AttributeValue)
expressionAttributeValues :: Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue),
    -- | Use @ReturnValuesOnConditionCheckFailure@ to get the item attributes if
    -- the @Put@ condition fails. For @ReturnValuesOnConditionCheckFailure@,
    -- the valid values are: NONE and ALL_OLD.
    Put -> Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure :: Prelude.Maybe ReturnValuesOnConditionCheckFailure,
    -- | A condition that must be satisfied in order for a conditional update to
    -- succeed.
    Put -> Maybe Text
conditionExpression :: Prelude.Maybe Prelude.Text,
    -- | A map of attribute name to attribute values, representing the primary
    -- key of the item to be written by @PutItem@. All of the table\'s primary
    -- key attributes must be specified, and their data types must match those
    -- of the table\'s key schema. If any attributes are present in the item
    -- that are part of an index key schema for the table, their types must
    -- match the index key schema.
    Put -> HashMap Text AttributeValue
item :: Prelude.HashMap Prelude.Text AttributeValue,
    -- | Name of the table in which to write the item.
    Put -> Text
tableName :: Prelude.Text
  }
  deriving (Put -> Put -> Bool
(Put -> Put -> Bool) -> (Put -> Put -> Bool) -> Eq Put
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Put -> Put -> Bool
$c/= :: Put -> Put -> Bool
== :: Put -> Put -> Bool
$c== :: Put -> Put -> Bool
Prelude.Eq, ReadPrec [Put]
ReadPrec Put
Int -> ReadS Put
ReadS [Put]
(Int -> ReadS Put)
-> ReadS [Put] -> ReadPrec Put -> ReadPrec [Put] -> Read Put
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Put]
$creadListPrec :: ReadPrec [Put]
readPrec :: ReadPrec Put
$creadPrec :: ReadPrec Put
readList :: ReadS [Put]
$creadList :: ReadS [Put]
readsPrec :: Int -> ReadS Put
$creadsPrec :: Int -> ReadS Put
Prelude.Read, Int -> Put -> ShowS
[Put] -> ShowS
Put -> String
(Int -> Put -> ShowS)
-> (Put -> String) -> ([Put] -> ShowS) -> Show Put
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Put] -> ShowS
$cshowList :: [Put] -> ShowS
show :: Put -> String
$cshow :: Put -> String
showsPrec :: Int -> Put -> ShowS
$cshowsPrec :: Int -> Put -> ShowS
Prelude.Show, (forall x. Put -> Rep Put x)
-> (forall x. Rep Put x -> Put) -> Generic Put
forall x. Rep Put x -> Put
forall x. Put -> Rep Put x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Put x -> Put
$cfrom :: forall x. Put -> Rep Put x
Prelude.Generic)

-- |
-- Create a value of 'Put' 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:
--
-- 'expressionAttributeNames', 'put_expressionAttributeNames' - One or more substitution tokens for attribute names in an expression.
--
-- 'expressionAttributeValues', 'put_expressionAttributeValues' - One or more values that can be substituted in an expression.
--
-- 'returnValuesOnConditionCheckFailure', 'put_returnValuesOnConditionCheckFailure' - Use @ReturnValuesOnConditionCheckFailure@ to get the item attributes if
-- the @Put@ condition fails. For @ReturnValuesOnConditionCheckFailure@,
-- the valid values are: NONE and ALL_OLD.
--
-- 'conditionExpression', 'put_conditionExpression' - A condition that must be satisfied in order for a conditional update to
-- succeed.
--
-- 'item', 'put_item' - A map of attribute name to attribute values, representing the primary
-- key of the item to be written by @PutItem@. All of the table\'s primary
-- key attributes must be specified, and their data types must match those
-- of the table\'s key schema. If any attributes are present in the item
-- that are part of an index key schema for the table, their types must
-- match the index key schema.
--
-- 'tableName', 'put_tableName' - Name of the table in which to write the item.
newPut ::
  -- | 'tableName'
  Prelude.Text ->
  Put
newPut :: Text -> Put
newPut Text
pTableName_ =
  Put' :: Maybe (HashMap Text Text)
-> Maybe (HashMap Text AttributeValue)
-> Maybe ReturnValuesOnConditionCheckFailure
-> Maybe Text
-> HashMap Text AttributeValue
-> Text
-> Put
Put'
    { $sel:expressionAttributeNames:Put' :: Maybe (HashMap Text Text)
expressionAttributeNames = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:expressionAttributeValues:Put' :: Maybe (HashMap Text AttributeValue)
expressionAttributeValues = Maybe (HashMap Text AttributeValue)
forall a. Maybe a
Prelude.Nothing,
      $sel:returnValuesOnConditionCheckFailure:Put' :: Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure =
        Maybe ReturnValuesOnConditionCheckFailure
forall a. Maybe a
Prelude.Nothing,
      $sel:conditionExpression:Put' :: Maybe Text
conditionExpression = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:item:Put' :: HashMap Text AttributeValue
item = HashMap Text AttributeValue
forall a. Monoid a => a
Prelude.mempty,
      $sel:tableName:Put' :: Text
tableName = Text
pTableName_
    }

-- | One or more substitution tokens for attribute names in an expression.
put_expressionAttributeNames :: Lens.Lens' Put (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
put_expressionAttributeNames :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> Put -> f Put
put_expressionAttributeNames = (Put -> Maybe (HashMap Text Text))
-> (Put -> Maybe (HashMap Text Text) -> Put)
-> Lens
     Put Put (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 (\Put' {Maybe (HashMap Text Text)
expressionAttributeNames :: Maybe (HashMap Text Text)
$sel:expressionAttributeNames:Put' :: Put -> Maybe (HashMap Text Text)
expressionAttributeNames} -> Maybe (HashMap Text Text)
expressionAttributeNames) (\s :: Put
s@Put' {} Maybe (HashMap Text Text)
a -> Put
s {$sel:expressionAttributeNames:Put' :: Maybe (HashMap Text Text)
expressionAttributeNames = Maybe (HashMap Text Text)
a} :: Put) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> Put -> f Put)
-> ((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)))
-> Put
-> f Put
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

-- | One or more values that can be substituted in an expression.
put_expressionAttributeValues :: Lens.Lens' Put (Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue))
put_expressionAttributeValues :: (Maybe (HashMap Text AttributeValue)
 -> f (Maybe (HashMap Text AttributeValue)))
-> Put -> f Put
put_expressionAttributeValues = (Put -> Maybe (HashMap Text AttributeValue))
-> (Put -> Maybe (HashMap Text AttributeValue) -> Put)
-> Lens
     Put
     Put
     (Maybe (HashMap Text AttributeValue))
     (Maybe (HashMap Text AttributeValue))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Put' {Maybe (HashMap Text AttributeValue)
expressionAttributeValues :: Maybe (HashMap Text AttributeValue)
$sel:expressionAttributeValues:Put' :: Put -> Maybe (HashMap Text AttributeValue)
expressionAttributeValues} -> Maybe (HashMap Text AttributeValue)
expressionAttributeValues) (\s :: Put
s@Put' {} Maybe (HashMap Text AttributeValue)
a -> Put
s {$sel:expressionAttributeValues:Put' :: Maybe (HashMap Text AttributeValue)
expressionAttributeValues = Maybe (HashMap Text AttributeValue)
a} :: Put) ((Maybe (HashMap Text AttributeValue)
  -> f (Maybe (HashMap Text AttributeValue)))
 -> Put -> f Put)
-> ((Maybe (HashMap Text AttributeValue)
     -> f (Maybe (HashMap Text AttributeValue)))
    -> Maybe (HashMap Text AttributeValue)
    -> f (Maybe (HashMap Text AttributeValue)))
-> (Maybe (HashMap Text AttributeValue)
    -> f (Maybe (HashMap Text AttributeValue)))
-> Put
-> f Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text AttributeValue)
  (HashMap Text AttributeValue)
  (HashMap Text AttributeValue)
  (HashMap Text AttributeValue)
-> Iso
     (Maybe (HashMap Text AttributeValue))
     (Maybe (HashMap Text AttributeValue))
     (Maybe (HashMap Text AttributeValue))
     (Maybe (HashMap Text AttributeValue))
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 AttributeValue)
  (HashMap Text AttributeValue)
  (HashMap Text AttributeValue)
  (HashMap Text AttributeValue)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Use @ReturnValuesOnConditionCheckFailure@ to get the item attributes if
-- the @Put@ condition fails. For @ReturnValuesOnConditionCheckFailure@,
-- the valid values are: NONE and ALL_OLD.
put_returnValuesOnConditionCheckFailure :: Lens.Lens' Put (Prelude.Maybe ReturnValuesOnConditionCheckFailure)
put_returnValuesOnConditionCheckFailure :: (Maybe ReturnValuesOnConditionCheckFailure
 -> f (Maybe ReturnValuesOnConditionCheckFailure))
-> Put -> f Put
put_returnValuesOnConditionCheckFailure = (Put -> Maybe ReturnValuesOnConditionCheckFailure)
-> (Put -> Maybe ReturnValuesOnConditionCheckFailure -> Put)
-> Lens
     Put
     Put
     (Maybe ReturnValuesOnConditionCheckFailure)
     (Maybe ReturnValuesOnConditionCheckFailure)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Put' {Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure :: Maybe ReturnValuesOnConditionCheckFailure
$sel:returnValuesOnConditionCheckFailure:Put' :: Put -> Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure} -> Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure) (\s :: Put
s@Put' {} Maybe ReturnValuesOnConditionCheckFailure
a -> Put
s {$sel:returnValuesOnConditionCheckFailure:Put' :: Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure = Maybe ReturnValuesOnConditionCheckFailure
a} :: Put)

-- | A condition that must be satisfied in order for a conditional update to
-- succeed.
put_conditionExpression :: Lens.Lens' Put (Prelude.Maybe Prelude.Text)
put_conditionExpression :: (Maybe Text -> f (Maybe Text)) -> Put -> f Put
put_conditionExpression = (Put -> Maybe Text)
-> (Put -> Maybe Text -> Put)
-> Lens Put Put (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Put' {Maybe Text
conditionExpression :: Maybe Text
$sel:conditionExpression:Put' :: Put -> Maybe Text
conditionExpression} -> Maybe Text
conditionExpression) (\s :: Put
s@Put' {} Maybe Text
a -> Put
s {$sel:conditionExpression:Put' :: Maybe Text
conditionExpression = Maybe Text
a} :: Put)

-- | A map of attribute name to attribute values, representing the primary
-- key of the item to be written by @PutItem@. All of the table\'s primary
-- key attributes must be specified, and their data types must match those
-- of the table\'s key schema. If any attributes are present in the item
-- that are part of an index key schema for the table, their types must
-- match the index key schema.
put_item :: Lens.Lens' Put (Prelude.HashMap Prelude.Text AttributeValue)
put_item :: (HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> Put -> f Put
put_item = (Put -> HashMap Text AttributeValue)
-> (Put -> HashMap Text AttributeValue -> Put)
-> Lens
     Put Put (HashMap Text AttributeValue) (HashMap Text AttributeValue)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Put' {HashMap Text AttributeValue
item :: HashMap Text AttributeValue
$sel:item:Put' :: Put -> HashMap Text AttributeValue
item} -> HashMap Text AttributeValue
item) (\s :: Put
s@Put' {} HashMap Text AttributeValue
a -> Put
s {$sel:item:Put' :: HashMap Text AttributeValue
item = HashMap Text AttributeValue
a} :: Put) ((HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
 -> Put -> f Put)
-> ((HashMap Text AttributeValue
     -> f (HashMap Text AttributeValue))
    -> HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> (HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> Put
-> f Put
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

-- | Name of the table in which to write the item.
put_tableName :: Lens.Lens' Put Prelude.Text
put_tableName :: (Text -> f Text) -> Put -> f Put
put_tableName = (Put -> Text) -> (Put -> Text -> Put) -> Lens Put Put Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Put' {Text
tableName :: Text
$sel:tableName:Put' :: Put -> Text
tableName} -> Text
tableName) (\s :: Put
s@Put' {} Text
a -> Put
s {$sel:tableName:Put' :: Text
tableName = Text
a} :: Put)

instance Prelude.Hashable Put

instance Prelude.NFData Put

instance Core.ToJSON Put where
  toJSON :: Put -> Value
toJSON Put' {Maybe Text
Maybe (HashMap Text Text)
Maybe (HashMap Text AttributeValue)
Maybe ReturnValuesOnConditionCheckFailure
Text
HashMap Text AttributeValue
tableName :: Text
item :: HashMap Text AttributeValue
conditionExpression :: Maybe Text
returnValuesOnConditionCheckFailure :: Maybe ReturnValuesOnConditionCheckFailure
expressionAttributeValues :: Maybe (HashMap Text AttributeValue)
expressionAttributeNames :: Maybe (HashMap Text Text)
$sel:tableName:Put' :: Put -> Text
$sel:item:Put' :: Put -> HashMap Text AttributeValue
$sel:conditionExpression:Put' :: Put -> Maybe Text
$sel:returnValuesOnConditionCheckFailure:Put' :: Put -> Maybe ReturnValuesOnConditionCheckFailure
$sel:expressionAttributeValues:Put' :: Put -> Maybe (HashMap Text AttributeValue)
$sel:expressionAttributeNames:Put' :: Put -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (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,
            (Text
"ExpressionAttributeValues" Text -> HashMap Text AttributeValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (HashMap Text AttributeValue -> Pair)
-> Maybe (HashMap Text AttributeValue) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text AttributeValue)
expressionAttributeValues,
            (Text
"ReturnValuesOnConditionCheckFailure" Text -> ReturnValuesOnConditionCheckFailure -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ReturnValuesOnConditionCheckFailure -> Pair)
-> Maybe ReturnValuesOnConditionCheckFailure -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure,
            (Text
"ConditionExpression" 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
conditionExpression,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Item" Text -> HashMap Text AttributeValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text AttributeValue
item),
            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)
          ]
      )