{-# 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.Delete
-- 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.Delete 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 @DeleteItem@ operation.
--
-- /See:/ 'newDelete' smart constructor.
data Delete = Delete'
  { -- | One or more substitution tokens for attribute names in an expression.
    Delete -> Maybe (HashMap Text Text)
expressionAttributeNames :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | One or more values that can be substituted in an expression.
    Delete -> Maybe (HashMap Text AttributeValue)
expressionAttributeValues :: Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue),
    -- | Use @ReturnValuesOnConditionCheckFailure@ to get the item attributes if
    -- the @Delete@ condition fails. For @ReturnValuesOnConditionCheckFailure@,
    -- the valid values are: NONE and ALL_OLD.
    Delete -> Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure :: Prelude.Maybe ReturnValuesOnConditionCheckFailure,
    -- | A condition that must be satisfied in order for a conditional delete to
    -- succeed.
    Delete -> Maybe Text
conditionExpression :: Prelude.Maybe Prelude.Text,
    -- | The primary key of the item to be deleted. Each element consists of an
    -- attribute name and a value for that attribute.
    Delete -> HashMap Text AttributeValue
key :: Prelude.HashMap Prelude.Text AttributeValue,
    -- | Name of the table in which the item to be deleted resides.
    Delete -> Text
tableName :: Prelude.Text
  }
  deriving (Delete -> Delete -> Bool
(Delete -> Delete -> Bool)
-> (Delete -> Delete -> Bool) -> Eq Delete
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Delete -> Delete -> Bool
$c/= :: Delete -> Delete -> Bool
== :: Delete -> Delete -> Bool
$c== :: Delete -> Delete -> Bool
Prelude.Eq, ReadPrec [Delete]
ReadPrec Delete
Int -> ReadS Delete
ReadS [Delete]
(Int -> ReadS Delete)
-> ReadS [Delete]
-> ReadPrec Delete
-> ReadPrec [Delete]
-> Read Delete
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Delete]
$creadListPrec :: ReadPrec [Delete]
readPrec :: ReadPrec Delete
$creadPrec :: ReadPrec Delete
readList :: ReadS [Delete]
$creadList :: ReadS [Delete]
readsPrec :: Int -> ReadS Delete
$creadsPrec :: Int -> ReadS Delete
Prelude.Read, Int -> Delete -> ShowS
[Delete] -> ShowS
Delete -> String
(Int -> Delete -> ShowS)
-> (Delete -> String) -> ([Delete] -> ShowS) -> Show Delete
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Delete] -> ShowS
$cshowList :: [Delete] -> ShowS
show :: Delete -> String
$cshow :: Delete -> String
showsPrec :: Int -> Delete -> ShowS
$cshowsPrec :: Int -> Delete -> ShowS
Prelude.Show, (forall x. Delete -> Rep Delete x)
-> (forall x. Rep Delete x -> Delete) -> Generic Delete
forall x. Rep Delete x -> Delete
forall x. Delete -> Rep Delete x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Delete x -> Delete
$cfrom :: forall x. Delete -> Rep Delete x
Prelude.Generic)

-- |
-- Create a value of 'Delete' 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', 'delete_expressionAttributeNames' - One or more substitution tokens for attribute names in an expression.
--
-- 'expressionAttributeValues', 'delete_expressionAttributeValues' - One or more values that can be substituted in an expression.
--
-- 'returnValuesOnConditionCheckFailure', 'delete_returnValuesOnConditionCheckFailure' - Use @ReturnValuesOnConditionCheckFailure@ to get the item attributes if
-- the @Delete@ condition fails. For @ReturnValuesOnConditionCheckFailure@,
-- the valid values are: NONE and ALL_OLD.
--
-- 'conditionExpression', 'delete_conditionExpression' - A condition that must be satisfied in order for a conditional delete to
-- succeed.
--
-- 'key', 'delete_key' - The primary key of the item to be deleted. Each element consists of an
-- attribute name and a value for that attribute.
--
-- 'tableName', 'delete_tableName' - Name of the table in which the item to be deleted resides.
newDelete ::
  -- | 'tableName'
  Prelude.Text ->
  Delete
newDelete :: Text -> Delete
newDelete Text
pTableName_ =
  Delete' :: Maybe (HashMap Text Text)
-> Maybe (HashMap Text AttributeValue)
-> Maybe ReturnValuesOnConditionCheckFailure
-> Maybe Text
-> HashMap Text AttributeValue
-> Text
-> Delete
Delete'
    { $sel:expressionAttributeNames:Delete' :: Maybe (HashMap Text Text)
expressionAttributeNames = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:expressionAttributeValues:Delete' :: Maybe (HashMap Text AttributeValue)
expressionAttributeValues = Maybe (HashMap Text AttributeValue)
forall a. Maybe a
Prelude.Nothing,
      $sel:returnValuesOnConditionCheckFailure:Delete' :: Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure =
        Maybe ReturnValuesOnConditionCheckFailure
forall a. Maybe a
Prelude.Nothing,
      $sel:conditionExpression:Delete' :: Maybe Text
conditionExpression = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:key:Delete' :: HashMap Text AttributeValue
key = HashMap Text AttributeValue
forall a. Monoid a => a
Prelude.mempty,
      $sel:tableName:Delete' :: Text
tableName = Text
pTableName_
    }

-- | One or more substitution tokens for attribute names in an expression.
delete_expressionAttributeNames :: Lens.Lens' Delete (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
delete_expressionAttributeNames :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> Delete -> f Delete
delete_expressionAttributeNames = (Delete -> Maybe (HashMap Text Text))
-> (Delete -> Maybe (HashMap Text Text) -> Delete)
-> Lens
     Delete
     Delete
     (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 (\Delete' {Maybe (HashMap Text Text)
expressionAttributeNames :: Maybe (HashMap Text Text)
$sel:expressionAttributeNames:Delete' :: Delete -> Maybe (HashMap Text Text)
expressionAttributeNames} -> Maybe (HashMap Text Text)
expressionAttributeNames) (\s :: Delete
s@Delete' {} Maybe (HashMap Text Text)
a -> Delete
s {$sel:expressionAttributeNames:Delete' :: Maybe (HashMap Text Text)
expressionAttributeNames = Maybe (HashMap Text Text)
a} :: Delete) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> Delete -> f Delete)
-> ((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)))
-> Delete
-> f Delete
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.
delete_expressionAttributeValues :: Lens.Lens' Delete (Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue))
delete_expressionAttributeValues :: (Maybe (HashMap Text AttributeValue)
 -> f (Maybe (HashMap Text AttributeValue)))
-> Delete -> f Delete
delete_expressionAttributeValues = (Delete -> Maybe (HashMap Text AttributeValue))
-> (Delete -> Maybe (HashMap Text AttributeValue) -> Delete)
-> Lens
     Delete
     Delete
     (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 (\Delete' {Maybe (HashMap Text AttributeValue)
expressionAttributeValues :: Maybe (HashMap Text AttributeValue)
$sel:expressionAttributeValues:Delete' :: Delete -> Maybe (HashMap Text AttributeValue)
expressionAttributeValues} -> Maybe (HashMap Text AttributeValue)
expressionAttributeValues) (\s :: Delete
s@Delete' {} Maybe (HashMap Text AttributeValue)
a -> Delete
s {$sel:expressionAttributeValues:Delete' :: Maybe (HashMap Text AttributeValue)
expressionAttributeValues = Maybe (HashMap Text AttributeValue)
a} :: Delete) ((Maybe (HashMap Text AttributeValue)
  -> f (Maybe (HashMap Text AttributeValue)))
 -> Delete -> f Delete)
-> ((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)))
-> Delete
-> f Delete
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 @Delete@ condition fails. For @ReturnValuesOnConditionCheckFailure@,
-- the valid values are: NONE and ALL_OLD.
delete_returnValuesOnConditionCheckFailure :: Lens.Lens' Delete (Prelude.Maybe ReturnValuesOnConditionCheckFailure)
delete_returnValuesOnConditionCheckFailure :: (Maybe ReturnValuesOnConditionCheckFailure
 -> f (Maybe ReturnValuesOnConditionCheckFailure))
-> Delete -> f Delete
delete_returnValuesOnConditionCheckFailure = (Delete -> Maybe ReturnValuesOnConditionCheckFailure)
-> (Delete -> Maybe ReturnValuesOnConditionCheckFailure -> Delete)
-> Lens
     Delete
     Delete
     (Maybe ReturnValuesOnConditionCheckFailure)
     (Maybe ReturnValuesOnConditionCheckFailure)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Delete' {Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure :: Maybe ReturnValuesOnConditionCheckFailure
$sel:returnValuesOnConditionCheckFailure:Delete' :: Delete -> Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure} -> Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure) (\s :: Delete
s@Delete' {} Maybe ReturnValuesOnConditionCheckFailure
a -> Delete
s {$sel:returnValuesOnConditionCheckFailure:Delete' :: Maybe ReturnValuesOnConditionCheckFailure
returnValuesOnConditionCheckFailure = Maybe ReturnValuesOnConditionCheckFailure
a} :: Delete)

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

-- | The primary key of the item to be deleted. Each element consists of an
-- attribute name and a value for that attribute.
delete_key :: Lens.Lens' Delete (Prelude.HashMap Prelude.Text AttributeValue)
delete_key :: (HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> Delete -> f Delete
delete_key = (Delete -> HashMap Text AttributeValue)
-> (Delete -> HashMap Text AttributeValue -> Delete)
-> Lens
     Delete
     Delete
     (HashMap Text AttributeValue)
     (HashMap Text AttributeValue)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Delete' {HashMap Text AttributeValue
key :: HashMap Text AttributeValue
$sel:key:Delete' :: Delete -> HashMap Text AttributeValue
key} -> HashMap Text AttributeValue
key) (\s :: Delete
s@Delete' {} HashMap Text AttributeValue
a -> Delete
s {$sel:key:Delete' :: HashMap Text AttributeValue
key = HashMap Text AttributeValue
a} :: Delete) ((HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
 -> Delete -> f Delete)
-> ((HashMap Text AttributeValue
     -> f (HashMap Text AttributeValue))
    -> HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> (HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> Delete
-> f Delete
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 the item to be deleted resides.
delete_tableName :: Lens.Lens' Delete Prelude.Text
delete_tableName :: (Text -> f Text) -> Delete -> f Delete
delete_tableName = (Delete -> Text)
-> (Delete -> Text -> Delete) -> Lens Delete Delete Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Delete' {Text
tableName :: Text
$sel:tableName:Delete' :: Delete -> Text
tableName} -> Text
tableName) (\s :: Delete
s@Delete' {} Text
a -> Delete
s {$sel:tableName:Delete' :: Text
tableName = Text
a} :: Delete)

instance Prelude.Hashable Delete

instance Prelude.NFData Delete

instance Core.ToJSON Delete where
  toJSON :: Delete -> Value
toJSON Delete' {Maybe Text
Maybe (HashMap Text Text)
Maybe (HashMap Text AttributeValue)
Maybe ReturnValuesOnConditionCheckFailure
Text
HashMap Text AttributeValue
tableName :: Text
key :: HashMap Text AttributeValue
conditionExpression :: Maybe Text
returnValuesOnConditionCheckFailure :: Maybe ReturnValuesOnConditionCheckFailure
expressionAttributeValues :: Maybe (HashMap Text AttributeValue)
expressionAttributeNames :: Maybe (HashMap Text Text)
$sel:tableName:Delete' :: Delete -> Text
$sel:key:Delete' :: Delete -> HashMap Text AttributeValue
$sel:conditionExpression:Delete' :: Delete -> Maybe Text
$sel:returnValuesOnConditionCheckFailure:Delete' :: Delete -> Maybe ReturnValuesOnConditionCheckFailure
$sel:expressionAttributeValues:Delete' :: Delete -> Maybe (HashMap Text AttributeValue)
$sel:expressionAttributeNames:Delete' :: Delete -> 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
"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)
          ]
      )