{-# 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.CloudDirectory.BatchRead
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Performs all the read operations in a batch.
module Amazonka.CloudDirectory.BatchRead
  ( -- * Creating a Request
    BatchRead (..),
    newBatchRead,

    -- * Request Lenses
    batchRead_consistencyLevel,
    batchRead_directoryArn,
    batchRead_operations,

    -- * Destructuring the Response
    BatchReadResponse (..),
    newBatchReadResponse,

    -- * Response Lenses
    batchReadResponse_responses,
    batchReadResponse_httpStatus,
  )
where

import Amazonka.CloudDirectory.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newBatchRead' smart constructor.
data BatchRead = BatchRead'
  { -- | Represents the manner and timing in which the successful write or update
    -- of an object is reflected in a subsequent read operation of that same
    -- object.
    BatchRead -> Maybe ConsistencyLevel
consistencyLevel :: Prelude.Maybe ConsistencyLevel,
    -- | The Amazon Resource Name (ARN) that is associated with the Directory.
    -- For more information, see arns.
    BatchRead -> Text
directoryArn :: Prelude.Text,
    -- | A list of operations that are part of the batch.
    BatchRead -> [BatchReadOperation]
operations :: [BatchReadOperation]
  }
  deriving (BatchRead -> BatchRead -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchRead -> BatchRead -> Bool
$c/= :: BatchRead -> BatchRead -> Bool
== :: BatchRead -> BatchRead -> Bool
$c== :: BatchRead -> BatchRead -> Bool
Prelude.Eq, ReadPrec [BatchRead]
ReadPrec BatchRead
Int -> ReadS BatchRead
ReadS [BatchRead]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchRead]
$creadListPrec :: ReadPrec [BatchRead]
readPrec :: ReadPrec BatchRead
$creadPrec :: ReadPrec BatchRead
readList :: ReadS [BatchRead]
$creadList :: ReadS [BatchRead]
readsPrec :: Int -> ReadS BatchRead
$creadsPrec :: Int -> ReadS BatchRead
Prelude.Read, Int -> BatchRead -> ShowS
[BatchRead] -> ShowS
BatchRead -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchRead] -> ShowS
$cshowList :: [BatchRead] -> ShowS
show :: BatchRead -> String
$cshow :: BatchRead -> String
showsPrec :: Int -> BatchRead -> ShowS
$cshowsPrec :: Int -> BatchRead -> ShowS
Prelude.Show, forall x. Rep BatchRead x -> BatchRead
forall x. BatchRead -> Rep BatchRead x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchRead x -> BatchRead
$cfrom :: forall x. BatchRead -> Rep BatchRead x
Prelude.Generic)

-- |
-- Create a value of 'BatchRead' 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:
--
-- 'consistencyLevel', 'batchRead_consistencyLevel' - Represents the manner and timing in which the successful write or update
-- of an object is reflected in a subsequent read operation of that same
-- object.
--
-- 'directoryArn', 'batchRead_directoryArn' - The Amazon Resource Name (ARN) that is associated with the Directory.
-- For more information, see arns.
--
-- 'operations', 'batchRead_operations' - A list of operations that are part of the batch.
newBatchRead ::
  -- | 'directoryArn'
  Prelude.Text ->
  BatchRead
newBatchRead :: Text -> BatchRead
newBatchRead Text
pDirectoryArn_ =
  BatchRead'
    { $sel:consistencyLevel:BatchRead' :: Maybe ConsistencyLevel
consistencyLevel = forall a. Maybe a
Prelude.Nothing,
      $sel:directoryArn:BatchRead' :: Text
directoryArn = Text
pDirectoryArn_,
      $sel:operations:BatchRead' :: [BatchReadOperation]
operations = forall a. Monoid a => a
Prelude.mempty
    }

-- | Represents the manner and timing in which the successful write or update
-- of an object is reflected in a subsequent read operation of that same
-- object.
batchRead_consistencyLevel :: Lens.Lens' BatchRead (Prelude.Maybe ConsistencyLevel)
batchRead_consistencyLevel :: Lens' BatchRead (Maybe ConsistencyLevel)
batchRead_consistencyLevel = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchRead' {Maybe ConsistencyLevel
consistencyLevel :: Maybe ConsistencyLevel
$sel:consistencyLevel:BatchRead' :: BatchRead -> Maybe ConsistencyLevel
consistencyLevel} -> Maybe ConsistencyLevel
consistencyLevel) (\s :: BatchRead
s@BatchRead' {} Maybe ConsistencyLevel
a -> BatchRead
s {$sel:consistencyLevel:BatchRead' :: Maybe ConsistencyLevel
consistencyLevel = Maybe ConsistencyLevel
a} :: BatchRead)

-- | The Amazon Resource Name (ARN) that is associated with the Directory.
-- For more information, see arns.
batchRead_directoryArn :: Lens.Lens' BatchRead Prelude.Text
batchRead_directoryArn :: Lens' BatchRead Text
batchRead_directoryArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchRead' {Text
directoryArn :: Text
$sel:directoryArn:BatchRead' :: BatchRead -> Text
directoryArn} -> Text
directoryArn) (\s :: BatchRead
s@BatchRead' {} Text
a -> BatchRead
s {$sel:directoryArn:BatchRead' :: Text
directoryArn = Text
a} :: BatchRead)

-- | A list of operations that are part of the batch.
batchRead_operations :: Lens.Lens' BatchRead [BatchReadOperation]
batchRead_operations :: Lens' BatchRead [BatchReadOperation]
batchRead_operations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchRead' {[BatchReadOperation]
operations :: [BatchReadOperation]
$sel:operations:BatchRead' :: BatchRead -> [BatchReadOperation]
operations} -> [BatchReadOperation]
operations) (\s :: BatchRead
s@BatchRead' {} [BatchReadOperation]
a -> BatchRead
s {$sel:operations:BatchRead' :: [BatchReadOperation]
operations = [BatchReadOperation]
a} :: BatchRead) 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 BatchRead where
  type AWSResponse BatchRead = BatchReadResponse
  request :: (Service -> Service) -> BatchRead -> Request BatchRead
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 BatchRead
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse BatchRead)))
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 [BatchReadOperationResponse] -> Int -> BatchReadResponse
BatchReadResponse'
            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
"Responses" 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 BatchRead where
  hashWithSalt :: Int -> BatchRead -> Int
hashWithSalt Int
_salt BatchRead' {[BatchReadOperation]
Maybe ConsistencyLevel
Text
operations :: [BatchReadOperation]
directoryArn :: Text
consistencyLevel :: Maybe ConsistencyLevel
$sel:operations:BatchRead' :: BatchRead -> [BatchReadOperation]
$sel:directoryArn:BatchRead' :: BatchRead -> Text
$sel:consistencyLevel:BatchRead' :: BatchRead -> Maybe ConsistencyLevel
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ConsistencyLevel
consistencyLevel
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
directoryArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [BatchReadOperation]
operations

instance Prelude.NFData BatchRead where
  rnf :: BatchRead -> ()
rnf BatchRead' {[BatchReadOperation]
Maybe ConsistencyLevel
Text
operations :: [BatchReadOperation]
directoryArn :: Text
consistencyLevel :: Maybe ConsistencyLevel
$sel:operations:BatchRead' :: BatchRead -> [BatchReadOperation]
$sel:directoryArn:BatchRead' :: BatchRead -> Text
$sel:consistencyLevel:BatchRead' :: BatchRead -> Maybe ConsistencyLevel
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ConsistencyLevel
consistencyLevel
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
directoryArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [BatchReadOperation]
operations

instance Data.ToHeaders BatchRead where
  toHeaders :: BatchRead -> ResponseHeaders
toHeaders BatchRead' {[BatchReadOperation]
Maybe ConsistencyLevel
Text
operations :: [BatchReadOperation]
directoryArn :: Text
consistencyLevel :: Maybe ConsistencyLevel
$sel:operations:BatchRead' :: BatchRead -> [BatchReadOperation]
$sel:directoryArn:BatchRead' :: BatchRead -> Text
$sel:consistencyLevel:BatchRead' :: BatchRead -> Maybe ConsistencyLevel
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"x-amz-consistency-level" forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# Maybe ConsistencyLevel
consistencyLevel,
        HeaderName
"x-amz-data-partition" forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# Text
directoryArn
      ]

instance Data.ToJSON BatchRead where
  toJSON :: BatchRead -> Value
toJSON BatchRead' {[BatchReadOperation]
Maybe ConsistencyLevel
Text
operations :: [BatchReadOperation]
directoryArn :: Text
consistencyLevel :: Maybe ConsistencyLevel
$sel:operations:BatchRead' :: BatchRead -> [BatchReadOperation]
$sel:directoryArn:BatchRead' :: BatchRead -> Text
$sel:consistencyLevel:BatchRead' :: BatchRead -> Maybe ConsistencyLevel
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"Operations" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [BatchReadOperation]
operations)]
      )

instance Data.ToPath BatchRead where
  toPath :: BatchRead -> ByteString
toPath =
    forall a b. a -> b -> a
