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

import Amazonka.APIGateway.Types.ApiStage
import Amazonka.APIGateway.Types.QuotaSettings
import Amazonka.APIGateway.Types.ThrottleSettings
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

-- | Represents a usage plan used to specify who can assess associated API
-- stages. Optionally, target request rate and quota limits can be set. In
-- some cases clients can exceed the targets that you set. Don’t rely on
-- usage plans to control costs. Consider using
-- <https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-managing-costs.html Amazon Web Services Budgets>
-- to monitor costs and
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html WAF>
-- to manage API requests.
--
-- /See:/ 'newUsagePlan' smart constructor.
data UsagePlan = UsagePlan'
  { -- | The associated API stages of a usage plan.
    UsagePlan -> Maybe [ApiStage]
apiStages :: Prelude.Maybe [ApiStage],
    -- | The description of a usage plan.
    UsagePlan -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The identifier of a UsagePlan resource.
    UsagePlan -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | The name of a usage plan.
    UsagePlan -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The AWS Markeplace product identifier to associate with the usage plan
    -- as a SaaS product on AWS Marketplace.
    UsagePlan -> Maybe Text
productCode :: Prelude.Maybe Prelude.Text,
    -- | The target maximum number of permitted requests per a given unit time
    -- interval.
    UsagePlan -> Maybe QuotaSettings
quota :: Prelude.Maybe QuotaSettings,
    -- | The collection of tags. Each tag element is associated with a given
    -- resource.
    UsagePlan -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | A map containing method level throttling information for API stage in a
    -- usage plan.
    UsagePlan -> Maybe ThrottleSettings
throttle :: Prelude.Maybe ThrottleSettings
  }
  deriving (UsagePlan -> UsagePlan -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UsagePlan -> UsagePlan -> Bool
$c/= :: UsagePlan -> UsagePlan -> Bool
== :: UsagePlan -> UsagePlan -> Bool
$c== :: UsagePlan -> UsagePlan -> Bool
Prelude.Eq, ReadPrec [UsagePlan]
ReadPrec UsagePlan
Int -> ReadS UsagePlan
ReadS [UsagePlan]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UsagePlan]
$creadListPrec :: ReadPrec [UsagePlan]
readPrec :: ReadPrec UsagePlan
$creadPrec :: ReadPrec UsagePlan
readList :: ReadS [UsagePlan]
$creadList :: ReadS [UsagePlan]
readsPrec :: Int -> ReadS UsagePlan
$creadsPrec :: Int -> ReadS UsagePlan
Prelude.Read, Int -> UsagePlan -> ShowS
[UsagePlan] -> ShowS
UsagePlan -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UsagePlan] -> ShowS
$cshowList :: [UsagePlan] -> ShowS
show :: UsagePlan -> String
$cshow :: UsagePlan -> String
showsPrec :: Int -> UsagePlan -> ShowS
$cshowsPrec :: Int -> UsagePlan -> ShowS
Prelude.Show, forall x. Rep UsagePlan x -> UsagePlan
forall x. UsagePlan -> Rep UsagePlan x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UsagePlan x -> UsagePlan
$cfrom :: forall x. UsagePlan -> Rep UsagePlan x
Prelude.Generic)

-- |
-- Create a value of 'UsagePlan' 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:
--
-- 'apiStages', 'usagePlan_apiStages' - The associated API stages of a usage plan.
--
-- 'description', 'usagePlan_description' - The description of a usage plan.
--
-- 'id', 'usagePlan_id' - The identifier of a UsagePlan resource.
--
-- 'name', 'usagePlan_name' - The name of a usage plan.
--
-- 'productCode', 'usagePlan_productCode' - The AWS Markeplace product identifier to associate with the usage plan
-- as a SaaS product on AWS Marketplace.
--
-- 'quota', 'usagePlan_quota' - The target maximum number of permitted requests per a given unit time
-- interval.
--
-- 'tags', 'usagePlan_tags' - The collection of tags. Each tag element is associated with a given
-- resource.
--
-- 'throttle', 'usagePlan_throttle' - A map containing method level throttling information for API stage in a
-- usage plan.
newUsagePlan ::
  UsagePlan
newUsagePlan :: UsagePlan
newUsagePlan =
  UsagePlan'
    { $sel:apiStages:UsagePlan' :: Maybe [ApiStage]
apiStages = forall a. Maybe a
Prelude.Nothing,
      $sel:description:UsagePlan' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:id:UsagePlan' :: Maybe Text
id = forall a. Maybe a
Prelude.Nothing,
      $sel:name:UsagePlan' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:productCode:UsagePlan' :: Maybe Text
productCode = forall a. Maybe a
Prelude.Nothing,
      $sel:quota:UsagePlan' :: Maybe QuotaSettings
quota = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:UsagePlan' :: Maybe (HashMap Text Text)
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:throttle:UsagePlan' :: Maybe ThrottleSettings
throttle = forall a. Maybe a
Prelude.Nothing
    }

-- | The associated API stages of a usage plan.
usagePlan_apiStages :: Lens.Lens' UsagePlan (Prelude.Maybe [ApiStage])
usagePlan_apiStages :: Lens' UsagePlan (Maybe [ApiStage])
usagePlan_apiStages = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsagePlan' {Maybe [ApiStage]
apiStages :: Maybe [ApiStage]
$sel:apiStages:UsagePlan' :: UsagePlan -> Maybe [ApiStage]
apiStages} -> Maybe [ApiStage]
apiStages) (\s :: UsagePlan
s@UsagePlan' {} Maybe [ApiStage]
a -> UsagePlan
s {$sel:apiStages:UsagePlan' :: Maybe [ApiStage]
apiStages = Maybe [ApiStage]
a} :: UsagePlan) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The description of a usage plan.
usagePlan_description :: Lens.Lens' UsagePlan (Prelude.Maybe Prelude.Text)
usagePlan_description :: Lens' UsagePlan (Maybe Text)
usagePlan_description = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsagePlan' {Maybe Text
description :: Maybe Text
$sel:description:UsagePlan' :: UsagePlan -> Maybe Text
description} -> Maybe Text
description) (\s :: UsagePlan
s@UsagePlan' {} Maybe Text
a -> UsagePlan
s {$sel:description:UsagePlan' :: Maybe Text
description = Maybe Text
a} :: UsagePlan)

-- | The identifier of a UsagePlan resource.
usagePlan_id :: Lens.Lens' UsagePlan (Prelude.Maybe Prelude.Text)
usagePlan_id :: Lens' UsagePlan (Maybe Text)
usagePlan_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsagePlan' {Maybe Text
id :: Maybe Text
$sel:id:UsagePlan' :: UsagePlan -> Maybe Text
id} -> Maybe Text
id) (\s :: UsagePlan
s@UsagePlan' {} Maybe Text
a -> UsagePlan
s {$sel:id:UsagePlan' :: Maybe Text
id = Maybe Text
a} :: UsagePlan)

-- | The name of a usage plan.
usagePlan_name :: Lens.Lens' UsagePlan (Prelude.Maybe Prelude.Text)
usagePlan_name :: Lens' UsagePlan (Maybe Text)
usagePlan_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsagePlan' {Maybe Text
name :: Maybe Text
$sel:name:UsagePlan' :: UsagePlan -> Maybe Text
name} -> Maybe Text
name) (\s :: UsagePlan
s@UsagePlan' {} Maybe Text
a -> UsagePlan
s {$sel:name:UsagePlan' :: Maybe Text
name = Maybe Text
a} :: UsagePlan)

-- | The AWS Markeplace product identifier to associate with the usage plan
-- as a SaaS product on AWS Marketplace.
usagePlan_productCode :: Lens.Lens' UsagePlan (Prelude.Maybe Prelude.Text)
usagePlan_productCode :: Lens' UsagePlan (Maybe Text)
usagePlan_productCode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsagePlan' {Maybe Text
productCode :: Maybe Text
$sel:productCode:UsagePlan' :: UsagePlan -> Maybe Text
productCode} -> Maybe Text
productCode) (\s :: UsagePlan
s@UsagePlan' {} Maybe Text
a -> UsagePlan
s {$sel:productCode:UsagePlan' :: Maybe Text
productCode = Maybe Text
a} :: UsagePlan)

-- | The target maximum number of permitted requests per a given unit time
-- interval.
usagePlan_quota :: Lens.Lens' UsagePlan (Prelude.Maybe QuotaSettings)
usagePlan_quota :: Lens' UsagePlan (Maybe QuotaSettings)
usagePlan_quota = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsagePlan' {Maybe QuotaSettings
quota :: Maybe QuotaSettings
$sel:quota:UsagePlan' :: UsagePlan -> Maybe QuotaSettings
quota} -> Maybe QuotaSettings
quota) (\s :: UsagePlan
s@UsagePlan' {} Maybe QuotaSettings
a -> UsagePlan
s {$sel:quota:UsagePlan' :: Maybe QuotaSettings
quota = Maybe QuotaSettings
a} :: UsagePlan)

-- | The collection of tags. Each tag element is associated with a given
-- resource.
usagePlan_tags :: Lens.Lens' UsagePlan (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
usagePlan_tags :: Lens' UsagePlan (Maybe (HashMap Text Text))
usagePlan_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsagePlan' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:UsagePlan' :: UsagePlan -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: UsagePlan
s@UsagePlan' {} Maybe (HashMap Text Text)
a -> UsagePlan
s {$sel:tags:UsagePlan' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: UsagePlan) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A map containing method level throttling information for API stage in a
-- usage plan.
usagePlan_throttle :: Lens.Lens' UsagePlan (Prelude.Maybe ThrottleSettings)
usagePlan_throttle :: Lens' UsagePlan (Maybe ThrottleSettings)
usagePlan_throttle = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsagePlan' {Maybe ThrottleSettings
throttle :: Maybe ThrottleSettings
$sel:throttle:UsagePlan' :: UsagePlan -> Maybe ThrottleSettings
throttle} -> Maybe ThrottleSettings
throttle) (\s :: UsagePlan
s@UsagePlan' {} Maybe ThrottleSettings
a -> UsagePlan
s {$sel:throttle:UsagePlan' :: Maybe ThrottleSettings
throttle = Maybe ThrottleSettings
a} :: UsagePlan)

instance Data.FromJSON UsagePlan where
  parseJSON :: Value -> Parser UsagePlan
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"UsagePlan"
      ( \Object
x ->
          Maybe [ApiStage]
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe QuotaSettings
-> Maybe (HashMap Text Text)
-> Maybe ThrottleSettings
-> UsagePlan
UsagePlan'
            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
"apiStages" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"description")
            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
"id")
            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
"name")
            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
"productCode")
            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
"quota")
            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
"tags" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"throttle")
      )

instance Prelude.Hashable UsagePlan where
  hashWithSalt :: Int -> UsagePlan -> Int
hashWithSalt Int
_salt UsagePlan' {Maybe [ApiStage]
Maybe Text
Maybe (HashMap Text Text)
Maybe QuotaSettings
Maybe ThrottleSettings
throttle :: Maybe ThrottleSettings
tags :: Maybe (HashMap Text Text)
quota :: Maybe QuotaSettings
productCode :: Maybe Text
name :: Maybe Text
id :: Maybe Text
description :: Maybe Text
apiStages :: Maybe [ApiStage]
$sel:throttle:UsagePlan' :: UsagePlan -> Maybe ThrottleSettings
$sel:tags:UsagePlan' :: UsagePlan -> Maybe (HashMap Text Text)
$sel:quota:UsagePlan' :: UsagePlan -> Maybe QuotaSettings
$sel:productCode:UsagePlan' :: UsagePlan -> Maybe Text
$sel:name:UsagePlan' :: UsagePlan -> Maybe Text
$sel:id:UsagePlan' :: UsagePlan -> Maybe Text
$sel:description:UsagePlan' :: UsagePlan -> Maybe Text
$sel:apiStages:UsagePlan' :: UsagePlan -> Maybe [ApiStage]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [ApiStage]
apiStages
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
productCode
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe QuotaSettings
quota
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ThrottleSettings
throttle

instance Prelude.NFData UsagePlan where
  rnf :: UsagePlan -> ()
rnf UsagePlan' {Maybe [ApiStage]
Maybe Text
Maybe (HashMap Text Text)
Maybe QuotaSettings
Maybe ThrottleSettings
throttle :: Maybe ThrottleSettings
tags :: Maybe (HashMap Text Text)
quota :: Maybe QuotaSettings
productCode :: Maybe Text
name :: Maybe Text
id :: Maybe Text
description :: Maybe Text
apiStages :: Maybe [ApiStage]
$sel:throttle:UsagePlan' :: UsagePlan -> Maybe ThrottleSettings
$sel:tags:UsagePlan' :: UsagePlan -> Maybe (HashMap Text Text)
$sel:quota:UsagePlan' :: UsagePlan -> Maybe QuotaSettings
$sel:productCode:UsagePlan' :: UsagePlan -> Maybe Text
$sel:name:UsagePlan' :: UsagePlan -> Maybe Text
$sel:id:UsagePlan' :: UsagePlan -> Maybe Text
$sel:description:UsagePlan' :: UsagePlan -> Maybe Text
$sel:apiStages:UsagePlan' :: UsagePlan -> Maybe [ApiStage]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [ApiStage]
apiStages
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
id
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
productCode
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe QuotaSettings
quota
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ThrottleSettings
throttle