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

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

-- | Represents a request to perform a @DeleteItem@ operation on an item.
--
-- /See:/ 'newDeleteRequest' smart constructor.
data DeleteRequest = DeleteRequest'
  { -- | A map of attribute name to attribute values, representing the primary
    -- key of the item to delete. All of the table\'s primary key attributes
    -- must be specified, and their data types must match those of the table\'s
    -- key schema.
    DeleteRequest -> HashMap Text AttributeValue
key :: Prelude.HashMap Prelude.Text AttributeValue
  }
  deriving (DeleteRequest -> DeleteRequest -> Bool
(DeleteRequest -> DeleteRequest -> Bool)
-> (DeleteRequest -> DeleteRequest -> Bool) -> Eq DeleteRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteRequest -> DeleteRequest -> Bool
$c/= :: DeleteRequest -> DeleteRequest -> Bool
== :: DeleteRequest -> DeleteRequest -> Bool
$c== :: DeleteRequest -> DeleteRequest -> Bool
Prelude.Eq, ReadPrec [DeleteRequest]
ReadPrec DeleteRequest
Int -> ReadS DeleteRequest
ReadS [DeleteRequest]
(Int -> ReadS DeleteRequest)
-> ReadS [DeleteRequest]
-> ReadPrec DeleteRequest
-> ReadPrec [DeleteRequest]
-> Read DeleteRequest
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteRequest]
$creadListPrec :: ReadPrec [DeleteRequest]
readPrec :: ReadPrec DeleteRequest
$creadPrec :: ReadPrec DeleteRequest
readList :: ReadS [DeleteRequest]
$creadList :: ReadS [DeleteRequest]
readsPrec :: Int -> ReadS DeleteRequest
$creadsPrec :: Int -> ReadS DeleteRequest
Prelude.Read, Int -> DeleteRequest -> ShowS
[DeleteRequest] -> ShowS
DeleteRequest -> String
(Int -> DeleteRequest -> ShowS)
-> (DeleteRequest -> String)
-> ([DeleteRequest] -> ShowS)
-> Show DeleteRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteRequest] -> ShowS
$cshowList :: [DeleteRequest] -> ShowS
show :: DeleteRequest -> String
$cshow :: DeleteRequest -> String
showsPrec :: Int -> DeleteRequest -> ShowS
$cshowsPrec :: Int -> DeleteRequest -> ShowS
Prelude.Show, (forall x. DeleteRequest -> Rep DeleteRequest x)
-> (forall x. Rep DeleteRequest x -> DeleteRequest)
-> Generic DeleteRequest
forall x. Rep DeleteRequest x -> DeleteRequest
forall x. DeleteRequest -> Rep DeleteRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteRequest x -> DeleteRequest
$cfrom :: forall x. DeleteRequest -> Rep DeleteRequest x
Prelude.Generic)

-- |
-- Create a value of 'DeleteRequest' 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:
--
-- 'key', 'deleteRequest_key' - A map of attribute name to attribute values, representing the primary
-- key of the item to delete. All of the table\'s primary key attributes
-- must be specified, and their data types must match those of the table\'s
-- key schema.
newDeleteRequest ::
  DeleteRequest
newDeleteRequest :: DeleteRequest
newDeleteRequest =
  DeleteRequest' :: HashMap Text AttributeValue -> DeleteRequest
DeleteRequest' {$sel:key:DeleteRequest' :: HashMap Text AttributeValue
key = HashMap Text AttributeValue
forall a. Monoid a => a
Prelude.mempty}

-- | A map of attribute name to attribute values, representing the primary
-- key of the item to delete. All of the table\'s primary key attributes
-- must be specified, and their data types must match those of the table\'s
-- key schema.
deleteRequest_key :: Lens.Lens' DeleteRequest (Prelude.HashMap Prelude.Text AttributeValue)
deleteRequest_key :: (HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> DeleteRequest -> f DeleteRequest
deleteRequest_key = (DeleteRequest -> HashMap Text AttributeValue)
-> (DeleteRequest -> HashMap Text AttributeValue -> DeleteRequest)
-> Lens
     DeleteRequest
     DeleteRequest
     (HashMap Text AttributeValue)
     (HashMap Text AttributeValue)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteRequest' {HashMap Text AttributeValue
key :: HashMap Text AttributeValue
$sel:key:DeleteRequest' :: DeleteRequest -> HashMap Text AttributeValue
key} -> HashMap Text AttributeValue
key) (\s :: DeleteRequest
s@DeleteRequest' {} HashMap Text AttributeValue
a -> DeleteRequest
s {$sel:key:DeleteRequest' :: HashMap Text AttributeValue
key = HashMap Text AttributeValue
a} :: DeleteRequest) ((HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
 -> DeleteRequest -> f DeleteRequest)
-> ((HashMap Text AttributeValue
     -> f (HashMap Text AttributeValue))
    -> HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> (HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> DeleteRequest
-> f DeleteRequest
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

instance Core.FromJSON DeleteRequest where
  parseJSON :: Value -> Parser DeleteRequest
parseJSON =
    String
-> (Object -> Parser DeleteRequest)
-> Value
-> Parser DeleteRequest
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DeleteRequest"
      ( \Object
x ->
          HashMap Text AttributeValue -> DeleteRequest
DeleteRequest'
            (HashMap Text AttributeValue -> DeleteRequest)
-> Parser (HashMap Text AttributeValue) -> Parser DeleteRequest
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (HashMap Text AttributeValue))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Key" Parser (Maybe (HashMap Text AttributeValue))
-> HashMap Text AttributeValue
-> Parser (HashMap Text AttributeValue)
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= HashMap Text AttributeValue
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable DeleteRequest

instance Prelude.NFData DeleteRequest

instance Core.ToJSON DeleteRequest where
  toJSON :: DeleteRequest -> Value
toJSON DeleteRequest' {HashMap Text AttributeValue
key :: HashMap Text AttributeValue
$sel:key:DeleteRequest' :: DeleteRequest -> HashMap Text AttributeValue
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [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)]
      )