{-# 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.APIGateway.Types.ThrottleSettings
-- 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.APIGateway.Types.ThrottleSettings where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The API request rate limits.
--
-- /See:/ 'newThrottleSettings' smart constructor.
data ThrottleSettings = ThrottleSettings'
  { -- | The API request burst limit, the maximum rate limit over a time ranging
    -- from one to a few seconds, depending upon whether the underlying token
    -- bucket is at its full capacity.
    ThrottleSettings -> Maybe Int
burstLimit :: Prelude.Maybe Prelude.Int,
    -- | The API request steady-state rate limit.
    ThrottleSettings -> Maybe Double
rateLimit :: Prelude.Maybe Prelude.Double
  }
  deriving (ThrottleSettings -> ThrottleSettings -> Bool
(ThrottleSettings -> ThrottleSettings -> Bool)
-> (ThrottleSettings -> ThrottleSettings -> Bool)
-> Eq ThrottleSettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ThrottleSettings -> ThrottleSettings -> Bool
$c/= :: ThrottleSettings -> ThrottleSettings -> Bool
== :: ThrottleSettings -> ThrottleSettings -> Bool
$c== :: ThrottleSettings -> ThrottleSettings -> Bool
Prelude.Eq, ReadPrec [ThrottleSettings]
ReadPrec ThrottleSettings
Int -> ReadS ThrottleSettings
ReadS [ThrottleSettings]
(Int -> ReadS ThrottleSettings)
-> ReadS [ThrottleSettings]
-> ReadPrec ThrottleSettings
-> ReadPrec [ThrottleSettings]
-> Read ThrottleSettings
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ThrottleSettings]
$creadListPrec :: ReadPrec [ThrottleSettings]
readPrec :: ReadPrec ThrottleSettings
$creadPrec :: ReadPrec ThrottleSettings
readList :: ReadS [ThrottleSettings]
$creadList :: ReadS [ThrottleSettings]
readsPrec :: Int -> ReadS ThrottleSettings
$creadsPrec :: Int -> ReadS ThrottleSettings
Prelude.Read, Int -> ThrottleSettings -> ShowS
[ThrottleSettings] -> ShowS
ThrottleSettings -> String
(Int -> ThrottleSettings -> ShowS)
-> (ThrottleSettings -> String)
-> ([ThrottleSettings] -> ShowS)
-> Show ThrottleSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ThrottleSettings] -> ShowS
$cshowList :: [ThrottleSettings] -> ShowS
show :: ThrottleSettings -> String
$cshow :: ThrottleSettings -> String
showsPrec :: Int -> ThrottleSettings -> ShowS
$cshowsPrec :: Int -> ThrottleSettings -> ShowS
Prelude.Show, (forall x. ThrottleSettings -> Rep ThrottleSettings x)
-> (forall x. Rep ThrottleSettings x -> ThrottleSettings)
-> Generic ThrottleSettings
forall x. Rep ThrottleSettings x -> ThrottleSettings
forall x. ThrottleSettings -> Rep ThrottleSettings x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ThrottleSettings x -> ThrottleSettings
$cfrom :: forall x. ThrottleSettings -> Rep ThrottleSettings x
Prelude.Generic)

-- |
-- Create a value of 'ThrottleSettings' 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:
--
-- 'burstLimit', 'throttleSettings_burstLimit' - The API request burst limit, the maximum rate limit over a time ranging
-- from one to a few seconds, depending upon whether the underlying token
-- bucket is at its full capacity.
--
-- 'rateLimit', 'throttleSettings_rateLimit' - The API request steady-state rate limit.
newThrottleSettings ::
  ThrottleSettings
newThrottleSettings :: ThrottleSettings
newThrottleSettings =
  ThrottleSettings' :: Maybe Int -> Maybe Double -> ThrottleSettings
ThrottleSettings'
    { $sel:burstLimit:ThrottleSettings' :: Maybe Int
burstLimit = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:rateLimit:ThrottleSettings' :: Maybe Double
rateLimit = Maybe Double
forall a. Maybe a
Prelude.Nothing
    }

-- | The API request burst limit, the maximum rate limit over a time ranging
-- from one to a few seconds, depending upon whether the underlying token
-- bucket is at its full capacity.
throttleSettings_burstLimit :: Lens.Lens' ThrottleSettings (Prelude.Maybe Prelude.Int)
throttleSettings_burstLimit :: (Maybe Int -> f (Maybe Int))
-> ThrottleSettings -> f ThrottleSettings
throttleSettings_burstLimit = (ThrottleSettings -> Maybe Int)
-> (ThrottleSettings -> Maybe Int -> ThrottleSettings)
-> Lens ThrottleSettings ThrottleSettings (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ThrottleSettings' {Maybe Int
burstLimit :: Maybe Int
$sel:burstLimit:ThrottleSettings' :: ThrottleSettings -> Maybe Int
burstLimit} -> Maybe Int
burstLimit) (\s :: ThrottleSettings
s@ThrottleSettings' {} Maybe Int
a -> ThrottleSettings
s {$sel:burstLimit:ThrottleSettings' :: Maybe Int
burstLimit = Maybe Int
a} :: ThrottleSettings)

-- | The API request steady-state rate limit.
throttleSettings_rateLimit :: Lens.Lens' ThrottleSettings (Prelude.Maybe Prelude.Double)
throttleSettings_rateLimit :: (Maybe Double -> f (Maybe Double))
-> ThrottleSettings -> f ThrottleSettings
throttleSettings_rateLimit = (ThrottleSettings -> Maybe Double)
-> (ThrottleSettings -> Maybe Double -> ThrottleSettings)
-> Lens
     ThrottleSettings ThrottleSettings (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ThrottleSettings' {Maybe Double
rateLimit :: Maybe Double
$sel:rateLimit:ThrottleSettings' :: ThrottleSettings -> Maybe Double
rateLimit} -> Maybe Double
rateLimit) (\s :: ThrottleSettings
s@ThrottleSettings' {} Maybe Double
a -> ThrottleSettings
s {$sel:rateLimit:ThrottleSettings' :: Maybe Double
rateLimit = Maybe Double
a} :: ThrottleSettings)

instance Core.FromJSON ThrottleSettings where
  parseJSON :: Value -> Parser ThrottleSettings
parseJSON =
    String
-> (Object -> Parser ThrottleSettings)
-> Value
-> Parser ThrottleSettings
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ThrottleSettings"
      ( \Object
x ->
          Maybe Int -> Maybe Double -> ThrottleSettings
ThrottleSettings'
            (Maybe Int -> Maybe Double -> ThrottleSettings)
-> Parser (Maybe Int) -> Parser (Maybe Double -> ThrottleSettings)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"burstLimit")
            Parser (Maybe Double -> ThrottleSettings)
-> Parser (Maybe Double) -> Parser ThrottleSettings
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"rateLimit")
      )

instance Prelude.Hashable ThrottleSettings

instance Prelude.NFData ThrottleSettings

instance Core.ToJSON ThrottleSettings where
  toJSON :: ThrottleSettings -> Value
toJSON ThrottleSettings' {Maybe Double
Maybe Int
rateLimit :: Maybe Double
burstLimit :: Maybe Int
$sel:rateLimit:ThrottleSettings' :: ThrottleSettings -> Maybe Double
$sel:burstLimit:ThrottleSettings' :: ThrottleSettings -> Maybe Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"burstLimit" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
burstLimit,
            (Text
"rateLimit" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
rateLimit
          ]
      )