{-# 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-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)
--
-- 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 Amazonka.DynamoDB.Types
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:/ '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
(UpdateGlobalTable -> UpdateGlobalTable -> Bool)
-> (UpdateGlobalTable -> UpdateGlobalTable -> Bool)
-> Eq UpdateGlobalTable
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]
(Int -> ReadS UpdateGlobalTable)
-> ReadS [UpdateGlobalTable]
-> ReadPrec UpdateGlobalTable
-> ReadPrec [UpdateGlobalTable]
-> Read 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
(Int -> UpdateGlobalTable -> ShowS)
-> (UpdateGlobalTable -> String)
-> ([UpdateGlobalTable] -> ShowS)
-> Show UpdateGlobalTable
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. UpdateGlobalTable -> Rep UpdateGlobalTable x)
-> (forall x. Rep UpdateGlobalTable x -> UpdateGlobalTable)
-> Generic UpdateGlobalTable
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' :: Text -> [ReplicaUpdate] -> UpdateGlobalTable
UpdateGlobalTable'
    { $sel:globalTableName:UpdateGlobalTable' :: Text
globalTableName =
        Text
pGlobalTableName_,
      $sel:replicaUpdates:UpdateGlobalTable' :: [ReplicaUpdate]
replicaUpdates = [ReplicaUpdate]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The global table name.
updateGlobalTable_globalTableName :: Lens.Lens' UpdateGlobalTable Prelude.Text
updateGlobalTable_globalTableName :: (Text -> f Text) -> UpdateGlobalTable -> f UpdateGlobalTable
updateGlobalTable_globalTableName = (UpdateGlobalTable -> Text)
-> (UpdateGlobalTable -> Text -> UpdateGlobalTable)
-> Lens UpdateGlobalTable UpdateGlobalTable Text Text
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 :: ([ReplicaUpdate] -> f [ReplicaUpdate])
-> UpdateGlobalTable -> f UpdateGlobalTable
updateGlobalTable_replicaUpdates = (UpdateGlobalTable -> [ReplicaUpdate])
-> (UpdateGlobalTable -> [ReplicaUpdate] -> UpdateGlobalTable)
-> Lens
     UpdateGlobalTable UpdateGlobalTable [ReplicaUpdate] [ReplicaUpdate]
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) (([ReplicaUpdate] -> f [ReplicaUpdate])
 -> UpdateGlobalTable -> f UpdateGlobalTable)
-> (([ReplicaUpdate] -> f [ReplicaUpdate])
    -> [ReplicaUpdate] -> f [ReplicaUpdate])
-> ([ReplicaUpdate] -> f [ReplicaUpdate])
-> UpdateGlobalTable
-> f UpdateGlobalTable
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([ReplicaUpdate] -> f [ReplicaUpdate])
-> [ReplicaUpdate] -> f [ReplicaUpdate]
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 :: UpdateGlobalTable -> Request UpdateGlobalTable
request = Service -> UpdateGlobalTable -> Request UpdateGlobalTable
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateGlobalTable
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateGlobalTable)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse UpdateGlobalTable))
-> Logger
-> Service
-> Proxy UpdateGlobalTable
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateGlobalTable)))
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 GlobalTableDescription -> Int -> UpdateGlobalTableResponse
UpdateGlobalTableResponse'
            (Maybe GlobalTableDescription -> Int -> UpdateGlobalTableResponse)
-> Either String (Maybe GlobalTableDescription)
-> Either String (Int -> UpdateGlobalTableResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe GlobalTableDescription)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"GlobalTableDescription")
            Either String (Int -> UpdateGlobalTableResponse)
-> Either String Int -> Either String UpdateGlobalTableResponse
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 UpdateGlobalTable

instance Prelude.NFData UpdateGlobalTable

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

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"GlobalTableName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
globalTableName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ReplicaUpdates" Text -> [ReplicaUpdate] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [ReplicaUpdate]
replicaUpdates)
          ]
      )

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

instance Core.ToQuery UpdateGlobalTable where
  toQuery :: UpdateGlobalTable -> QueryString
toQuery = QueryString -> UpdateGlobalTable -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(UpdateGlobalTableResponse -> UpdateGlobalTableResponse -> Bool)
-> (UpdateGlobalTableResponse -> UpdateGlobalTableResponse -> Bool)
-> Eq UpdateGlobalTableResponse
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]
(Int -> ReadS UpdateGlobalTableResponse)
-> ReadS [UpdateGlobalTableResponse]
-> ReadPrec UpdateGlobalTableResponse
-> ReadPrec [UpdateGlobalTableResponse]
-> Read 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
(Int -> UpdateGlobalTableResponse -> ShowS)
-> (UpdateGlobalTableResponse -> String)
-> ([UpdateGlobalTableResponse] -> ShowS)
-> Show UpdateGlobalTableResponse
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.
 UpdateGlobalTableResponse -> Rep UpdateGlobalTableResponse x)
-> (forall x.
    Rep UpdateGlobalTableResponse x -> UpdateGlobalTableResponse)
-> Generic UpdateGlobalTableResponse
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' :: Maybe GlobalTableDescription -> Int -> UpdateGlobalTableResponse
UpdateGlobalTableResponse'
    { $sel:globalTableDescription:UpdateGlobalTableResponse' :: Maybe GlobalTableDescription
globalTableDescription =
        Maybe 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 :: (Maybe GlobalTableDescription -> f (Maybe GlobalTableDescription))
-> UpdateGlobalTableResponse -> f UpdateGlobalTableResponse
updateGlobalTableResponse_globalTableDescription = (UpdateGlobalTableResponse -> Maybe GlobalTableDescription)
-> (UpdateGlobalTableResponse
    -> Maybe GlobalTableDescription -> UpdateGlobalTableResponse)
-> Lens
     UpdateGlobalTableResponse
     UpdateGlobalTableResponse
     (Maybe GlobalTableDescription)
     (Maybe 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 :: (Int -> f Int)
-> UpdateGlobalTableResponse -> f UpdateGlobalTableResponse
updateGlobalTableResponse_httpStatus = (UpdateGlobalTableResponse -> Int)
-> (UpdateGlobalTableResponse -> Int -> UpdateGlobalTableResponse)
-> Lens UpdateGlobalTableResponse UpdateGlobalTableResponse Int Int
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