{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.CreateUsagePlan
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a usage plan with the throttle and quota limits, as well as the
-- associated API stages, specified in the payload.
module Amazonka.APIGateway.CreateUsagePlan
  ( -- * Creating a Request
    CreateUsagePlan (..),
    newCreateUsagePlan,

    -- * Request Lenses
    createUsagePlan_apiStages,
    createUsagePlan_description,
    createUsagePlan_quota,
    createUsagePlan_tags,
    createUsagePlan_throttle,
    createUsagePlan_name,

    -- * Destructuring the Response
    UsagePlan (..),
    newUsagePlan,

    -- * Response Lenses
    usagePlan_apiStages,
    usagePlan_description,
    usagePlan_id,
    usagePlan_name,
    usagePlan_productCode,
    usagePlan_quota,
    usagePlan_tags,
    usagePlan_throttle,
  )
where

import Amazonka.APIGateway.Types
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
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | The POST request to create a usage plan with the name, description,
-- throttle limits and quota limits, as well as the associated API stages,
-- specified in the payload.
--
-- /See:/ 'newCreateUsagePlan' smart constructor.
data CreateUsagePlan = CreateUsagePlan'
  { -- | The associated API stages of the usage plan.
    CreateUsagePlan -> Maybe [ApiStage]
apiStages :: Prelude.Maybe [ApiStage],
    -- | The description of the usage plan.
    CreateUsagePlan -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The quota of the usage plan.
    CreateUsagePlan -> Maybe QuotaSettings
quota :: Prelude.Maybe QuotaSettings,
    -- | The key-value map of strings. The valid character set is
    -- [a-zA-Z+-=._:\/]. The tag key can be up to 128 characters and must not
    -- start with @aws:@. The tag value can be up to 256 characters.
    CreateUsagePlan -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The throttling limits of the usage plan.
    CreateUsagePlan -> Maybe ThrottleSettings
throttle :: Prelude.Maybe ThrottleSettings,
    -- | The name of the usage plan.
    CreateUsagePlan -> Text
name :: Prelude.Text
  }
  deriving (CreateUsagePlan -> CreateUsagePlan -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateUsagePlan -> CreateUsagePlan -> Bool
$c/= :: CreateUsagePlan -> CreateUsagePlan -> Bool
== :: CreateUsagePlan -> CreateUsagePlan -> Bool
$c== :: CreateUsagePlan -> CreateUsagePlan -> Bool
Prelude.Eq, ReadPrec [CreateUsagePlan]
ReadPrec CreateUsagePlan
Int -> ReadS CreateUsagePlan
ReadS [CreateUsagePlan]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateUsagePlan]
$creadListPrec :: ReadPrec [CreateUsagePlan]
readPrec :: ReadPrec CreateUsagePlan
$creadPrec :: ReadPrec CreateUsagePlan
readList :: ReadS [CreateUsagePlan]
$creadList :: ReadS [CreateUsagePlan]
readsPrec :: Int -> ReadS CreateUsagePlan
$creadsPrec :: Int -> ReadS CreateUsagePlan
Prelude.Read, Int -> CreateUsagePlan -> ShowS
[CreateUsagePlan] -> ShowS
CreateUsagePlan -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateUsagePlan] -> ShowS
$cshowList :: [CreateUsagePlan] -> ShowS
show :: CreateUsagePlan -> String
$cshow :: CreateUsagePlan -> String
showsPrec :: Int -> CreateUsagePlan -> ShowS
$cshowsPrec :: Int -> CreateUsagePlan -> ShowS
Prelude.Show, forall x. Rep CreateUsagePlan x -> CreateUsagePlan
forall x. CreateUsagePlan -> Rep CreateUsagePlan x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateUsagePlan x -> CreateUsagePlan
$cfrom :: forall x. CreateUsagePlan -> Rep CreateUsagePlan x
Prelude.Generic)

-- |
-- Create a value of 'CreateUsagePlan' 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', 'createUsagePlan_apiStages' - The associated API stages of the usage plan.
--
-- 'description', 'createUsagePlan_description' - The description of the usage plan.
--
-- 'quota', 'createUsagePlan_quota' - The quota of the usage plan.
--
-- 'tags', 'createUsagePlan_tags' - The key-value map of strings. The valid character set is
-- [a-zA-Z+-=._:\/]. The tag key can be up to 128 characters and must not
-- start with @aws:@. The tag value can be up to 256 characters.
--
-- 'throttle', 'createUsagePlan_throttle' - The throttling limits of the usage plan.
--
-- 'name', 'createUsagePlan_name' - The name of the usage plan.
newCreateUsagePlan ::
  -- | 'name'
  Prelude.Text ->
  CreateUsagePlan