Prelude.const
      ByteString
"/amazonclouddirectory/2017-01-11/batchread"

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

-- | /See:/ 'newBatchReadResponse' smart constructor.
data BatchReadResponse = BatchReadResponse'
  { -- | A list of all the responses for each batch read.
    BatchReadResponse -> Maybe [BatchReadOperationResponse]
responses :: Prelude.Maybe [BatchReadOperationResponse],
    -- | The response's http status code.
    BatchReadResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BatchReadResponse -> BatchReadResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchReadResponse -> BatchReadResponse -> Bool
$c/= :: BatchReadResponse -> BatchReadResponse -> Bool
== :: BatchReadResponse -> BatchReadResponse -> Bool
$c== :: BatchReadResponse -> BatchReadResponse -> Bool
Prelude.Eq, ReadPrec [BatchReadResponse]
ReadPrec BatchReadResponse
Int -> ReadS BatchReadResponse
ReadS [BatchReadResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchReadResponse]
$creadListPrec :: ReadPrec [BatchReadResponse]
readPrec :: ReadPrec BatchReadResponse
$creadPrec :: ReadPrec BatchReadResponse
readList :: ReadS [BatchReadResponse]
$creadList :: ReadS [BatchReadResponse]
readsPrec :: Int -> ReadS BatchReadResponse
$creadsPrec :: Int -> ReadS BatchReadResponse
Prelude.Read, Int -> BatchReadResponse -> ShowS
[BatchReadResponse] -> ShowS
BatchReadResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchReadResponse] -> ShowS
$cshowList :: [BatchReadResponse] -> ShowS
show :: BatchReadResponse -> String
$cshow :: BatchReadResponse -> String
showsPrec :: Int -> BatchReadResponse -> ShowS
$cshowsPrec :: Int -> BatchReadResponse -> ShowS
Prelude.Show, forall x. Rep BatchReadResponse x -> BatchReadResponse
forall x. BatchReadResponse -> Rep BatchReadResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchReadResponse x -> BatchReadResponse
$cfrom :: forall x. BatchReadResponse -> Rep BatchReadResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchReadResponse' 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:
--
-- 'responses', 'batchReadResponse_responses' - A list of all the responses for each batch read.
--
-- 'httpStatus', 'batchReadResponse_httpStatus' - The response's http status code.
newBatchReadResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchReadResponse
newBatchReadResponse :: Int -> BatchReadResponse
newBatchReadResponse Int
pHttpStatus_ =
  BatchReadResponse'
    { $sel:responses:BatchReadResponse' :: Maybe [BatchReadOperationResponse]
responses = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BatchReadResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of all the responses for each batch read.
batchReadResponse_responses :: Lens.Lens' BatchReadResponse (Prelude.Maybe [BatchReadOperationResponse])
batchReadResponse_responses :: Lens' BatchReadResponse (Maybe [BatchReadOperationResponse])
batchReadResponse_responses = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchReadResponse' {Maybe [BatchReadOperationResponse]
responses :: Maybe [BatchReadOperationResponse]
$sel:responses:BatchReadResponse' :: BatchReadResponse -> Maybe [BatchReadOperationResponse]
responses} -> Maybe [BatchReadOperationResponse]
responses) (\s :: BatchReadResponse
s@BatchReadResponse' {} Maybe [BatchReadOperationResponse]
a -> BatchReadResponse
s {$sel:responses:BatchReadResponse' :: Maybe [BatchReadOperationResponse]
responses = Maybe [BatchReadOperationResponse]
a} :: BatchReadResponse) 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.
batchReadResponse_httpStatus :: Lens.Lens' BatchReadResponse Prelude.Int
batchReadResponse_httpStatus :: Lens' BatchReadResponse Int
batchReadResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchReadResponse' {Int
httpStatus :: Int
$sel:httpStatus:BatchReadResponse' :: BatchReadResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: BatchReadResponse
s@BatchReadResponse' {} Int
a -> BatchReadResponse
s {$sel:httpStatus:BatchReadResponse' :: Int
httpStatus = Int
a} :: BatchReadResponse)

instance Prelude.NFData BatchReadResponse where
  rnf :: BatchReadResponse -> ()
rnf BatchReadResponse' {Int
Maybe [BatchReadOperationResponse]
httpStatus :: Int
responses :: Maybe [BatchReadOperationResponse]
$sel:httpStatus:BatchReadResponse' :: BatchReadResponse -> Int
$sel:responses:BatchReadResponse' :: BatchReadResponse -> Maybe [BatchReadOperationResponse]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [BatchReadOperationResponse]
responses
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus