{-# 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.QuotaSettings
-- 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.QuotaSettings where

import Amazonka.APIGateway.Types.QuotaPeriodType
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

-- | Quotas configured for a usage plan.
--
-- /See:/ 'newQuotaSettings' smart constructor.
data QuotaSettings = QuotaSettings'
  { -- | The target maximum number of requests that can be made in a given time
    -- period.
    QuotaSettings -> Maybe Int
limit :: Prelude.Maybe Prelude.Int,
    -- | The number of requests subtracted from the given limit in the initial
    -- time period.
    QuotaSettings -> Maybe Int
offset :: Prelude.Maybe Prelude.Int,
    -- | The time period in which the limit applies. Valid values are \"DAY\",
    -- \"WEEK\" or \"MONTH\".
    QuotaSettings -> Maybe QuotaPeriodType
period :: Prelude.Maybe QuotaPeriodType
  }
  deriving (QuotaSettings -> QuotaSettings -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QuotaSettings -> QuotaSettings -> Bool
$c/= :: QuotaSettings -> QuotaSettings -> Bool
== :: QuotaSettings -> QuotaSettings -> Bool
$c== :: QuotaSettings -> QuotaSettings -> Bool
Prelude.Eq, ReadPrec [QuotaSettings]
ReadPrec QuotaSettings
Int -> ReadS QuotaSettings
ReadS [QuotaSettings]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [QuotaSettings]
$creadListPrec :: ReadPrec [QuotaSettings]
readPrec :: ReadPrec QuotaSettings
$creadPrec :: ReadPrec QuotaSettings
readList :: ReadS [QuotaSettings]
$creadList :: ReadS [QuotaSettings]
readsPrec :: Int -> ReadS QuotaSettings
$creadsPrec :: Int -> ReadS QuotaSettings
Prelude.Read, Int -> QuotaSettings -> ShowS
[QuotaSettings] -> ShowS
QuotaSettings -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QuotaSettings] -> ShowS
$cshowList :: [QuotaSettings] -> ShowS
show :: QuotaSettings -> String
$cshow :: QuotaSettings -> String
showsPrec :: Int -> QuotaSettings -> ShowS
$cshowsPrec :: Int -> QuotaSettings -> ShowS
Prelude.Show, forall x. Rep QuotaSettings x -> QuotaSettings
forall x. QuotaSettings -> Rep QuotaSettings x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep QuotaSettings x -> QuotaSettings
$cfrom :: forall x. QuotaSettings -> Rep QuotaSettings x
Prelude.Generic)

-- |
-- Create a value of 'QuotaSettings' 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:
--
-- 'limit', 'quotaSettings_limit' - The target maximum number of requests that can be made in a given time
-- period.
--
-- 'offset', 'quotaSettings_offset' - The number of requests subtracted from the given limit in the initial
-- time period.
--
-- 'period', 'quotaSettings_period' - The time period in which the limit applies. Valid values are \"DAY\",
-- \"WEEK\" or \"MONTH\".
newQuotaSettings ::
  QuotaSettings
newQuotaSettings :: QuotaSettings
newQuotaSettings =
  QuotaSettings'
    { $sel:limit:QuotaSettings' :: Maybe Int
limit = forall a. Maybe a
Prelude.Nothing,
      $sel:offset:QuotaSettings' :: Maybe Int
offset = forall a. Maybe a
Prelude.Nothing,
      $sel:period:QuotaSettings' :: Maybe QuotaPeriodType
period = forall a. Maybe a
Prelude.Nothing
    }

-- | The target maximum number of requests that can be made in a given time
-- period.
quotaSettings_limit :: Lens.Lens' QuotaSettings (Prelude.Maybe Prelude.Int)
quotaSettings_limit :: Lens' QuotaSettings (Maybe Int)
quotaSettings_limit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QuotaSettings' {Maybe Int
limit :: Maybe Int
$sel:limit:QuotaSettings' :: QuotaSettings -> Maybe Int
limit} -> Maybe Int
limit) (\s :: QuotaSettings
s@QuotaSettings' {} Maybe Int
a -> QuotaSettings
s {$sel:limit:QuotaSettings' :: Maybe Int
limit = Maybe Int
a} :: QuotaSettings)

-- | The number of requests subtracted from the given limit in the initial
-- time period.
quotaSettings_offset :: Lens.Lens' QuotaSettings (Prelude.Maybe Prelude.Int)
quotaSettings_offset :: Lens' QuotaSettings (Maybe Int)
quotaSettings_offset = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QuotaSettings' {Maybe Int
offset :: Maybe Int
$sel:offset:QuotaSettings' :: QuotaSettings -> Maybe Int
offset} -> Maybe Int
offset) (\s :: QuotaSettings
s@QuotaSettings' {} Maybe Int
a -> QuotaSettings
s {$sel:offset:QuotaSettings' :: Maybe Int
offset = Maybe Int
a} :: QuotaSettings)

-- | The time period in which the limit applies. Valid values are \"DAY\",
-- \"WEEK\" or \"MONTH\".
quotaSettings_period :: Lens.Lens' QuotaSettings (Prelude.Maybe QuotaPeriodType)
quotaSettings_period :: Lens' QuotaSettings (Maybe QuotaPeriodType)
quotaSettings_period = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QuotaSettings' {Maybe QuotaPeriodType
period :: Maybe QuotaPeriodType
$sel:period:QuotaSettings' :: QuotaSettings -> Maybe QuotaPeriodType
period} -> Maybe QuotaPeriodType
period) (\s :: QuotaSettings
s@QuotaSettings' {} Maybe QuotaPeriodType
a -> QuotaSettings
s {$sel:period:QuotaSettings' :: Maybe QuotaPeriodType
period = Maybe QuotaPeriodType
a} :: QuotaSettings)

instance Data.FromJSON QuotaSettings where
  parseJSON :: Value -> Parser QuotaSettings
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"QuotaSettings"
      ( \Object
x ->
          Maybe Int -> Maybe Int -> Maybe QuotaPeriodType -> QuotaSettings
QuotaSettings'
            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
"limit")
            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
"offset")
            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
"period")
      )

instance Prelude.Hashable QuotaSettings where
  hashWithSalt :: Int -> QuotaSettings -> Int
hashWithSalt Int
_salt QuotaSettings' {Maybe Int
Maybe QuotaPeriodType
period :: Maybe QuotaPeriodType
offset :: Maybe Int
limit :: Maybe Int
$sel:period:QuotaSettings' :: QuotaSettings -> Maybe QuotaPeriodType
$sel:offset:QuotaSettings' :: QuotaSettings -> Maybe Int
$sel:limit:QuotaSettings' :: QuotaSettings -> Maybe Int
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
limit
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
offset
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe QuotaPeriodType
period

instance Prelude.NFData QuotaSettings where
  rnf :: QuotaSettings -> ()
rnf QuotaSettings' {Maybe Int
Maybe QuotaPeriodType
period :: Maybe QuotaPeriodType
offset :: Maybe Int
limit :: Maybe Int
$sel:period:QuotaSettings' :: QuotaSettings -> Maybe QuotaPeriodType
$sel:offset:QuotaSettings' :: QuotaSettings -> Maybe Int
$sel:limit:QuotaSettings' :: QuotaSettings -> Maybe Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
limit
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
offset
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe QuotaPeriodType
period

instance Data.ToJSON QuotaSettings where
  toJSON :: QuotaSettings -> Value
toJSON QuotaSettings' {Maybe Int
Maybe QuotaPeriodType
period :: Maybe QuotaPeriodType
offset :: Maybe Int
limit :: Maybe Int
$sel:period:QuotaSettings' :: QuotaSettings -> Maybe QuotaPeriodType
$sel:offset:QuotaSettings' :: QuotaSettings -> Maybe Int
$sel:limit:QuotaSettings' :: QuotaSettings -> Maybe Int
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"limit" 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
limit,
            (Key
"offset" 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
offset,
            (Key
"period" 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 QuotaPeriodType
period
          ]
      )