newCreateUsagePlan :: Text -> CreateUsagePlan
newCreateUsagePlan Text
pName_ =
  CreateUsagePlan'
    { $sel:apiStages:CreateUsagePlan' :: Maybe [ApiStage]
apiStages = forall a. Maybe a
Prelude.Nothing,
      $sel:description:CreateUsagePlan' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:quota:CreateUsagePlan' :: Maybe QuotaSettings
quota = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateUsagePlan' :: Maybe (HashMap Text Text)
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:throttle:CreateUsagePlan' :: Maybe ThrottleSettings
throttle = forall a. Maybe a
Prelude.Nothing,
      $sel:name:CreateUsagePlan' :: Text
name = Text
pName_
    }

-- | The associated API stages of the usage plan.
createUsagePlan_apiStages :: Lens.Lens' CreateUsagePlan (Prelude.Maybe [ApiStage])
createUsagePlan_apiStages :: Lens' CreateUsagePlan (Maybe [ApiStage])
createUsagePlan_apiStages = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUsagePlan' {Maybe [ApiStage]
apiStages :: Maybe [ApiStage]
$sel:apiStages:CreateUsagePlan' :: CreateUsagePlan -> Maybe [ApiStage]
apiStages} -> Maybe [ApiStage]
apiStages) (\s :: CreateUsagePlan
s@CreateUsagePlan' {} Maybe [ApiStage]
a -> CreateUsagePlan
s {$sel:apiStages:CreateUsagePlan' :: Maybe [ApiStage]
apiStages = Maybe [ApiStage]
a} :: CreateUsagePlan) 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 the usage plan.
createUsagePlan_description :: Lens.Lens' CreateUsagePlan (Prelude.Maybe Prelude.Text)
createUsagePlan_description :: Lens' CreateUsagePlan (Maybe Text)
createUsagePlan_description = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUsagePlan' {Maybe Text
description :: Maybe Text
$sel:description:CreateUsagePlan' :: CreateUsagePlan -> Maybe Text
description} -> Maybe Text
description) (\s :: CreateUsagePlan
s@CreateUsagePlan' {} Maybe Text
a -> CreateUsagePlan
s {$sel:description:CreateUsagePlan' :: Maybe Text
description = Maybe Text
a} :: CreateUsagePlan)

-- | The quota of the usage plan.
createUsagePlan_quota :: Lens.Lens' CreateUsagePlan (Prelude.Maybe QuotaSettings)
createUsagePlan_quota :: Lens' CreateUsagePlan (Maybe QuotaSettings)
createUsagePlan_quota = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUsagePlan' {Maybe QuotaSettings
quota :: Maybe QuotaSettings
$sel:quota:CreateUsagePlan' :: CreateUsagePlan -> Maybe QuotaSettings
quota} -> Maybe QuotaSettings
quota) (\s :: CreateUsagePlan
s@CreateUsagePlan' {} Maybe QuotaSettings
a -> CreateUsagePlan
s {$sel:quota:CreateUsagePlan' :: Maybe QuotaSettings
quota = Maybe QuotaSettings
a} :: CreateUsagePlan)

-- | The key-value map of strings. The valid character set is
-- [a-zA-Z+-=._:\/]. The tag key can be up to 128 characters and must not
-- start with @aws:@. The tag value can be up to 256 characters.
createUsagePlan_tags :: Lens.Lens' CreateUsagePlan (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createUsagePlan_tags :: Lens' CreateUsagePlan (Maybe (HashMap Text Text))
createUsagePlan_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUsagePlan' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateUsagePlan' :: CreateUsagePlan -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: CreateUsagePlan
s@CreateUsagePlan' {} Maybe (HashMap Text Text)
a -> CreateUsagePlan
s {$sel:tags:CreateUsagePlan' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: CreateUsagePlan) 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 throttling limits of the usage plan.
createUsagePlan_throttle :: Lens.Lens' CreateUsagePlan (Prelude.Maybe ThrottleSettings)
createUsagePlan_throttle :: Lens' CreateUsagePlan (Maybe ThrottleSettings)
createUsagePlan_throttle = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUsagePlan' {Maybe ThrottleSettings
throttle :: Maybe ThrottleSettings
$sel:throttle:CreateUsagePlan' :: CreateUsagePlan -> Maybe ThrottleSettings
throttle} -> Maybe ThrottleSettings
throttle) (\s :: CreateUsagePlan
s@CreateUsagePlan' {} Maybe ThrottleSettings
a -> CreateUsagePlan
s {$sel:throttle:CreateUsagePlan' :: Maybe ThrottleSettings
throttle = Maybe ThrottleSettings
a} :: CreateUsagePlan)

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

instance Core.AWSRequest CreateUsagePlan where
  type AWSResponse CreateUsagePlan = UsagePlan
  request :: (Service -> Service) -> CreateUsagePlan -> Request CreateUsagePlan
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy CreateUsagePlan
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateUsagePlan)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> forall a. FromJSON a => Object -> Either String a
Data.eitherParseJSON Object
x)

instance Prelude.Hashable CreateUsagePlan where
  hashWithSalt :: Int -> CreateUsagePlan -> Int
hashWithSalt Int
_salt CreateUsagePlan' {Maybe [ApiStage]
Maybe Text
Maybe (HashMap Text Text)
Maybe QuotaSettings
Maybe ThrottleSettings
Text
name :: Text
throttle :: Maybe ThrottleSettings
tags :: Maybe (HashMap Text Text)
quota :: Maybe QuotaSettings
description :: Maybe Text
apiStages :: Maybe [ApiStage]
$sel:name:CreateUsagePlan' :: CreateUsagePlan -> Text
$sel:throttle:CreateUsagePlan' :: CreateUsagePlan -> Maybe ThrottleSettings
$sel:tags:CreateUsagePlan' :: CreateUsagePlan -> Maybe (HashMap Text Text)
$sel:quota:CreateUsagePlan' :: CreateUsagePlan -> Maybe QuotaSettings
$sel:description:CreateUsagePlan' :: CreateUsagePlan -> Maybe Text
$sel:apiStages:CreateUsagePlan' :: CreateUsagePlan -> 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 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
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name

instance Prelude.NFData CreateUsagePlan where
  rnf :: CreateUsagePlan -> ()
rnf CreateUsagePlan' {Maybe [ApiStage]
Maybe Text
Maybe (HashMap Text Text)
Maybe QuotaSettings
Maybe ThrottleSettings
Text
name :: Text
throttle :: Maybe ThrottleSettings
tags :: Maybe (HashMap Text Text)
quota :: Maybe QuotaSettings
description :: Maybe Text
apiStages :: Maybe [ApiStage]
$sel:name:CreateUsagePlan' :: CreateUsagePlan -> Text
$sel:throttle:CreateUsagePlan' :: CreateUsagePlan -> Maybe ThrottleSettings
$sel:tags:CreateUsagePlan' :: CreateUsagePlan -> Maybe (HashMap Text Text)
$sel:quota:CreateUsagePlan' :: CreateUsagePlan -> Maybe QuotaSettings
$sel:description:CreateUsagePlan' :: CreateUsagePlan -> Maybe Text
$sel:apiStages:CreateUsagePlan' :: CreateUsagePlan -> 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 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
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name

instance Data.ToHeaders CreateUsagePlan where
  toHeaders :: CreateUsagePlan -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Accept"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# (ByteString
"application/json" :: Prelude.ByteString)
          ]
      )

instance Data.ToJSON CreateUsagePlan where
  toJSON :: CreateUsagePlan -> Value
toJSON CreateUsagePlan' {Maybe [ApiStage]
Maybe Text
Maybe (HashMap Text Text)
Maybe QuotaSettings
Maybe ThrottleSettings
Text
name :: Text
throttle :: Maybe ThrottleSettings
tags :: Maybe (HashMap Text Text)
quota :: Maybe QuotaSettings
description :: Maybe Text
apiStages :: Maybe [ApiStage]
$sel:name:CreateUsagePlan' :: CreateUsagePlan -> Text
$sel:throttle:CreateUsagePlan' :: CreateUsagePlan -> Maybe ThrottleSettings
$sel:tags:CreateUsagePlan' :: CreateUsagePlan -> Maybe (HashMap Text Text)
$sel:quota:CreateUsagePlan' :: CreateUsagePlan -> Maybe QuotaSettings
$sel:description:CreateUsagePlan' :: CreateUsagePlan -> Maybe Text
$sel:apiStages:CreateUsagePlan' :: CreateUsagePlan -> Maybe [ApiStage]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"apiStages" 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 [ApiStage]
apiStages,
            (Key
"description" 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 Text
description,
            (Key
"quota" 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 QuotaSettings
quota,
            (Key
"tags" 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 (HashMap Text Text)
tags,
            (Key
"throttle" 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 ThrottleSettings
throttle,
            forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name)
          ]
      )

instance Data.ToPath CreateUsagePlan where
  toPath :: CreateUsagePlan -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/usageplans"

instance Data.ToQuery CreateUsagePlan where
  toQuery :: CreateUsagePlan -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty