{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.APIGateway.Types.ThrottleSettings where

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

-- | The API request rate limits.
--
-- /See:/ 'newThrottleSettings' smart constructor.
data ThrottleSettings = ThrottleSettings'
  { -- | The API target request burst rate limit. This allows more requests
    -- through for a period of time than the target rate limit.
    ThrottleSettings -> Maybe Int
burstLimit :: Prelude.Maybe Prelude.Int,
    -- | The API target request rate limit.
    ThrottleSettings -> Maybe Double
rateLimit :: Prelude.Maybe Prelude.Double
  }
  deriving (ThrottleSettings -> ThrottleSettings -> Bool
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]
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
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. 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 target request burst rate limit. This allows more requests
-- through for a period of time than the target rate limit.
--
-- 'rateLimit', 'throttleSettings_rateLimit' - The API target request rate limit.
newThrottleSettings ::
  ThrottleSettings
newThrottleSettings :: ThrottleSettings
newThrottleSettings =
  ThrottleSettings'
    { $sel:burstLimit:ThrottleSettings' :: Maybe Int
burstLimit = forall a. Maybe a
Prelude.Nothing,
      $sel:rateLimit:ThrottleSettings' :: Maybe Double
rateLimit = forall a. Maybe a
Prelude.Nothing
    }

-- | The API target request burst rate limit. This allows more requests
-- through for a period of time than the target rate limit.
throttleSettings_burstLimit :: Lens.Lens' ThrottleSettings (Prelude.Maybe Prelude.Int)
throttleSettings_burstLimit :: Lens' ThrottleSettings (Maybe Int)
throttleSettings_burstLimit = 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 target request rate limit.
throttleSettings_rateLimit :: Lens.Lens' ThrottleSettings (Prelude.Maybe Prelude.Double)
throttleSettings_rateLimit :: Lens' ThrottleSettings (Maybe Double)
throttleSettings_rateLimit = 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 Data.FromJSON ThrottleSettings where
  parseJSON :: Value -> Parser ThrottleSettings
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ThrottleSettings"
      ( \Object
x ->
          Maybe Int -> Maybe Double -> ThrottleSettings
ThrottleSettings'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"burstLimit")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"rateLimit")
      )

instance Prelude.Hashable ThrottleSettings where
  hashWithSalt :: Int -> ThrottleSettings -> Int
hashWithSalt Int
_salt ThrottleSettings' {Maybe Double
Maybe Int
rateLimit :: Maybe Double
burstLimit :: Maybe Int
$sel:rateLimit:ThrottleSettings' :: ThrottleSettings -> Maybe Double
$sel:burstLimit:ThrottleSettings' :: ThrottleSettings -> Maybe Int
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
burstLimit
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
rateLimit

instance Prelude.NFData ThrottleSettings where
  rnf :: ThrottleSettings -> ()
rnf ThrottleSettings' {Maybe Double
Maybe Int
rateLimit :: Maybe Double
burstLimit :: Maybe Int
$sel:rateLimit:ThrottleSettings' :: ThrottleSettings -> Maybe Double
$sel:burstLimit:ThrottleSettings' :: ThrottleSettings -> Maybe Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
burstLimit
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
rateLimit

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"burstLimit" 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 Int
burstLimit,
            (Key
"rateLimit" 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 Double
rateLimit
          ]
      )