{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.TransactWriteItems
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- @TransactWriteItems@ is a synchronous write operation that groups up to
-- 100 action requests. These actions can target items in different tables,
-- but not in different Amazon Web Services accounts or Regions, and no two
-- actions can target the same item. For example, you cannot both
-- @ConditionCheck@ and @Update@ the same item. The aggregate size of the
-- items in the transaction cannot exceed 4 MB.
--
-- The actions are completed atomically so that either all of them succeed,
-- or all of them fail. They are defined by the following objects:
--
-- -   @Put@  —   Initiates a @PutItem@ operation to write a new item. This
--     structure specifies the primary key of the item to be written, the
--     name of the table to write it in, an optional condition expression
--     that must be satisfied for the write to succeed, a list of the
--     item\'s attributes, and a field indicating whether to retrieve the
--     item\'s attributes if the condition is not met.
--
-- -   @Update@  —   Initiates an @UpdateItem@ operation to update an
--     existing item. This structure specifies the primary key of the item
--     to be updated, the name of the table where it resides, an optional
--     condition expression that must be satisfied for the update to
--     succeed, an expression that defines one or more attributes to be
--     updated, and a field indicating whether to retrieve the item\'s
--     attributes if the condition is not met.
--
-- -   @Delete@  —   Initiates a @DeleteItem@ operation to delete an
--     existing item. This structure specifies the primary key of the item
--     to be deleted, the name of the table where it resides, an optional
--     condition expression that must be satisfied for the deletion to
--     succeed, and a field indicating whether to retrieve the item\'s
--     attributes if the condition is not met.
--
-- -   @ConditionCheck@  —   Applies a condition to an item that is not
--     being modified by the transaction. This structure specifies the
--     primary key of the item to be checked, the name of the table where
--     it resides, a condition expression that must be satisfied for the
--     transaction to succeed, and a field indicating whether to retrieve
--     the item\'s attributes if the condition is not met.
--
-- DynamoDB rejects the entire @TransactWriteItems@ request if any of the
-- following is true:
--
-- -   A condition in one of the condition expressions is not met.
--
-- -   An ongoing operation is in the process of updating the same item.
--
-- -   There is insufficient provisioned capacity for the transaction to be
--     completed.
--
-- -   An item size becomes too large (bigger than 400 KB), a local
--     secondary index (LSI) becomes too large, or a similar validation
--     error occurs because of changes made by the transaction.
--
-- -   The aggregate size of the items in the transaction exceeds 4 MB.
--
-- -   There is a user error, such as an invalid data format.
module Amazonka.DynamoDB.TransactWriteItems
  ( -- * Creating a Request
    TransactWriteItems (..),
    newTransactWriteItems,

    -- * Request Lenses
    transactWriteItems_clientRequestToken,
    transactWriteItems_returnConsumedCapacity,
    transactWriteItems_returnItemCollectionMetrics,
    transactWriteItems_transactItems,

    -- * Destructuring the Response
    TransactWriteItemsResponse (..),
    newTransactWriteItemsResponse,

    -- * Response Lenses
    transactWriteItemsResponse_consumedCapacity,
    transactWriteItemsResponse_itemCollectionMetrics,
    transactWriteItemsResponse_httpStatus,
  )
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
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newTransactWriteItems' smart constructor.
data TransactWriteItems = TransactWriteItems'
  { -- | Providing a @ClientRequestToken@ makes the call to @TransactWriteItems@
    -- idempotent, meaning that multiple identical calls have the same effect
    -- as one single call.
    --
    -- Although multiple identical calls using the same client request token
    -- produce the same result on the server (no side effects), the responses
    -- to the calls might not be the same. If the @ReturnConsumedCapacity>@
    -- parameter is set, then the initial @TransactWriteItems@ call returns the
    -- amount of write capacity units consumed in making the changes.
    -- Subsequent @TransactWriteItems@ calls with the same client token return
    -- the number of read capacity units consumed in reading the item.
    --
    -- A client request token is valid for 10 minutes after the first request
    -- that uses it is completed. After 10 minutes, any request with the same
    -- client token is treated as a new request. Do not resubmit the same
    -- request with the same client token for more than 10 minutes, or the
    -- result might not be idempotent.
    --
    -- If you submit a request with the same client token but a change in other
    -- parameters within the 10-minute idempotency window, DynamoDB returns an
    -- @IdempotentParameterMismatch@ exception.
    TransactWriteItems -> Maybe Text
clientRequestToken :: Prelude.Maybe Prelude.Text,
    TransactWriteItems -> Maybe ReturnConsumedCapacity
returnConsumedCapacity :: Prelude.Maybe ReturnConsumedCapacity,
    -- | Determines whether item collection metrics are returned. If set to
    -- @SIZE@, the response includes statistics about item collections (if
    -- any), that were modified during the operation and are returned in the
    -- response. If set to @NONE@ (the default), no statistics are returned.
    TransactWriteItems -> Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics :: Prelude.Maybe ReturnItemCollectionMetrics,
    -- | An ordered array of up to 100 @TransactWriteItem@ objects, each of which
    -- contains a @ConditionCheck@, @Put@, @Update@, or @Delete@ object. These
    -- can operate on items in different tables, but the tables must reside in
    -- the same Amazon Web Services account and Region, and no two of them can
    -- operate on the same item.
    TransactWriteItems -> NonEmpty TransactWriteItem
transactItems :: Prelude.NonEmpty TransactWriteItem
  }
  deriving (TransactWriteItems -> TransactWriteItems -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TransactWriteItems -> TransactWriteItems -> Bool
$c/= :: TransactWriteItems -> TransactWriteItems -> Bool
== :: TransactWriteItems -> TransactWriteItems -> Bool
$c== :: TransactWriteItems -> TransactWriteItems -> Bool
Prelude.Eq, ReadPrec [TransactWriteItems]
ReadPrec TransactWriteItems
Int -> ReadS TransactWriteItems
ReadS [TransactWriteItems]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TransactWriteItems]
$creadListPrec :: ReadPrec [TransactWriteItems]
readPrec :: ReadPrec TransactWriteItems
$creadPrec :: ReadPrec TransactWriteItems
readList :: ReadS [TransactWriteItems]
$creadList :: ReadS [TransactWriteItems]
readsPrec :: Int -> ReadS TransactWriteItems
$creadsPrec :: Int -> ReadS TransactWriteItems
Prelude.Read, Int -> TransactWriteItems -> ShowS
[TransactWriteItems] -> ShowS
TransactWriteItems -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TransactWriteItems] -> ShowS
$cshowList :: [TransactWriteItems] -> ShowS
show :: TransactWriteItems -> String
$cshow :: TransactWriteItems -> String
showsPrec :: Int -> TransactWriteItems -> ShowS
$cshowsPrec :: Int -> TransactWriteItems -> ShowS
Prelude.Show, forall x. Rep TransactWriteItems x -> TransactWriteItems
forall x. TransactWriteItems -> Rep TransactWriteItems x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TransactWriteItems x -> TransactWriteItems
$cfrom :: forall x. TransactWriteItems -> Rep TransactWriteItems x
Prelude.Generic)

