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

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

-- | A PartiQL batch statement response..
--
-- /See:/ 'newBatchStatementResponse' smart constructor.
data BatchStatementResponse = BatchStatementResponse'
  { -- | The error associated with a failed PartiQL batch statement.
    BatchStatementResponse -> Maybe BatchStatementError
error :: Prelude.Maybe BatchStatementError,
    -- | A DynamoDB item associated with a BatchStatementResponse
    BatchStatementResponse -> Maybe (HashMap Text AttributeValue)
item :: Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue),
    -- | The table name associated with a failed PartiQL batch statement.
    BatchStatementResponse -> Maybe Text
tableName :: Prelude.Maybe Prelude.Text
  }
  deriving (BatchStatementResponse -> BatchStatementResponse -> Bool
(BatchStatementResponse -> BatchStatementResponse -> Bool)
-> (BatchStatementResponse -> BatchStatementResponse -> Bool)
-> Eq BatchStatementResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchStatementResponse -> BatchStatementResponse -> Bool
$c/= :: BatchStatementResponse -> BatchStatementResponse -> Bool
== :: BatchStatementResponse -> BatchStatementResponse -> Bool
$c== :: BatchStatementResponse -> BatchStatementResponse -> Bool
Prelude.Eq, ReadPrec [BatchStatementResponse]
ReadPrec BatchStatementResponse
Int -> ReadS BatchStatementResponse
ReadS [BatchStatementResponse]
(Int -> ReadS BatchStatementResponse)
-> ReadS [BatchStatementResponse]
-> ReadPrec BatchStatementResponse
-> ReadPrec [BatchStatementResponse]
-> Read BatchStatementResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchStatementResponse]
$creadListPrec :: ReadPrec [BatchStatementResponse]
readPrec :: ReadPrec BatchStatementResponse
$creadPrec :: ReadPrec BatchStatementResponse
readList :: ReadS [BatchStatementResponse]
$creadList :: ReadS [BatchStatementResponse]
readsPrec :: Int -> ReadS BatchStatementResponse
$creadsPrec :: Int -> ReadS BatchStatementResponse
Prelude.Read, Int -> BatchStatementResponse -> ShowS
[BatchStatementResponse] -> ShowS
BatchStatementResponse -> String
(Int -> BatchStatementResponse -> ShowS)
-> (BatchStatementResponse -> String)
-> ([BatchStatementResponse] -> ShowS)
-> Show BatchStatementResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchStatementResponse] -> ShowS
$cshowList :: [BatchStatementResponse] -> ShowS
show :: BatchStatementResponse -> String
$cshow :: BatchStatementResponse -> String
showsPrec :: Int -> BatchStatementResponse -> ShowS
$cshowsPrec :: Int -> BatchStatementResponse -> ShowS
Prelude.Show, (forall x. BatchStatementResponse -> Rep BatchStatementResponse x)
-> (forall x.
    Rep BatchStatementResponse x -> BatchStatementResponse)
-> Generic BatchStatementResponse
forall x. Rep BatchStatementResponse x -> BatchStatementResponse
forall x. BatchStatementResponse -> Rep BatchStatementResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchStatementResponse x -> BatchStatementResponse
$cfrom :: forall x. BatchStatementResponse -> Rep BatchStatementResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchStatementResponse' 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:
--
-- 'error', 'batchStatementResponse_error' - The error associated with a failed PartiQL batch statement.
--
-- 'item', 'batchStatementResponse_item' - A DynamoDB item associated with a BatchStatementResponse
--
-- 'tableName', 'batchStatementResponse_tableName' - The table name associated with a failed PartiQL batch statement.
newBatchStatementResponse ::
  BatchStatementResponse
newBatchStatementResponse :: BatchStatementResponse
newBatchStatementResponse =
  BatchStatementResponse' :: Maybe BatchStatementError
