{-# 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.ProvisionedThroughput
-- 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.ProvisionedThroughput 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.WriteRequest
import qualified Amazonka.Prelude as Prelude

-- | Represents the provisioned throughput settings for a specified table or
-- index. The settings can be modified using the @UpdateTable@ operation.
--
-- For current minimum and maximum provisioned throughput values, see
-- <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html Service, Account, and Table Quotas>
-- in the /Amazon DynamoDB Developer Guide/.
--
-- /See:/ 'newProvisionedThroughput' smart constructor.
data ProvisionedThroughput = ProvisionedThroughput'
  { -- | The maximum number of strongly consistent reads consumed per second
    -- before DynamoDB returns a @ThrottlingException@. For more information,
    -- see
    -- <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html#ProvisionedThroughput Specifying Read and Write Requirements>
    -- in the /Amazon DynamoDB Developer Guide/.
    --
    -- If read\/write capacity mode is @PAY_PER_REQUEST@ the value is set to 0.
    ProvisionedThroughput -> Natural
readCapacityUnits :: Prelude.Natural,
    -- | The maximum number of writes consumed per second before DynamoDB returns
    -- a @ThrottlingException@. For more information, see
    -- <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html#ProvisionedThroughput Specifying Read and Write Requirements>
    -- in the /Amazon DynamoDB Developer Guide/.
    --
    -- If read\/write capacity mode is @PAY_PER_REQUEST@ the value is set to 0.
    ProvisionedThroughput -> Natural
writeCapacityUnits :: Prelude.Natural
  }
  deriving (ProvisionedThroughput -> ProvisionedThroughput -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProvisionedThroughput -> ProvisionedThroughput -> Bool
$c/= :: ProvisionedThroughput -> ProvisionedThroughput -> Bool
== :: ProvisionedThroughput -> ProvisionedThroughput -> Bool
$c== :: ProvisionedThroughput -> ProvisionedThroughput -> Bool
Prelude.Eq, ReadPrec [ProvisionedThroughput]
ReadPrec ProvisionedThroughput
Int -> ReadS ProvisionedThroughput
ReadS [ProvisionedThroughput]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ProvisionedThroughput]
$creadListPrec :: ReadPrec [ProvisionedThroughput]
readPrec :: ReadPrec ProvisionedThroughput
$creadPrec :: ReadPrec ProvisionedThroughput
readList :: ReadS [ProvisionedThroughput]
$creadList :: ReadS [ProvisionedThroughput]
readsPrec :: Int -> ReadS ProvisionedThroughput
$creadsPrec :: Int -> ReadS ProvisionedThroughput
Prelude.Read, Int -> ProvisionedThroughput -> ShowS
[ProvisionedThroughput] -> ShowS
ProvisionedThroughput -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProvisionedThroughput] -> ShowS
$cshowList :: [ProvisionedThroughput] -> ShowS
show :: ProvisionedThroughput -> String
$cshow :: ProvisionedThroughput -> String
showsPrec :: Int -> ProvisionedThroughput -> ShowS
$cshowsPrec :: Int -> ProvisionedThroughput -> ShowS
Prelude.Show, forall x. Rep ProvisionedThroughput x -> ProvisionedThroughput
forall x. ProvisionedThroughput -> Rep ProvisionedThroughput x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProvisionedThroughput x -> ProvisionedThroughput
$cfrom :: forall x. ProvisionedThroughput -> Rep ProvisionedThroughput x
Prelude.Generic)

-- |
-- Create a value of 'ProvisionedThroughput' 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:
--
-- 'readCapacityUnits', 'provisionedThroughput_readCapacityUnits' - The maximum number of strongly consistent reads consumed per second
-- before DynamoDB returns a @ThrottlingException@. For more information,
-- see
-- <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html#ProvisionedThroughput Specifying Read and Write Requirements>
-- in the /Amazon DynamoDB Developer Guide/.
--
-- If read\/write capacity mode is @PAY_PER_REQUEST@ the value is set to 0.
--
-- 'writeCapacityUnits', 'provisionedThroughput_writeCapacityUnits' - The maximum number of writes consumed per second before DynamoDB returns
-- a @ThrottlingException@. For more information, see
-- <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html#ProvisionedThroughput Specifying Read and Write Requirements>
-- in the /Amazon DynamoDB Developer Guide/.
--
-- If read\/write capacity mode is @PAY_PER_REQUEST@ the value is set to 0.
newProvisionedThroughput ::
  -- | 'readCapacityUnits'
  Prelude.Natural ->
  -- | 'writeCapacityUnits'
  Prelude.Natural ->
  ProvisionedThroughput
newProvisionedThroughput :: Natural -> Natural -> ProvisionedThroughput
newProvisionedThroughput
  Natural
pReadCapacityUnits_
  Natural
pWriteCapacityUnits_ =
    ProvisionedThroughput'
      { $sel:readCapacityUnits:ProvisionedThroughput' :: Natural
readCapacityUnits =
          Natural
pReadCapacityUnits_,
        $sel:writeCapacityUnits:ProvisionedThroughput' :: Natural
writeCapacityUnits = Natural
pWriteCapacityUnits_
      }

-- | The maximum number of strongly consistent reads consumed per second
-- before DynamoDB returns a @ThrottlingException@. For more information,
-- see
-- <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html#ProvisionedThroughput Specifying Read and Write Requirements>
-- in the /Amazon DynamoDB Developer Guide/.
--
-- If read\/write capacity mode is @PAY_PER_REQUEST@ the value is set to 0.
provisionedThroughput_readCapacityUnits :: Lens.Lens' ProvisionedThroughput Prelude.Natural
provisionedThroughput_readCapacityUnits :: Lens' ProvisionedThroughput Natural
provisionedThroughput_readCapacityUnits = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProvisionedThroughput' {Natural
readCapacityUnits :: Natural
$sel:readCapacityUnits:ProvisionedThroughput' :: ProvisionedThroughput -> Natural
readCapacityUnits} -> Natural
readCapacityUnits) (\s :: ProvisionedThroughput
s@ProvisionedThroughput' {} Natural
a -> ProvisionedThroughput
s {$sel:readCapacityUnits:ProvisionedThroughput' :: Natural
readCapacityUnits = Natural
a} :: ProvisionedThroughput)

-- | The maximum number of writes consumed per second before DynamoDB returns
-- a @ThrottlingException@. For more information, see
-- <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html#ProvisionedThroughput Specifying Read and Write Requirements>
-- in the /Amazon DynamoDB Developer Guide/.
--
-- If read\/write capacity mode is @PAY_PER_REQUEST@ the value is set to 0.
provisionedThroughput_writeCapacityUnits :: Lens.Lens' ProvisionedThroughput Prelude.Natural
provisionedThroughput_writeCapacityUnits :: Lens' ProvisionedThroughput Natural
provisionedThroughput_writeCapacityUnits = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProvisionedThroughput' {Natural
writeCapacityUnits :: Natural
$sel:writeCapacityUnits:ProvisionedThroughput' :: ProvisionedThroughput -> Natural
writeCapacityUnits} -> Natural
writeCapacityUnits) (\s :: ProvisionedThroughput
s@ProvisionedThroughput' {} Natural
a -> ProvisionedThroughput
s {$sel:writeCapacityUnits:ProvisionedThroughput' :: Natural
writeCapacityUnits = Natural
a} :: ProvisionedThroughput)

instance Data.FromJSON ProvisionedThroughput where
  parseJSON :: Value -> Parser ProvisionedThroughput
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ProvisionedThroughput"
      ( \Object
x ->
          Natural -> Natural -> ProvisionedThroughput
ProvisionedThroughput'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ReadCapacityUnits")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"WriteCapacityUnits")
      )

instance Prelude.Hashable ProvisionedThroughput where
  hashWithSalt :: Int -> ProvisionedThroughput -> Int
hashWithSalt Int
_salt ProvisionedThroughput' {Natural
writeCapacityUnits :: Natural
readCapacityUnits :: Natural
$sel:writeCapacityUnits:ProvisionedThroughput' :: ProvisionedThroughput -> Natural
$sel:readCapacityUnits:ProvisionedThroughput' :: ProvisionedThroughput -> Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
readCapacityUnits
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
writeCapacityUnits

instance Prelude.NFData ProvisionedThroughput where
  rnf :: ProvisionedThroughput -> ()
rnf ProvisionedThroughput' {Natural
writeCapacityUnits :: Natural
readCapacityUnits :: Natural
$sel:writeCapacityUnits:ProvisionedThroughput' :: ProvisionedThroughput -> Natural
$sel:readCapacityUnits:ProvisionedThroughput' :: ProvisionedThroughput -> Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Natural
readCapacityUnits
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
writeCapacityUnits

instance Data.ToJSON ProvisionedThroughput where
  toJSON :: ProvisionedThroughput -> Value
toJSON ProvisionedThroughput' {Natural
writeCapacityUnits :: Natural
readCapacityUnits :: Natural
$sel:writeCapacityUnits:ProvisionedThroughput' :: ProvisionedThroughput -> Natural
$sel:readCapacityUnits:ProvisionedThroughput' :: ProvisionedThroughput -> Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"ReadCapacityUnits" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
readCapacityUnits),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"WriteCapacityUnits" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
writeCapacityUnits)
          ]
      )