{-# 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-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)
--
-- 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.Lens as Lens
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
(BatchRead -> BatchRead -> Bool)
-> (BatchRead -> BatchRead -> Bool) -> Eq BatchRead
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]
(Int -> ReadS BatchRead)
-> ReadS [BatchRead]
-> ReadPrec BatchRead
-> ReadPrec [BatchRead]
-> Read 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
(Int -> BatchRead -> ShowS)
-> (BatchRead -> String)
-> ([BatchRead] -> ShowS)
-> Show BatchRead
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. BatchRead -> Rep BatchRead x)
-> (forall x. Rep BatchRead x -> BatchRead) -> Generic BatchRead
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' :: Maybe ConsistencyLevel -> Text -> [BatchReadOperation] -> BatchRead
BatchRead'
    { $sel:consistencyLevel:BatchRead' :: Maybe ConsistencyLevel
consistencyLevel = Maybe ConsistencyLevel
forall a. Maybe a
Prelude.Nothing,
      $sel:directoryArn:BatchRead' :: Text
directoryArn = Text
pDirectoryArn_,
      $sel:operations:BatchRead' :: [BatchReadOperation]
operations = [BatchReadOperation]
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 :: (Maybe ConsistencyLevel -> f (Maybe ConsistencyLevel))
-> BatchRead -> f BatchRead
batchRead_consistencyLevel = (BatchRead -> Maybe ConsistencyLevel)
-> (BatchRead -> Maybe ConsistencyLevel -> BatchRead)
-> Lens
     BatchRead
     BatchRead
     (Maybe ConsistencyLevel)
     (Maybe 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 :: (Text -> f Text) -> BatchRead -> f BatchRead
batchRead_directoryArn = (BatchRead -> Text)
-> (BatchRead -> Text -> BatchRead)
-> Lens BatchRead BatchRead Text Text
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 :: ([BatchReadOperation] -> f [BatchReadOperation])
-> BatchRead -> f BatchRead
batchRead_operations = (BatchRead -> [BatchReadOperation])
-> (BatchRead -> [BatchReadOperation] -> BatchRead)
-> Lens
     BatchRead BatchRead [BatchReadOperation] [BatchReadOperation]
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) (([BatchReadOperation] -> f [BatchReadOperation])
 -> BatchRead -> f BatchRead)
-> (([BatchReadOperation] -> f [BatchReadOperation])
    -> [BatchReadOperation] -> f [BatchReadOperation])
-> ([BatchReadOperation] -> f [BatchReadOperation])
-> BatchRead
-> f BatchRead
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([BatchReadOperation] -> f [BatchReadOperation])
-> [BatchReadOperation] -> f [BatchReadOperation]
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 :: BatchRead -> Request BatchRead
request = Service -> BatchRead -> Request BatchRead
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy BatchRead
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse BatchRead)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse BatchRead))
-> Logger
-> Service
-> Proxy BatchRead
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse BatchRead)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [BatchReadOperationResponse] -> Int -> BatchReadResponse
BatchReadResponse'
            (Maybe [BatchReadOperationResponse] -> Int -> BatchReadResponse)
-> Either String (Maybe [BatchReadOperationResponse])
-> Either String (Int -> BatchReadResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object
-> Text
-> Either String (Maybe (Maybe [BatchReadOperationResponse]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Responses" Either String (Maybe (Maybe [BatchReadOperationResponse]))
-> Maybe [BatchReadOperationResponse]
-> Either String (Maybe [BatchReadOperationResponse])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [BatchReadOperationResponse]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> BatchReadResponse)
-> Either String Int -> Either String BatchReadResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable BatchRead

instance Prelude.NFData BatchRead

instance Core.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
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"x-amz-consistency-level" HeaderName -> Maybe ConsistencyLevel -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Maybe ConsistencyLevel
consistencyLevel,
        HeaderName
"x-amz-data-partition" HeaderName -> Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Text
directoryArn
      ]

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Operations" Text -> [BatchReadOperation] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [BatchReadOperation]
operations)]
      )

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

instance Core.ToQuery BatchRead where
  toQuery :: BatchRead -> QueryString
toQuery = QueryString -> BatchRead -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(BatchReadResponse -> BatchReadResponse -> Bool)
-> (BatchReadResponse -> BatchReadResponse -> Bool)
-> Eq BatchReadResponse
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]
(Int -> ReadS BatchReadResponse)
-> ReadS [BatchReadResponse]
-> ReadPrec BatchReadResponse
-> ReadPrec [BatchReadResponse]
-> Read 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
(Int -> BatchReadResponse -> ShowS)
-> (BatchReadResponse -> String)
-> ([BatchReadResponse] -> ShowS)
-> Show BatchReadResponse
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. BatchReadResponse -> Rep BatchReadResponse x)
-> (forall x. Rep BatchReadResponse x -> BatchReadResponse)
-> Generic BatchReadResponse
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' :: Maybe [BatchReadOperationResponse] -> Int -> BatchReadResponse
BatchReadResponse'
    { $sel:responses:BatchReadResponse' :: Maybe [BatchReadOperationResponse]
responses = Maybe [BatchReadOperationResponse]
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 :: (Maybe [BatchReadOperationResponse]
 -> f (Maybe [BatchReadOperationResponse]))
-> BatchReadResponse -> f BatchReadResponse
batchReadResponse_responses = (BatchReadResponse -> Maybe [BatchReadOperationResponse])
-> (BatchReadResponse
    -> Maybe [BatchReadOperationResponse] -> BatchReadResponse)
-> Lens
     BatchReadResponse
     BatchReadResponse
     (Maybe [BatchReadOperationResponse])
     (Maybe [BatchReadOperationResponse])
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) ((Maybe [BatchReadOperationResponse]
  -> f (Maybe [BatchReadOperationResponse]))
 -> BatchReadResponse -> f BatchReadResponse)
-> ((Maybe [BatchReadOperationResponse]
     -> f (Maybe [BatchReadOperationResponse]))
    -> Maybe [BatchReadOperationResponse]
    -> f (Maybe [BatchReadOperationResponse]))
-> (Maybe [BatchReadOperationResponse]
    -> f (Maybe [BatchReadOperationResponse]))
-> BatchReadResponse
-> f BatchReadResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [BatchReadOperationResponse]
  [BatchReadOperationResponse]
  [BatchReadOperationResponse]
  [BatchReadOperationResponse]
-> Iso
     (Maybe [BatchReadOperationResponse])
     (Maybe [BatchReadOperationResponse])
     (Maybe [BatchReadOperationResponse])
     (Maybe [BatchReadOperationResponse])
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
  [BatchReadOperationResponse]
  [BatchReadOperationResponse]
  [BatchReadOperationResponse]
  [BatchReadOperationResponse]
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 :: (Int -> f Int) -> BatchReadResponse -> f BatchReadResponse
batchReadResponse_httpStatus = (BatchReadResponse -> Int)
-> (BatchReadResponse -> Int -> BatchReadResponse)
-> Lens BatchReadResponse BatchReadResponse Int Int
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