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

import Amazonka.APIGateway.Types.QuotaPeriodType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Quotas configured for a usage plan.
--
-- /See:/ 'newQuotaSettings' smart constructor.
data QuotaSettings = QuotaSettings'
  { -- | The day that a time period starts. For example, with a time period of
    -- @WEEK@, an offset of @0@ starts on Sunday, and an offset of @1@ starts
    -- on Monday.
    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,
    -- | The maximum number of requests that can be made in a given time period.
    QuotaSettings -> Maybe Int
limit :: Prelude.Maybe Prelude.Int
  }
  deriving (QuotaSettings -> QuotaSettings -> Bool
(QuotaSettings -> QuotaSettings -> Bool)
-> (QuotaSettings -> QuotaSettings -> Bool) -> Eq QuotaSettings
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]
(Int -> ReadS QuotaSettings)
-> ReadS [QuotaSettings]
-> ReadPrec QuotaSettings
-> ReadPrec [QuotaSettings]
-> Read 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
(Int -> QuotaSettings -> ShowS)
-> (QuotaSettings -> String)
-> ([QuotaSettings] -> ShowS)
-> Show QuotaSettings
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. QuotaSettings -> Rep QuotaSettings x)
-> (forall x. Rep QuotaSettings x -> QuotaSettings)
-> Generic QuotaSettings
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:
--
-- 'offset', 'quotaSettings_offset' - The day that a time period starts. For example, with a time period of
-- @WEEK@, an offset of @0@ starts on Sunday, and an offset of @1@ starts
-- on Monday.
--
-- 'period', 'quotaSettings_period' - The time period in which the limit applies. Valid values are \"DAY\",
-- \"WEEK\" or \"MONTH\".
--
-- 'limit', 'quotaSettings_limit' - The maximum number of requests that can be made in a given time period.
newQuotaSettings ::
  QuotaSettings
newQuotaSettings :: QuotaSettings
newQuotaSettings =
  QuotaSettings' :: Maybe Int -> Maybe QuotaPeriodType -> Maybe Int -> QuotaSettings
QuotaSettings'
    { $sel:offset:QuotaSettings' :: Maybe Int
offset = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:period:QuotaSettings' :: Maybe QuotaPeriodType
period = Maybe QuotaPeriodType
forall a. Maybe a
Prelude.Nothing,
      $sel:limit:QuotaSettings' :: Maybe Int
limit = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | The day that a time period starts. For example, with a time period of
-- @WEEK@, an offset of @0@ starts on Sunday, and an offset of @1@ starts
-- on Monday.
quotaSettings_offset :: Lens.Lens' QuotaSettings (Prelude.Maybe Prelude.Int)
quotaSettings_offset :: (Maybe Int -> f (Maybe Int)) -> QuotaSettings -> f QuotaSettings
quotaSettings_offset = (QuotaSettings -> Maybe Int)
-> (QuotaSettings -> Maybe Int -> QuotaSettings)
-> Lens QuotaSettings QuotaSettings (Maybe Int) (Maybe Int)
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 :: (Maybe QuotaPeriodType -> f (Maybe QuotaPeriodType))
-> QuotaSettings -> f QuotaSettings
quotaSettings_period = (QuotaSettings -> Maybe QuotaPeriodType)
-> (QuotaSettings -> Maybe QuotaPeriodType -> QuotaSettings)
-> Lens
     QuotaSettings
     QuotaSettings
     (Maybe QuotaPeriodType)
     (Maybe QuotaPeriodType)
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)

-- | The maximum number of requests that can be made in a given time period.
quotaSettings_limit :: Lens.Lens' QuotaSettings (Prelude.Maybe Prelude.Int)
quotaSettings_limit :: (Maybe Int -> f (Maybe Int)) -> QuotaSettings -> f QuotaSettings
quotaSettings_limit = (QuotaSettings -> Maybe Int)
-> (QuotaSettings -> Maybe Int -> QuotaSettings)
-> Lens QuotaSettings QuotaSettings (Maybe Int) (Maybe Int)
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)

instance Core.FromJSON QuotaSettings where
  parseJSON :: Value -> Parser QuotaSettings
parseJSON =
    String
-> (Object -> Parser QuotaSettings)
-> Value
-> Parser QuotaSettings
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"QuotaSettings"
      ( \Object
x ->
          Maybe Int -> Maybe QuotaPeriodType -> Maybe Int -> QuotaSettings
QuotaSettings'
            (Maybe Int -> Maybe QuotaPeriodType -> Maybe Int -> QuotaSettings)
-> Parser (Maybe Int)
-> Parser (Maybe QuotaPeriodType -> Maybe Int -> QuotaSettings)
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
"offset")
            Parser (Maybe QuotaPeriodType -> Maybe Int -> QuotaSettings)
-> Parser (Maybe QuotaPeriodType)
-> Parser (Maybe Int -> QuotaSettings)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe QuotaPeriodType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"period")
            Parser (Maybe Int -> QuotaSettings)
-> Parser (Maybe Int) -> Parser QuotaSettings
forall (f :: * -> *) a b. Applicative f => 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
"limit")
      )

instance Prelude.Hashable QuotaSettings

instance Prelude.NFData QuotaSettings

instance Core.ToJSON QuotaSettings where
  toJSON :: QuotaSettings -> Value
toJSON QuotaSettings' {Maybe Int
Maybe QuotaPeriodType
limit :: Maybe Int
period :: Maybe QuotaPeriodType
offset :: Maybe Int
$sel:limit:QuotaSettings' :: QuotaSettings -> Maybe Int
$sel:period:QuotaSettings' :: QuotaSettings -> Maybe QuotaPeriodType
$sel:offset:QuotaSettings' :: QuotaSettings -> Maybe Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"offset" 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
offset,
            (Text
"period" Text -> QuotaPeriodType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (QuotaPeriodType -> Pair) -> Maybe QuotaPeriodType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe QuotaPeriodType
period,
            (Text
"limit" 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
limit
          ]
      )