{-# 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-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)
module Amazonka.DynamoDB.Types.ProvisionedThroughput where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(ProvisionedThroughput -> ProvisionedThroughput -> Bool)
-> (ProvisionedThroughput -> ProvisionedThroughput -> Bool)
-> Eq ProvisionedThroughput
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]
(Int -> ReadS ProvisionedThroughput)
-> ReadS [ProvisionedThroughput]
-> ReadPrec ProvisionedThroughput
-> ReadPrec [ProvisionedThroughput]
-> Read 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
(Int -> ProvisionedThroughput -> ShowS)
-> (ProvisionedThroughput -> String)
-> ([ProvisionedThroughput] -> ShowS)
-> Show ProvisionedThroughput
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. ProvisionedThroughput -> Rep ProvisionedThroughput x)
-> (forall x. Rep ProvisionedThroughput x -> ProvisionedThroughput)
-> Generic ProvisionedThroughput
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' :: Natural -> Natural -> ProvisionedThroughput
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 :: (Natural -> f Natural)
-> ProvisionedThroughput -> f ProvisionedThroughput
provisionedThroughput_readCapacityUnits = (ProvisionedThroughput -> Natural)
-> (ProvisionedThroughput -> Natural -> ProvisionedThroughput)
-> Lens ProvisionedThroughput ProvisionedThroughput Natural Natural
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 :: (Natural -> f Natural)
-> ProvisionedThroughput -> f ProvisionedThroughput
provisionedThroughput_writeCapacityUnits = (ProvisionedThroughput -> Natural)
-> (ProvisionedThroughput -> Natural -> ProvisionedThroughput)
-> Lens ProvisionedThroughput ProvisionedThroughput Natural Natural
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 Core.FromJSON ProvisionedThroughput where
  parseJSON :: Value -> Parser ProvisionedThroughput
parseJSON =
    String
-> (Object -> Parser ProvisionedThroughput)
-> Value
-> Parser ProvisionedThroughput
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ProvisionedThroughput"
      ( \Object
x ->
          Natural -> Natural -> ProvisionedThroughput
ProvisionedThroughput'
            (Natural -> Natural -> ProvisionedThroughput)
-> Parser Natural -> Parser (Natural -> ProvisionedThroughput)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ReadCapacityUnits")
            Parser (Natural -> ProvisionedThroughput)
-> Parser Natural -> Parser ProvisionedThroughput
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"WriteCapacityUnits")
      )

instance Prelude.Hashable ProvisionedThroughput

instance Prelude.NFData ProvisionedThroughput

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ReadCapacityUnits" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
readCapacityUnits),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"WriteCapacityUnits" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
writeCapacityUnits)
          ]
      )