-- |
-- Create a value of 'TransactWriteItems' 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:
--
-- 'clientRequestToken', 'transactWriteItems_clientRequestToken' - Providing a @ClientRequestToken@ makes the call to @TransactWriteItems@
-- idempotent, meaning that multiple identical calls have the same effect
-- as one single call.
--
-- Although multiple identical calls using the same client request token
-- produce the same result on the server (no side effects), the responses
-- to the calls might not be the same. If the @ReturnConsumedCapacity>@
-- parameter is set, then the initial @TransactWriteItems@ call returns the
-- amount of write capacity units consumed in making the changes.
-- Subsequent @TransactWriteItems@ calls with the same client token return
-- the number of read capacity units consumed in reading the item.
--
-- A client request token is valid for 10 minutes after the first request
-- that uses it is completed. After 10 minutes, any request with the same
-- client token is treated as a new request. Do not resubmit the same
-- request with the same client token for more than 10 minutes, or the
-- result might not be idempotent.
--
-- If you submit a request with the same client token but a change in other
-- parameters within the 10-minute idempotency window, DynamoDB returns an
-- @IdempotentParameterMismatch@ exception.
--
-- 'returnConsumedCapacity', 'transactWriteItems_returnConsumedCapacity' - Undocumented member.
--
-- 'returnItemCollectionMetrics', 'transactWriteItems_returnItemCollectionMetrics' - Determines whether item collection metrics are returned. If set to
-- @SIZE@, the response includes statistics about item collections (if
-- any), that were modified during the operation and are returned in the
-- response. If set to @NONE@ (the default), no statistics are returned.
--
-- 'transactItems', 'transactWriteItems_transactItems' - An ordered array of up to 100 @TransactWriteItem@ objects, each of which
-- contains a @ConditionCheck@, @Put@, @Update@, or @Delete@ object. These
-- can operate on items in different tables, but the tables must reside in
-- the same Amazon Web Services account and Region, and no two of them can
-- operate on the same item.
newTransactWriteItems ::
  -- | 'transactItems'
  Prelude.NonEmpty TransactWriteItem ->
  TransactWriteItems
newTransactWriteItems :: NonEmpty TransactWriteItem -> TransactWriteItems
newTransactWriteItems NonEmpty TransactWriteItem
pTransactItems_ =
  TransactWriteItems'
    { $sel:clientRequestToken:TransactWriteItems' :: Maybe Text
clientRequestToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:returnConsumedCapacity:TransactWriteItems' :: Maybe ReturnConsumedCapacity
returnConsumedCapacity = forall a. Maybe a
Prelude.Nothing,
      $sel:returnItemCollectionMetrics:TransactWriteItems' :: Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics = forall a. Maybe a
Prelude.Nothing,
      $sel:transactItems:TransactWriteItems' :: NonEmpty TransactWriteItem
transactItems = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty TransactWriteItem
pTransactItems_
    }

-- | Providing a @ClientRequestToken@ makes the call to @TransactWriteItems@
-- idempotent, meaning that multiple identical calls have the same effect
-- as one single call.
--
-- Although multiple identical calls using the same client request token
-- produce the same result on the server (no side effects), the responses
-- to the calls might not be the same. If the @ReturnConsumedCapacity>@
-- parameter is set, then the initial @TransactWriteItems@ call returns the
-- amount of write capacity units consumed in making the changes.
-- Subsequent @TransactWriteItems@ calls with the same client token return
-- the number of read capacity units consumed in reading the item.
--
-- A client request token is valid for 10 minutes after the first request
-- that uses it is completed. After 10 minutes, any request with the same
-- client token is treated as a new request. Do not resubmit the same
-- request with the same client token for more than 10 minutes, or the
-- result might not be idempotent.
--
-- If you submit a request with the same client token but a change in other
-- parameters within the 10-minute idempotency window, DynamoDB returns an
-- @IdempotentParameterMismatch@ exception.
transactWriteItems_clientRequestToken :: Lens.Lens' TransactWriteItems (Prelude.Maybe Prelude.Text)
transactWriteItems_clientRequestToken :: Lens' TransactWriteItems (Maybe Text)
transactWriteItems_clientRequestToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransactWriteItems' {Maybe Text
clientRequestToken :: Maybe Text
$sel:clientRequestToken:TransactWriteItems' :: TransactWriteItems -> Maybe Text
clientRequestToken} -> Maybe Text
clientRequestToken) (\s :: TransactWriteItems
s@TransactWriteItems' {} Maybe Text
a -> TransactWriteItems
s {$sel:clientRequestToken:TransactWriteItems' :: Maybe Text
clientRequestToken = Maybe Text
a} :: TransactWriteItems)

-- | Undocumented member.
transactWriteItems_returnConsumedCapacity :: Lens.Lens' TransactWriteItems (Prelude.Maybe ReturnConsumedCapacity)
transactWriteItems_returnConsumedCapacity :: Lens' TransactWriteItems (Maybe ReturnConsumedCapacity)
transactWriteItems_returnConsumedCapacity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransactWriteItems' {Maybe ReturnConsumedCapacity
returnConsumedCapacity :: Maybe ReturnConsumedCapacity
$sel:returnConsumedCapacity:TransactWriteItems' :: TransactWriteItems -> Maybe ReturnConsumedCapacity
returnConsumedCapacity} -> Maybe ReturnConsumedCapacity
returnConsumedCapacity) (\s :: TransactWriteItems
s@TransactWriteItems' {} Maybe ReturnConsumedCapacity
a -> TransactWriteItems
s {$sel:returnConsumedCapacity:TransactWriteItems' :: Maybe ReturnConsumedCapacity
returnConsumedCapacity = Maybe ReturnConsumedCapacity
a} :: TransactWriteItems)

-- | Determines whether item collection metrics are returned. If set to
-- @SIZE@, the response includes statistics about item collections (if
-- any), that were modified during the operation and are returned in the
-- response. If set to @NONE@ (the default), no statistics are returned.
transactWriteItems_returnItemCollectionMetrics :: Lens.Lens' TransactWriteItems (Prelude.Maybe ReturnItemCollectionMetrics)
transactWriteItems_returnItemCollectionMetrics :: Lens' TransactWriteItems (Maybe ReturnItemCollectionMetrics)
transactWriteItems_returnItemCollectionMetrics = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransactWriteItems' {Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics :: Maybe ReturnItemCollectionMetrics
$sel:returnItemCollectionMetrics:TransactWriteItems' :: TransactWriteItems -> Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics} -> Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics) (\s :: TransactWriteItems
s@TransactWriteItems' {} Maybe ReturnItemCollectionMetrics
a -> TransactWriteItems
s {$sel:returnItemCollectionMetrics:TransactWriteItems' :: Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics = Maybe ReturnItemCollectionMetrics
a} :: TransactWriteItems)

-- | An ordered array of up to 100 @TransactWriteItem@ objects, each of which
-- contains a @ConditionCheck@, @Put@, @Update@, or @Delete@ object. These
-- can operate on items in different tables, but the tables must reside in
-- the same Amazon Web Services account and Region, and no two of them can
-- operate on the same item.
transactWriteItems_transactItems :: Lens.Lens' TransactWriteItems (Prelude.NonEmpty TransactWriteItem)
transactWriteItems_transactItems :: Lens' TransactWriteItems (NonEmpty TransactWriteItem)
transactWriteItems_transactItems = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransactWriteItems' {NonEmpty TransactWriteItem
transactItems :: NonEmpty TransactWriteItem
$sel:transactItems:TransactWriteItems' :: TransactWriteItems -> NonEmpty TransactWriteItem
transactItems} -> NonEmpty TransactWriteItem
transactItems) (\s :: TransactWriteItems
s@TransactWriteItems' {} NonEmpty TransactWriteItem
a -> TransactWriteItems
s {$sel:transactItems:TransactWriteItems' :: NonEmpty TransactWriteItem
transactItems = NonEmpty TransactWriteItem
a} :: TransactWriteItems) 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

instance Core.AWSRequest TransactWriteItems where
  type
    AWSResponse TransactWriteItems =
      TransactWriteItemsResponse
  request :: (Service -> Service)
-> TransactWriteItems -> Request TransactWriteItems
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy TransactWriteItems
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse TransactWriteItems)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [ConsumedCapacity]
-> Maybe (HashMap Text [ItemCollectionMetrics])
-> Int
-> TransactWriteItemsResponse
TransactWriteItemsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"ConsumedCapacity"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"ItemCollectionMetrics"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable TransactWriteItems where
  hashWithSalt :: Int -> TransactWriteItems -> Int
hashWithSalt Int
_salt TransactWriteItems' {Maybe Text
Maybe ReturnItemCollectionMetrics
Maybe ReturnConsumedCapacity
NonEmpty TransactWriteItem
transactItems :: NonEmpty TransactWriteItem
returnItemCollectionMetrics :: Maybe ReturnItemCollectionMetrics
returnConsumedCapacity :: Maybe ReturnConsumedCapacity
clientRequestToken :: Maybe Text
$sel:transactItems:TransactWriteItems' :: TransactWriteItems -> NonEmpty TransactWriteItem
$sel:returnItemCollectionMetrics:TransactWriteItems' :: TransactWriteItems -> Maybe ReturnItemCollectionMetrics
$sel:returnConsumedCapacity:TransactWriteItems' :: TransactWriteItems -> Maybe ReturnConsumedCapacity
$sel:clientRequestToken:TransactWriteItems' :: TransactWriteItems -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
clientRequestToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ReturnConsumedCapacity
returnConsumedCapacity
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty TransactWriteItem
transactItems

instance Prelude.NFData TransactWriteItems where
  rnf :: TransactWriteItems -> ()
rnf TransactWriteItems' {Maybe Text
Maybe ReturnItemCollectionMetrics
Maybe ReturnConsumedCapacity
NonEmpty TransactWriteItem
transactItems :: NonEmpty TransactWriteItem
returnItemCollectionMetrics :: Maybe ReturnItemCollectionMetrics
returnConsumedCapacity :: Maybe ReturnConsumedCapacity
clientRequestToken :: Maybe Text
$sel:transactItems:TransactWriteItems' :: TransactWriteItems -> NonEmpty TransactWriteItem
$sel:returnItemCollectionMetrics:TransactWriteItems' :: TransactWriteItems -> Maybe ReturnItemCollectionMetrics
$sel:returnConsumedCapacity:TransactWriteItems' :: TransactWriteItems -> Maybe ReturnConsumedCapacity
$sel:clientRequestToken:TransactWriteItems' :: TransactWriteItems -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
clientRequestToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ReturnConsumedCapacity
returnConsumedCapacity
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty TransactWriteItem
transactItems

instance Data.ToHeaders TransactWriteItems where
  toHeaders :: TransactWriteItems -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"DynamoDB_20120810.TransactWriteItems" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON TransactWriteItems where
  toJSON :: TransactWriteItems -> Value
toJSON TransactWriteItems' {Maybe Text
Maybe ReturnItemCollectionMetrics
Maybe ReturnConsumedCapacity
NonEmpty TransactWriteItem
transactItems :: NonEmpty TransactWriteItem
returnItemCollectionMetrics :: Maybe ReturnItemCollectionMetrics
returnConsumedCapacity :: Maybe ReturnConsumedCapacity
clientRequestToken :: Maybe Text
$sel:transactItems:TransactWriteItems' :: TransactWriteItems -> NonEmpty TransactWriteItem
$sel:returnItemCollectionMetrics:TransactWriteItems' :: TransactWriteItems -> Maybe ReturnItemCollectionMetrics
$sel:returnConsumedCapacity:TransactWriteItems' :: TransactWriteItems -> Maybe ReturnConsumedCapacity
$sel:clientRequestToken:TransactWriteItems' :: TransactWriteItems -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ClientRequestToken" 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
clientRequestToken,
            (Key
"ReturnConsumedCapacity" 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 ReturnConsumedCapacity
returnConsumedCapacity,
            (Key
"ReturnItemCollectionMetrics" 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 ReturnItemCollectionMetrics
returnItemCollectionMetrics,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"TransactItems" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty TransactWriteItem
transactItems)
          ]
      )

instance Data.ToPath TransactWriteItems where
  toPath :: TransactWriteItems -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery TransactWriteItems where
  toQuery :: TransactWriteItems -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newTransactWriteItemsResponse' smart constructor.