-> Maybe (HashMap Text AttributeValue)
-> Maybe Text
-> BatchStatementResponse
BatchStatementResponse'
    { $sel:error:BatchStatementResponse' :: Maybe BatchStatementError
error = Maybe BatchStatementError
forall a. Maybe a
Prelude.Nothing,
      $sel:item:BatchStatementResponse' :: Maybe (HashMap Text AttributeValue)
item = Maybe (HashMap Text AttributeValue)
forall a. Maybe a
Prelude.Nothing,
      $sel:tableName:BatchStatementResponse' :: Maybe Text
tableName = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The error associated with a failed PartiQL batch statement.
batchStatementResponse_error :: Lens.Lens' BatchStatementResponse (Prelude.Maybe BatchStatementError)
batchStatementResponse_error :: (Maybe BatchStatementError -> f (Maybe BatchStatementError))
-> BatchStatementResponse -> f BatchStatementResponse
batchStatementResponse_error = (BatchStatementResponse -> Maybe BatchStatementError)
-> (BatchStatementResponse
    -> Maybe BatchStatementError -> BatchStatementResponse)
-> Lens
     BatchStatementResponse
     BatchStatementResponse
     (Maybe BatchStatementError)
     (Maybe BatchStatementError)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchStatementResponse' {Maybe BatchStatementError
error :: Maybe BatchStatementError
$sel:error:BatchStatementResponse' :: BatchStatementResponse -> Maybe BatchStatementError
error} -> Maybe BatchStatementError
error) (\s :: BatchStatementResponse
s@BatchStatementResponse' {} Maybe BatchStatementError
a -> BatchStatementResponse
s {$sel:error:BatchStatementResponse' :: Maybe BatchStatementError
error = Maybe BatchStatementError
a} :: BatchStatementResponse)

-- | A DynamoDB item associated with a BatchStatementResponse
batchStatementResponse_item :: Lens.Lens' BatchStatementResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue))
batchStatementResponse_item :: (Maybe (HashMap Text AttributeValue)
 -> f (Maybe (HashMap Text AttributeValue)))
-> BatchStatementResponse -> f BatchStatementResponse
batchStatementResponse_item = (BatchStatementResponse -> Maybe (HashMap Text AttributeValue))
-> (BatchStatementResponse
    -> Maybe (HashMap Text AttributeValue) -> BatchStatementResponse)
-> Lens
     BatchStatementResponse
     BatchStatementResponse
     (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 (\BatchStatementResponse' {Maybe (HashMap Text AttributeValue)
item :: Maybe (HashMap Text AttributeValue)
$sel:item:BatchStatementResponse' :: BatchStatementResponse -> Maybe (HashMap Text AttributeValue)
item} -> Maybe (HashMap Text AttributeValue)
item) (\s :: BatchStatementResponse
s@BatchStatementResponse' {} Maybe (HashMap Text AttributeValue)
a -> BatchStatementResponse
s {$sel:item:BatchStatementResponse' :: Maybe (HashMap Text AttributeValue)
item = Maybe (HashMap Text AttributeValue)
a} :: BatchStatementResponse) ((Maybe (HashMap Text AttributeValue)
  -> f (Maybe (HashMap Text AttributeValue)))
 -> BatchStatementResponse -> f BatchStatementResponse)
-> ((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)))
-> BatchStatementResponse
-> f BatchStatementResponse
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

-- | The table name associated with a failed PartiQL batch statement.
batchStatementResponse_tableName :: Lens.Lens' BatchStatementResponse (Prelude.Maybe Prelude.Text)
batchStatementResponse_tableName :: (Maybe Text -> f (Maybe Text))
-> BatchStatementResponse -> f BatchStatementResponse
batchStatementResponse_tableName = (BatchStatementResponse -> Maybe Text)
-> (BatchStatementResponse -> Maybe Text -> BatchStatementResponse)
-> Lens
     BatchStatementResponse
     BatchStatementResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchStatementResponse' {Maybe Text
tableName :: Maybe Text
$sel:tableName:BatchStatementResponse' :: BatchStatementResponse -> Maybe Text
tableName} -> Maybe Text
tableName) (\s :: BatchStatementResponse
s@BatchStatementResponse' {} Maybe Text
a -> BatchStatementResponse
s {$sel:tableName:BatchStatementResponse' :: Maybe Text
tableName = Maybe Text
a} :: BatchStatementResponse)

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

instance Prelude.Hashable BatchStatementResponse

instance Prelude.NFData BatchStatementResponse