{-# 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.UpdateGlobalTable
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Adds or removes replicas in the specified global table. The global table
-- must already exist to be able to use this operation. Any replica to be
-- added must be empty, have the same name as the global table, have the
-- same key schema, have DynamoDB Streams enabled, and have the same
-- provisioned and maximum write capacity units.
--
-- Although you can use @UpdateGlobalTable@ to add replicas and remove
-- replicas in a single request, for simplicity we recommend that you issue
-- separate requests for adding or removing replicas.
--
-- If global secondary indexes are specified, then the following conditions
-- must also be met:
--
-- -   The global secondary indexes must have the same name.
--
-- -   The global secondary indexes must have the same hash key and sort
--     key (if present).
--
-- -   The global secondary indexes must have the same provisioned and
--     maximum write capacity units.
module Amazonka.DynamoDB.UpdateGlobalTable
  ( -- * Creating a Request
    UpdateGlobalTable (..),
    newUpdateGlobalTable,

    -- * Request Lenses
    updateGlobalTable_globalTableName,
    updateGlobalTable_replicaUpdates,

    -- * Destructuring the Response
    UpdateGlobalTableResponse (..),
    newUpdateGlobalTableResponse,

    -- * Response Lenses
    updateGlobalTableResponse_globalTableDescription,
    updateGlobalTableResponse_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:/ 'newUpdateGlobalTable' smart constructor.
data UpdateGlobalTable = UpdateGlobalTable'
  { -- | The global table name.
    UpdateGlobalTable -> Text
globalTableName :: Prelude.Text,
    -- | A list of Regions that should be added or removed from the global table.
    UpdateGlobalTable -> [ReplicaUpdate]
replicaUpdates :: [ReplicaUpdate]
  }
  deriving (UpdateGlobalTable -> UpdateGlobalTable -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateGlobalTable -> UpdateGlobalTable -> Bool
$c/= :: UpdateGlobalTable -> UpdateGlobalTable -> Bool
== :: UpdateGlobalTable -> UpdateGlobalTable -> Bool
$c== :: UpdateGlobalTable -> UpdateGlobalTable -> Bool
Prelude.Eq, ReadPrec [UpdateGlobalTable]
ReadPrec UpdateGlobalTable
Int -> ReadS UpdateGlobalTable
ReadS [UpdateGlobalTable]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateGlobalTable]
$creadListPrec :: ReadPrec [UpdateGlobalTable]
readPrec :: ReadPrec UpdateGlobalTable
$creadPrec :: ReadPrec UpdateGlobalTable
readList :: ReadS [UpdateGlobalTable]
$creadList :: ReadS [UpdateGlobalTable]
readsPrec :: Int -> ReadS UpdateGlobalTable
$creadsPrec :: Int -> ReadS UpdateGlobalTable
Prelude.Read, Int -> UpdateGlobalTable -> ShowS
[UpdateGlobalTable] -> ShowS
UpdateGlobalTable -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateGlobalTable] -> ShowS
$cshowList :: [UpdateGlobalTable] -> ShowS
show :: UpdateGlobalTable -> String
$cshow :: UpdateGlobalTable -> String
showsPrec :: Int -> UpdateGlobalTable -> ShowS
$cshowsPrec :: Int -> UpdateGlobalTable -> ShowS
Prelude.Show, forall x. Rep UpdateGlobalTable x -> UpdateGlobalTable
forall x. UpdateGlobalTable -> Rep UpdateGlobalTable x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateGlobalTable x -> UpdateGlobalTable
$cfrom :: forall x. UpdateGlobalTable -> Rep UpdateGlobalTable x
Prelude.Generic)

-- |
-- Create a value of 'UpdateGlobalTable' 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:
--
-- 'globalTableName', 'updateGlobalTable_globalTableName' - The global table name.
--
-- 'replicaUpdates', 'updateGlobalTable_replicaUpdates' - A list of Regions that should be added or removed from the global table.
newUpdateGlobalTable ::
  -- | 'globalTableName'
  Prelude.Text ->
  UpdateGlobalTable
newUpdateGlobalTable :: Text -> UpdateGlobalTable
newUpdateGlobalTable Text
pGlobalTableName_ =
  UpdateGlobalTable'
    { $sel:globalTableName:UpdateGlobalTable' :: Text
globalTableName =
        Text
pGlobalTableName_,
      $sel:replicaUpdates:UpdateGlobalTable' :: [ReplicaUpdate]
replicaUpdates = forall a. Monoid a => a
Prelude.mempty
    }

-- | The global table name.
updateGlobalTable_globalTableName :: Lens.Lens' UpdateGlobalTable Prelude.Text
updateGlobalTable_globalTableName :: Lens' UpdateGlobalTable Text
updateGlobalTable_globalTableName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateGlobalTable' {Text
globalTableName :: Text
$sel:globalTableName:UpdateGlobalTable' :: UpdateGlobalTable -> Text
globalTableName} -> Text
globalTableName) (\s :: UpdateGlobalTable
s@UpdateGlobalTable' {} Text
a -> UpdateGlobalTable
s {$sel:globalTableName:UpdateGlobalTable' :: Text
globalTableName = Text
a} :: UpdateGlobalTable)

-- | A list of Regions that should be added or removed from the global table.
updateGlobalTable_replicaUpdates :: Lens.Lens' UpdateGlobalTable [ReplicaUpdate]
updateGlobalTable_replicaUpdates :: Lens' UpdateGlobalTable [ReplicaUpdate]
updateGlobalTable_replicaUpdates = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateGlobalTable' {[ReplicaUpdate]
replicaUpdates :: [ReplicaUpdate]
$sel:replicaUpdates:UpdateGlobalTable' :: UpdateGlobalTable -> [ReplicaUpdate]
replicaUpdates} -> [ReplicaUpdate]
replicaUpdates) (\s :: UpdateGlobalTable
s@UpdateGlobalTable' {} [ReplicaUpdate]
a -> UpdateGlobalTable
s {$sel:replicaUpdates:UpdateGlobalTable' :: [ReplicaUpdate]
replicaUpdates = [ReplicaUpdate]
a} :: UpdateGlobalTable) 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 UpdateGlobalTable where
  type
    AWSResponse UpdateGlobalTable =
      UpdateGlobalTableResponse
  request :: (Service -> Service)
-> UpdateGlobalTable -> Request UpdateGlobalTable
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 UpdateGlobalTable
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateGlobalTable)))
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 GlobalTableDescription -> Int -> UpdateGlobalTableResponse
UpdateGlobalTableResponse'
            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
"GlobalTableDescription")
            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 UpdateGlobalTable where
  hashWithSalt :: Int -> UpdateGlobalTable -> Int
hashWithSalt Int
_salt UpdateGlobalTable' {[ReplicaUpdate]
Text
replicaUpdates :: [ReplicaUpdate]
globalTableName :: Text
$sel:replicaUpdates:UpdateGlobalTable' :: UpdateGlobalTable -> [ReplicaUpdate]
$sel:globalTableName:UpdateGlobalTable' :: UpdateGlobalTable -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
globalTableName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [ReplicaUpdate]
replicaUpdates

instance Prelude.NFData UpdateGlobalTable where
  rnf :: UpdateGlobalTable -> ()
rnf UpdateGlobalTable' {[ReplicaUpdate]
Text
replicaUpdates :: [ReplicaUpdate]
globalTableName :: Text
$sel:replicaUpdates:UpdateGlobalTable' :: UpdateGlobalTable -> [ReplicaUpdate]
$sel:globalTableName:UpdateGlobalTable' :: UpdateGlobalTable -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
globalTableName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [ReplicaUpdate]
replicaUpdates

instance Data.ToHeaders UpdateGlobalTable where
  toHeaders :: UpdateGlobalTable -> 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.UpdateGlobalTable" ::
                          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 UpdateGlobalTable where
  toJSON :: UpdateGlobalTable -> Value
toJSON UpdateGlobalTable' {[ReplicaUpdate]
Text
replicaUpdates :: [ReplicaUpdate]
globalTableName :: Text
$sel:replicaUpdates:UpdateGlobalTable' :: UpdateGlobalTable -> [ReplicaUpdate]
$sel:globalTableName:UpdateGlobalTable' :: UpdateGlobalTable -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"GlobalTableName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
globalTableName),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ReplicaUpdates" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [ReplicaUpdate]
replicaUpdates)
          ]
      )

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

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

-- | /See:/ 'newUpdateGlobalTableResponse' smart constructor.
data UpdateGlobalTableResponse = UpdateGlobalTableResponse'
  { -- | Contains the details of the global table.
    UpdateGlobalTableResponse -> Maybe GlobalTableDescription
globalTableDescription :: Prelude.Maybe GlobalTableDescription,
    -- | The response's http status code.
    UpdateGlobalTableResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (UpdateGlobalTableResponse -> UpdateGlobalTableResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateGlobalTableResponse -> UpdateGlobalTableResponse -> Bool
$c/= :: UpdateGlobalTableResponse -> UpdateGlobalTableResponse -> Bool
== :: UpdateGlobalTableResponse -> UpdateGlobalTableResponse -> Bool
$c== :: UpdateGlobalTableResponse -> UpdateGlobalTableResponse -> Bool
Prelude.Eq, ReadPrec [UpdateGlobalTableResponse]
ReadPrec UpdateGlobalTableResponse
Int -> ReadS UpdateGlobalTableResponse
ReadS [UpdateGlobalTableResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateGlobalTableResponse]
$creadListPrec :: ReadPrec [UpdateGlobalTableResponse]
readPrec :: ReadPrec UpdateGlobalTableResponse
$creadPrec :: ReadPrec UpdateGlobalTableResponse
readList :: ReadS [UpdateGlobalTableResponse]
$creadList :: ReadS [UpdateGlobalTableResponse]
readsPrec :: Int -> ReadS UpdateGlobalTableResponse
$creadsPrec :: Int -> ReadS UpdateGlobalTableResponse
Prelude.Read, Int -> UpdateGlobalTableResponse -> ShowS
[UpdateGlobalTableResponse] -> ShowS
UpdateGlobalTableResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateGlobalTableResponse] -> ShowS
$cshowList :: [UpdateGlobalTableResponse] -> ShowS
show :: UpdateGlobalTableResponse -> String
$cshow :: UpdateGlobalTableResponse -> String
showsPrec :: Int -> UpdateGlobalTableResponse -> ShowS
$cshowsPrec :: Int -> UpdateGlobalTableResponse -> ShowS
Prelude.Show, forall x.
Rep UpdateGlobalTableResponse x -> UpdateGlobalTableResponse
forall x.
UpdateGlobalTableResponse -> Rep UpdateGlobalTableResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdateGlobalTableResponse x -> UpdateGlobalTableResponse
$cfrom :: forall x.
UpdateGlobalTableResponse -> Rep UpdateGlobalTableResponse x
Prelude.Generic)

-- |
-- Create a value of 'UpdateGlobalTableResponse' 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:
--
-- 'globalTableDescription', 'updateGlobalTableResponse_globalTableDescription' - Contains the details of the global table.
--
-- 'httpStatus', 'updateGlobalTableResponse_httpStatus' - The response's http status code.
newUpdateGlobalTableResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdateGlobalTableResponse
newUpdateGlobalTableResponse :: Int -> UpdateGlobalTableResponse
newUpdateGlobalTableResponse Int
pHttpStatus_ =
  UpdateGlobalTableResponse'
    { $sel:globalTableDescription:UpdateGlobalTableResponse' :: Maybe GlobalTableDescription
globalTableDescription =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:UpdateGlobalTableResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Contains the details of the global table.
updateGlobalTableResponse_globalTableDescription :: Lens.Lens' UpdateGlobalTableResponse (Prelude.Maybe GlobalTableDescription)
updateGlobalTableResponse_globalTableDescription :: Lens' UpdateGlobalTableResponse (Maybe GlobalTableDescription)
updateGlobalTableResponse_globalTableDescription = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateGlobalTableResponse' {Maybe GlobalTableDescription
globalTableDescription :: Maybe GlobalTableDescription
$sel:globalTableDescription:UpdateGlobalTableResponse' :: UpdateGlobalTableResponse -> Maybe GlobalTableDescription
globalTableDescription} -> Maybe GlobalTableDescription
globalTableDescription) (\s :: UpdateGlobalTableResponse
s@UpdateGlobalTableResponse' {} Maybe GlobalTableDescription
a -> UpdateGlobalTableResponse
s {$sel:globalTableDescription:UpdateGlobalTableResponse' :: Maybe GlobalTableDescription
globalTableDescription = Maybe GlobalTableDescription
a} :: UpdateGlobalTableResponse)

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

instance Prelude.NFData UpdateGlobalTableResponse where
  rnf :: UpdateGlobalTableResponse -> ()
rnf UpdateGlobalTableResponse' {Int
Maybe GlobalTableDescription
httpStatus :: Int
globalTableDescription :: Maybe GlobalTableDescription
$sel:httpStatus:UpdateGlobalTableResponse' :: UpdateGlobalTableResponse -> Int
$sel:globalTableDescription:UpdateGlobalTableResponse' :: UpdateGlobalTableResponse -> Maybe GlobalTableDescription
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe GlobalTableDescription
globalTableDescription
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus