{-# 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.GlobalSecondaryIndexUpdate
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.DynamoDB.Types.GlobalSecondaryIndexUpdate 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.AttributeValue
import Amazonka.DynamoDB.Types.CreateGlobalSecondaryIndexAction
import Amazonka.DynamoDB.Types.DeleteGlobalSecondaryIndexAction
import Amazonka.DynamoDB.Types.UpdateGlobalSecondaryIndexAction
import Amazonka.DynamoDB.Types.WriteRequest
import qualified Amazonka.Prelude as Prelude

-- | Represents one of the following:
--
-- -   A new global secondary index to be added to an existing table.
--
-- -   New provisioned throughput parameters for an existing global
--     secondary index.
--
-- -   An existing global secondary index to be removed from an existing
--     table.
--
-- /See:/ 'newGlobalSecondaryIndexUpdate' smart constructor.
data GlobalSecondaryIndexUpdate = GlobalSecondaryIndexUpdate'
  { -- | The parameters required for creating a global secondary index on an
    -- existing table:
    --
    -- -   @IndexName @
    --
    -- -   @KeySchema @
    --
    -- -   @AttributeDefinitions @
    --
    -- -   @Projection @
    --
    -- -   @ProvisionedThroughput @
    GlobalSecondaryIndexUpdate
-> Maybe CreateGlobalSecondaryIndexAction
create :: Prelude.Maybe CreateGlobalSecondaryIndexAction,
    -- | The name of an existing global secondary index to be removed.
    GlobalSecondaryIndexUpdate
-> Maybe DeleteGlobalSecondaryIndexAction
delete' :: Prelude.Maybe DeleteGlobalSecondaryIndexAction,
    -- | The name of an existing global secondary index, along with new
    -- provisioned throughput settings to be applied to that index.
    GlobalSecondaryIndexUpdate
-> Maybe UpdateGlobalSecondaryIndexAction
update :: Prelude.Maybe UpdateGlobalSecondaryIndexAction
  }
  deriving (GlobalSecondaryIndexUpdate -> GlobalSecondaryIndexUpdate -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GlobalSecondaryIndexUpdate -> GlobalSecondaryIndexUpdate -> Bool
$c/= :: GlobalSecondaryIndexUpdate -> GlobalSecondaryIndexUpdate -> Bool
== :: GlobalSecondaryIndexUpdate -> GlobalSecondaryIndexUpdate -> Bool
$c== :: GlobalSecondaryIndexUpdate -> GlobalSecondaryIndexUpdate -> Bool
Prelude.Eq, ReadPrec [GlobalSecondaryIndexUpdate]
ReadPrec GlobalSecondaryIndexUpdate
Int -> ReadS GlobalSecondaryIndexUpdate
ReadS [GlobalSecondaryIndexUpdate]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GlobalSecondaryIndexUpdate]
$creadListPrec :: ReadPrec [GlobalSecondaryIndexUpdate]
readPrec :: ReadPrec GlobalSecondaryIndexUpdate
$creadPrec :: ReadPrec GlobalSecondaryIndexUpdate
readList :: ReadS [GlobalSecondaryIndexUpdate]
$creadList :: ReadS [GlobalSecondaryIndexUpdate]
readsPrec :: Int -> ReadS GlobalSecondaryIndexUpdate
$creadsPrec :: Int -> ReadS GlobalSecondaryIndexUpdate
Prelude.Read, Int -> GlobalSecondaryIndexUpdate -> ShowS
[GlobalSecondaryIndexUpdate] -> ShowS
GlobalSecondaryIndexUpdate -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GlobalSecondaryIndexUpdate] -> ShowS
$cshowList :: [GlobalSecondaryIndexUpdate] -> ShowS
show :: GlobalSecondaryIndexUpdate -> String
$cshow :: GlobalSecondaryIndexUpdate -> String
showsPrec :: Int -> GlobalSecondaryIndexUpdate -> ShowS
$cshowsPrec :: Int -> GlobalSecondaryIndexUpdate -> ShowS
Prelude.Show, forall x.
Rep GlobalSecondaryIndexUpdate x -> GlobalSecondaryIndexUpdate
forall x.
GlobalSecondaryIndexUpdate -> Rep GlobalSecondaryIndexUpdate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GlobalSecondaryIndexUpdate x -> GlobalSecondaryIndexUpdate
$cfrom :: forall x.
GlobalSecondaryIndexUpdate -> Rep GlobalSecondaryIndexUpdate x
Prelude.Generic)

-- |
-- Create a value of 'GlobalSecondaryIndexUpdate' 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:
--
-- 'create', 'globalSecondaryIndexUpdate_create' - The parameters required for creating a global secondary index on an
-- existing table:
--
-- -   @IndexName @
--
-- -   @KeySchema @
--
-- -   @AttributeDefinitions @
--
-- -   @Projection @
--
-- -   @ProvisionedThroughput @
--
-- 'delete'', 'globalSecondaryIndexUpdate_delete' - The name of an existing global secondary index to be removed.
--
-- 'update', 'globalSecondaryIndexUpdate_update' - The name of an existing global secondary index, along with new
-- provisioned throughput settings to be applied to that index.
newGlobalSecondaryIndexUpdate ::
  GlobalSecondaryIndexUpdate
newGlobalSecondaryIndexUpdate :: GlobalSecondaryIndexUpdate
newGlobalSecondaryIndexUpdate =
  GlobalSecondaryIndexUpdate'
    { $sel:create:GlobalSecondaryIndexUpdate' :: Maybe CreateGlobalSecondaryIndexAction
create =
        forall a. Maybe a
Prelude.Nothing,
      $sel:delete':GlobalSecondaryIndexUpdate' :: Maybe DeleteGlobalSecondaryIndexAction
delete' = forall a. Maybe a
Prelude.Nothing,
      $sel:update:GlobalSecondaryIndexUpdate' :: Maybe UpdateGlobalSecondaryIndexAction
update = forall a. Maybe a
Prelude.Nothing
    }

-- | The parameters required for creating a global secondary index on an
-- existing table:
--
-- -   @IndexName @
--
-- -   @KeySchema @
--
-- -   @AttributeDefinitions @
--
-- -   @Projection @
--
-- -   @ProvisionedThroughput @
globalSecondaryIndexUpdate_create :: Lens.Lens' GlobalSecondaryIndexUpdate (Prelude.Maybe CreateGlobalSecondaryIndexAction)
globalSecondaryIndexUpdate_create :: Lens'
  GlobalSecondaryIndexUpdate (Maybe CreateGlobalSecondaryIndexAction)
globalSecondaryIndexUpdate_create = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GlobalSecondaryIndexUpdate' {Maybe CreateGlobalSecondaryIndexAction
create :: Maybe CreateGlobalSecondaryIndexAction
$sel:create:GlobalSecondaryIndexUpdate' :: GlobalSecondaryIndexUpdate
-> Maybe CreateGlobalSecondaryIndexAction
create} -> Maybe CreateGlobalSecondaryIndexAction
create) (\s :: GlobalSecondaryIndexUpdate
s@GlobalSecondaryIndexUpdate' {} Maybe CreateGlobalSecondaryIndexAction
a -> GlobalSecondaryIndexUpdate
s {$sel:create:GlobalSecondaryIndexUpdate' :: Maybe CreateGlobalSecondaryIndexAction
create = Maybe CreateGlobalSecondaryIndexAction
a} :: GlobalSecondaryIndexUpdate)

-- | The name of an existing global secondary index to be removed.
globalSecondaryIndexUpdate_delete :: Lens.Lens' GlobalSecondaryIndexUpdate (Prelude.Maybe DeleteGlobalSecondaryIndexAction)
globalSecondaryIndexUpdate_delete :: Lens'
  GlobalSecondaryIndexUpdate (Maybe DeleteGlobalSecondaryIndexAction)
globalSecondaryIndexUpdate_delete = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GlobalSecondaryIndexUpdate' {Maybe DeleteGlobalSecondaryIndexAction
delete' :: Maybe DeleteGlobalSecondaryIndexAction
$sel:delete':GlobalSecondaryIndexUpdate' :: GlobalSecondaryIndexUpdate
-> Maybe DeleteGlobalSecondaryIndexAction
delete'} -> Maybe DeleteGlobalSecondaryIndexAction
delete') (\s :: GlobalSecondaryIndexUpdate
s@GlobalSecondaryIndexUpdate' {} Maybe DeleteGlobalSecondaryIndexAction
a -> GlobalSecondaryIndexUpdate
s {$sel:delete':GlobalSecondaryIndexUpdate' :: Maybe DeleteGlobalSecondaryIndexAction
delete' = Maybe DeleteGlobalSecondaryIndexAction
a} :: GlobalSecondaryIndexUpdate)

-- | The name of an existing global secondary index, along with new
-- provisioned throughput settings to be applied to that index.
globalSecondaryIndexUpdate_update :: Lens.Lens' GlobalSecondaryIndexUpdate (Prelude.Maybe UpdateGlobalSecondaryIndexAction)
globalSecondaryIndexUpdate_update :: Lens'
  GlobalSecondaryIndexUpdate (Maybe UpdateGlobalSecondaryIndexAction)
globalSecondaryIndexUpdate_update = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GlobalSecondaryIndexUpdate' {Maybe UpdateGlobalSecondaryIndexAction
update :: Maybe UpdateGlobalSecondaryIndexAction
$sel:update:GlobalSecondaryIndexUpdate' :: GlobalSecondaryIndexUpdate
-> Maybe UpdateGlobalSecondaryIndexAction
update} -> Maybe UpdateGlobalSecondaryIndexAction
update) (\s :: GlobalSecondaryIndexUpdate
s@GlobalSecondaryIndexUpdate' {} Maybe UpdateGlobalSecondaryIndexAction
a -> GlobalSecondaryIndexUpdate
s {$sel:update:GlobalSecondaryIndexUpdate' :: Maybe UpdateGlobalSecondaryIndexAction
update = Maybe UpdateGlobalSecondaryIndexAction
a} :: GlobalSecondaryIndexUpdate)

instance Prelude.Hashable GlobalSecondaryIndexUpdate where
  hashWithSalt :: Int -> GlobalSecondaryIndexUpdate -> Int
hashWithSalt Int
_salt GlobalSecondaryIndexUpdate' {Maybe UpdateGlobalSecondaryIndexAction
Maybe DeleteGlobalSecondaryIndexAction
Maybe CreateGlobalSecondaryIndexAction
update :: Maybe UpdateGlobalSecondaryIndexAction
delete' :: Maybe DeleteGlobalSecondaryIndexAction
create :: Maybe CreateGlobalSecondaryIndexAction
$sel:update:GlobalSecondaryIndexUpdate' :: GlobalSecondaryIndexUpdate
-> Maybe UpdateGlobalSecondaryIndexAction
$sel:delete':GlobalSecondaryIndexUpdate' :: GlobalSecondaryIndexUpdate
-> Maybe DeleteGlobalSecondaryIndexAction
$sel:create:GlobalSecondaryIndexUpdate' :: GlobalSecondaryIndexUpdate
-> Maybe CreateGlobalSecondaryIndexAction
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CreateGlobalSecondaryIndexAction
create
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DeleteGlobalSecondaryIndexAction
delete'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe UpdateGlobalSecondaryIndexAction
update

instance Prelude.NFData GlobalSecondaryIndexUpdate where
  rnf :: GlobalSecondaryIndexUpdate -> ()
rnf GlobalSecondaryIndexUpdate' {Maybe UpdateGlobalSecondaryIndexAction
Maybe DeleteGlobalSecondaryIndexAction
Maybe CreateGlobalSecondaryIndexAction
update :: Maybe UpdateGlobalSecondaryIndexAction
delete' :: Maybe DeleteGlobalSecondaryIndexAction
create :: Maybe CreateGlobalSecondaryIndexAction
$sel:update:GlobalSecondaryIndexUpdate' :: GlobalSecondaryIndexUpdate
-> Maybe UpdateGlobalSecondaryIndexAction
$sel:delete':GlobalSecondaryIndexUpdate' :: GlobalSecondaryIndexUpdate
-> Maybe DeleteGlobalSecondaryIndexAction
$sel:create:GlobalSecondaryIndexUpdate' :: GlobalSecondaryIndexUpdate
-> Maybe CreateGlobalSecondaryIndexAction
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe CreateGlobalSecondaryIndexAction
create
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe DeleteGlobalSecondaryIndexAction
delete'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe UpdateGlobalSecondaryIndexAction
update

instance Data.ToJSON GlobalSecondaryIndexUpdate where
  toJSON :: GlobalSecondaryIndexUpdate -> Value
toJSON GlobalSecondaryIndexUpdate' {Maybe UpdateGlobalSecondaryIndexAction
Maybe DeleteGlobalSecondaryIndexAction
Maybe CreateGlobalSecondaryIndexAction
update :: Maybe UpdateGlobalSecondaryIndexAction
delete' :: Maybe DeleteGlobalSecondaryIndexAction
create :: Maybe CreateGlobalSecondaryIndexAction
$sel:update:GlobalSecondaryIndexUpdate' :: GlobalSecondaryIndexUpdate
-> Maybe UpdateGlobalSecondaryIndexAction
$sel:delete':GlobalSecondaryIndexUpdate' :: GlobalSecondaryIndexUpdate
-> Maybe DeleteGlobalSecondaryIndexAction
$sel:create:GlobalSecondaryIndexUpdate' :: GlobalSecondaryIndexUpdate
-> Maybe CreateGlobalSecondaryIndexAction
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Create" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CreateGlobalSecondaryIndexAction
create,
            (Key
"Delete" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DeleteGlobalSecondaryIndexAction
delete',
            (Key
"Update" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe UpdateGlobalSecondaryIndexAction
update
          ]
      )