data TransactWriteItemsResponse = TransactWriteItemsResponse'
  { -- | The capacity units consumed by the entire @TransactWriteItems@
    -- operation. The values of the list are ordered according to the ordering
    -- of the @TransactItems@ request parameter.
    TransactWriteItemsResponse -> Maybe [ConsumedCapacity]
consumedCapacity :: Prelude.Maybe [ConsumedCapacity],
    -- | A list of tables that were processed by @TransactWriteItems@ and, for
    -- each table, information about any item collections that were affected by
    -- individual @UpdateItem@, @PutItem@, or @DeleteItem@ operations.
    TransactWriteItemsResponse
-> Maybe (HashMap Text [ItemCollectionMetrics])
itemCollectionMetrics :: Prelude.Maybe (Prelude.HashMap Prelude.Text [ItemCollectionMetrics]),
    -- | The response's http status code.
    TransactWriteItemsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (TransactWriteItemsResponse -> TransactWriteItemsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TransactWriteItemsResponse -> TransactWriteItemsResponse -> Bool
$c/= :: TransactWriteItemsResponse -> TransactWriteItemsResponse -> Bool
== :: TransactWriteItemsResponse -> TransactWriteItemsResponse -> Bool
$c== :: TransactWriteItemsResponse -> TransactWriteItemsResponse -> Bool
Prelude.Eq, ReadPrec [TransactWriteItemsResponse]
ReadPrec TransactWriteItemsResponse
Int -> ReadS TransactWriteItemsResponse
ReadS [TransactWriteItemsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TransactWriteItemsResponse]
$creadListPrec :: ReadPrec [TransactWriteItemsResponse]
readPrec :: ReadPrec TransactWriteItemsResponse
$creadPrec :: ReadPrec TransactWriteItemsResponse
readList :: ReadS [TransactWriteItemsResponse]
$creadList :: ReadS [TransactWriteItemsResponse]
readsPrec :: Int -> ReadS TransactWriteItemsResponse
$creadsPrec :: Int -> ReadS TransactWriteItemsResponse
Prelude.Read, Int -> TransactWriteItemsResponse -> ShowS
[TransactWriteItemsResponse] -> ShowS
TransactWriteItemsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TransactWriteItemsResponse] -> ShowS
$cshowList :: [TransactWriteItemsResponse] -> ShowS
show :: TransactWriteItemsResponse -> String
$cshow :: TransactWriteItemsResponse -> String
showsPrec :: Int -> TransactWriteItemsResponse -> ShowS
$cshowsPrec :: Int -> TransactWriteItemsResponse -> ShowS
Prelude.Show, forall x.
Rep TransactWriteItemsResponse x -> TransactWriteItemsResponse
forall x.
TransactWriteItemsResponse -> Rep TransactWriteItemsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep TransactWriteItemsResponse x -> TransactWriteItemsResponse
$cfrom :: forall x.
TransactWriteItemsResponse -> Rep TransactWriteItemsResponse x
Prelude.Generic)

-- |
-- Create a value of 'TransactWriteItemsResponse' 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:
--
-- 'consumedCapacity', 'transactWriteItemsResponse_consumedCapacity' - The capacity units consumed by the entire @TransactWriteItems@
-- operation. The values of the list are ordered according to the ordering
-- of the @TransactItems@ request parameter.
--
-- 'itemCollectionMetrics', 'transactWriteItemsResponse_itemCollectionMetrics' - A list of tables that were processed by @TransactWriteItems@ and, for
-- each table, information about any item collections that were affected by
-- individual @UpdateItem@, @PutItem@, or @DeleteItem@ operations.
--
-- 'httpStatus', 'transactWriteItemsResponse_httpStatus' - The response's http status code.
newTransactWriteItemsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  TransactWriteItemsResponse
newTransactWriteItemsResponse :: Int -> TransactWriteItemsResponse
newTransactWriteItemsResponse Int
pHttpStatus_ =
  TransactWriteItemsResponse'
    { $sel:consumedCapacity:TransactWriteItemsResponse' :: Maybe [ConsumedCapacity]
consumedCapacity =
        forall a. Maybe a
Prelude.Nothing,
      $sel:itemCollectionMetrics:TransactWriteItemsResponse' :: Maybe (HashMap Text [ItemCollectionMetrics])
itemCollectionMetrics = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:TransactWriteItemsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The capacity units consumed by the entire @TransactWriteItems@
-- operation. The values of the list are ordered according to the ordering
-- of the @TransactItems@ request parameter.
transactWriteItemsResponse_consumedCapacity :: Lens.Lens' TransactWriteItemsResponse (Prelude.Maybe [ConsumedCapacity])
transactWriteItemsResponse_consumedCapacity :: Lens' TransactWriteItemsResponse (Maybe [ConsumedCapacity])
transactWriteItemsResponse_consumedCapacity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransactWriteItemsResponse' {Maybe [ConsumedCapacity]
consumedCapacity :: Maybe [ConsumedCapacity]
$sel:consumedCapacity:TransactWriteItemsResponse' :: TransactWriteItemsResponse -> Maybe [ConsumedCapacity]
consumedCapacity} -> Maybe [ConsumedCapacity]
consumedCapacity) (\s :: TransactWriteItemsResponse
s@TransactWriteItemsResponse' {} Maybe [ConsumedCapacity]
a -> TransactWriteItemsResponse
s {$sel:consumedCapacity:TransactWriteItemsResponse' :: Maybe [ConsumedCapacity]
consumedCapacity = Maybe [ConsumedCapacity]
a} :: TransactWriteItemsResponse) 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

-- | A list of tables that were processed by @TransactWriteItems@ and, for
-- each table, information about any item collections that were affected by
-- individual @UpdateItem@, @PutItem@, or @DeleteItem@ operations.
transactWriteItemsResponse_itemCollectionMetrics :: Lens.Lens' TransactWriteItemsResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text [ItemCollectionMetrics]))
transactWriteItemsResponse_itemCollectionMetrics :: Lens'
  TransactWriteItemsResponse
  (Maybe (HashMap Text [ItemCollectionMetrics]))
transactWriteItemsResponse_itemCollectionMetrics = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransactWriteItemsResponse' {Maybe (HashMap Text [ItemCollectionMetrics])
itemCollectionMetrics :: Maybe (HashMap Text [ItemCollectionMetrics])
$sel:itemCollectionMetrics:TransactWriteItemsResponse' :: TransactWriteItemsResponse
-> Maybe (HashMap Text [ItemCollectionMetrics])
itemCollectionMetrics} -> Maybe (HashMap Text [ItemCollectionMetrics])
itemCollectionMetrics) (\s :: TransactWriteItemsResponse
s@TransactWriteItemsResponse' {} Maybe (HashMap Text [ItemCollectionMetrics])
a -> TransactWriteItemsResponse
s {$sel:itemCollectionMetrics:TransactWriteItemsResponse' :: Maybe (HashMap Text [ItemCollectionMetrics])
itemCollectionMetrics = Maybe (HashMap Text [ItemCollectionMetrics])
a} :: TransactWriteItemsResponse) 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

-- | The response's http status code.
transactWriteItemsResponse_httpStatus :: Lens.Lens' TransactWriteItemsResponse Prelude.Int
transactWriteItemsResponse_httpStatus :: Lens' TransactWriteItemsResponse Int
transactWriteItemsResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransactWriteItemsResponse' {Int
httpStatus :: Int
$sel:httpStatus:TransactWriteItemsResponse' :: TransactWriteItemsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: TransactWriteItemsResponse
s@TransactWriteItemsResponse' {} Int
a -> TransactWriteItemsResponse
s {$sel:httpStatus:TransactWriteItemsResponse' :: Int
httpStatus = Int
a} :: TransactWriteItemsResponse)

instance Prelude.NFData TransactWriteItemsResponse where
  rnf :: TransactWriteItemsResponse -> ()
rnf TransactWriteItemsResponse' {Int
Maybe [ConsumedCapacity]
Maybe (HashMap Text [ItemCollectionMetrics])
httpStatus :: Int
itemCollectionMetrics :: Maybe (HashMap Text [ItemCollectionMetrics])
consumedCapacity :: Maybe [ConsumedCapacity]
$sel:httpStatus:TransactWriteItemsResponse' :: TransactWriteItemsResponse -> Int
$sel:itemCollectionMetrics:TransactWriteItemsResponse' :: TransactWriteItemsResponse
-> Maybe (HashMap Text [ItemCollectionMetrics])
$sel:consumedCapacity:TransactWriteItemsResponse' :: TransactWriteItemsResponse -> Maybe [ConsumedCapacity]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [ConsumedCapacity]
consumedCapacity
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text [ItemCollectionMetrics])
itemCollectionMetrics
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus