{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.DynamoDB.Types.Put where

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

-- | Represents a request to perform a @PutItem@ operation.
--
-- /See:/ 'newPut' smart constructor.
data Put = Put'
  { -- | A condition that must be satisfied in order for a conditional update to
    -- succeed.
    Put -> Maybe Text
conditionExpression :: Prelude.Maybe Prelude.Text,
    -- | 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 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
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]
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
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. 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:
--
-- 'conditionExpression', 'put_conditionExpression' - A condition that must be satisfied in order for a conditional update to
-- succeed.
--
-- '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.
--
-- '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'
    { $sel:conditionExpression:Put' :: Maybe Text
conditionExpression = forall a. Maybe a
Prelude.Nothing,
      $sel:expressionAttributeNames:Put' :: Maybe (HashMap Text Text)
expressionAttributeNames = forall a. Maybe a
Prelude.Nothing,
      $sel:expressionAttributeValues:Put' :: Maybe (HashMap Text AttributeValue)
expressionAttributeValues = forall a. Maybe a
Prelude.Nothing,
      $sel:returnValuesOnConditionCheckFailure:Put' :: Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure =
        forall a. Maybe a
Prelude.Nothing,
      $sel:item:Put' :: HashMap Text AttributeValue
item = forall a. Monoid a => a
Prelude.mempty,
      $sel:tableName:Put' :: Text
tableName = Text
pTableName_
    }

-- | 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 :: Lens' Put (Maybe Text)
put_conditionExpression = 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)

-- | 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 :: Lens' Put (Maybe (HashMap Text Text))
put_expressionAttributeNames = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' Put (Maybe (HashMap Text AttributeValue))
put_expressionAttributeValues = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' Put (Maybe ReturnValuesOnConditionCheckFailure)
put_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 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 :: Lens' Put (HashMap Text AttributeValue)
put_item = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 :: Lens' Put Text
put_tableName = 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 where
  hashWithSalt :: Int -> Put -> Int
hashWithSalt Int
_salt Put' {Maybe Text
Maybe (HashMap Text Text)
Maybe (HashMap Text AttributeValue)
Maybe ReturnValuesOnConditionCheckFailure
Text
HashMap Text AttributeValue
tableName :: Text
item :: HashMap Text AttributeValue
returnValuesOnConditionCheckFailure :: Maybe ReturnValuesOnConditionCheckFailure
expressionAttributeValues :: Maybe (HashMap Text AttributeValue)
expressionAttributeNames :: Maybe (HashMap Text Text)
conditionExpression :: Maybe Text
$sel:tableName:Put' :: Put -> Text
$sel:item:Put' :: Put -> HashMap Text AttributeValue
$sel:returnValuesOnConditionCheckFailure:Put' :: Put -> Maybe ReturnValuesOnConditionCheckFailure
$sel:expressionAttributeValues:Put' :: Put -> Maybe (HashMap Text AttributeValue)
$sel:expressionAttributeNames:Put' :: Put -> Maybe (HashMap Text Text)
$sel:conditionExpression:Put' :: Put -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
conditionExpression
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
expressionAttributeNames
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text AttributeValue)
expressionAttributeValues
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` HashMap Text AttributeValue
item
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
tableName

instance Prelude.NFData Put where
  rnf :: Put -> ()
rnf Put' {Maybe Text
Maybe (HashMap Text Text)
Maybe (HashMap Text AttributeValue)
Maybe ReturnValuesOnConditionCheckFailure
Text
HashMap Text AttributeValue
tableName :: Text
item :: HashMap Text AttributeValue
returnValuesOnConditionCheckFailure :: Maybe ReturnValuesOnConditionCheckFailure
expressionAttributeValues :: Maybe (HashMap Text AttributeValue)
expressionAttributeNames :: Maybe (HashMap Text Text)
conditionExpression :: Maybe Text
$sel:tableName:Put' :: Put -> Text
$sel:item:Put' :: Put -> HashMap Text AttributeValue
$sel:returnValuesOnConditionCheckFailure:Put' :: Put -> Maybe ReturnValuesOnConditionCheckFailure
$sel:expressionAttributeValues:Put' :: Put -> Maybe (HashMap Text AttributeValue)
$sel:expressionAttributeNames:Put' :: Put -> Maybe (HashMap Text Text)
$sel:conditionExpression:Put' :: Put -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
conditionExpression
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
expressionAttributeNames
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text AttributeValue)
expressionAttributeValues
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf HashMap Text AttributeValue
item
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
tableName

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