{-# 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.CreateUsagePlanKey
-- 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)
--
-- Creates a usage plan key for adding an existing API key to a usage plan.
module Amazonka.APIGateway.CreateUsagePlanKey
  ( -- * Creating a Request
    CreateUsagePlanKey (..),
    newCreateUsagePlanKey,

    -- * Request Lenses
    createUsagePlanKey_usagePlanId,
    createUsagePlanKey_keyId,
    createUsagePlanKey_keyType,

    -- * Destructuring the Response
    UsagePlanKey (..),
    newUsagePlanKey,

    -- * Response Lenses
    usagePlanKey_value,
    usagePlanKey_name,
    usagePlanKey_id,
    usagePlanKey_type,
  )
where

import Amazonka.APIGateway.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 key for adding an existing API
-- key to a usage plan.
--
-- /See:/ 'newCreateUsagePlanKey' smart constructor.
data CreateUsagePlanKey = CreateUsagePlanKey'
  { -- | [Required] The Id of the UsagePlan resource representing the usage plan
    -- containing the to-be-created UsagePlanKey resource representing a plan
    -- customer.
    CreateUsagePlanKey -> Text
usagePlanId :: Prelude.Text,
    -- | [Required] The identifier of a UsagePlanKey resource for a plan
    -- customer.
    CreateUsagePlanKey -> Text
keyId :: Prelude.Text,
    -- | [Required] The type of a UsagePlanKey resource for a plan customer.
    CreateUsagePlanKey -> Text
keyType :: Prelude.Text
  }
  deriving (CreateUsagePlanKey -> CreateUsagePlanKey -> Bool
(CreateUsagePlanKey -> CreateUsagePlanKey -> Bool)
-> (CreateUsagePlanKey -> CreateUsagePlanKey -> Bool)
-> Eq CreateUsagePlanKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateUsagePlanKey -> CreateUsagePlanKey -> Bool
$c/= :: CreateUsagePlanKey -> CreateUsagePlanKey -> Bool
== :: CreateUsagePlanKey -> CreateUsagePlanKey -> Bool
$c== :: CreateUsagePlanKey -> CreateUsagePlanKey -> Bool
Prelude.Eq, ReadPrec [CreateUsagePlanKey]
ReadPrec CreateUsagePlanKey
Int -> ReadS CreateUsagePlanKey
ReadS [CreateUsagePlanKey]
(Int -> ReadS CreateUsagePlanKey)
-> ReadS [CreateUsagePlanKey]
-> ReadPrec CreateUsagePlanKey
-> ReadPrec [CreateUsagePlanKey]
-> Read CreateUsagePlanKey
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateUsagePlanKey]
$creadListPrec :: ReadPrec [CreateUsagePlanKey]
readPrec :: ReadPrec CreateUsagePlanKey
$creadPrec :: ReadPrec CreateUsagePlanKey
readList :: ReadS [CreateUsagePlanKey]
$creadList :: ReadS [CreateUsagePlanKey]
readsPrec :: Int -> ReadS CreateUsagePlanKey
$creadsPrec :: Int -> ReadS CreateUsagePlanKey
Prelude.Read, Int -> CreateUsagePlanKey -> ShowS
[CreateUsagePlanKey] -> ShowS
CreateUsagePlanKey -> String
(Int -> CreateUsagePlanKey -> ShowS)
-> (CreateUsagePlanKey -> String)
-> ([CreateUsagePlanKey] -> ShowS)
-> Show CreateUsagePlanKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateUsagePlanKey] -> ShowS
$cshowList :: [CreateUsagePlanKey] -> ShowS
show :: CreateUsagePlanKey -> String
$cshow :: CreateUsagePlanKey -> String
showsPrec :: Int -> CreateUsagePlanKey -> ShowS
$cshowsPrec :: Int -> CreateUsagePlanKey -> ShowS
Prelude.Show, (forall x. CreateUsagePlanKey -> Rep CreateUsagePlanKey x)
-> (forall x. Rep CreateUsagePlanKey x -> CreateUsagePlanKey)
-> Generic CreateUsagePlanKey
forall x. Rep CreateUsagePlanKey x -> CreateUsagePlanKey
forall x. CreateUsagePlanKey -> Rep CreateUsagePlanKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateUsagePlanKey x -> CreateUsagePlanKey
$cfrom :: forall x. CreateUsagePlanKey -> Rep CreateUsagePlanKey x
Prelude.Generic)

-- |
-- Create a value of 'CreateUsagePlanKey' 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:
--
-- 'usagePlanId', 'createUsagePlanKey_usagePlanId' - [Required] The Id of the UsagePlan resource representing the usage plan
-- containing the to-be-created UsagePlanKey resource representing a plan
-- customer.
--
-- 'keyId', 'createUsagePlanKey_keyId' - [Required] The identifier of a UsagePlanKey resource for a plan
-- customer.
--
-- 'keyType', 'createUsagePlanKey_keyType' - [Required] The type of a UsagePlanKey resource for a plan customer.
newCreateUsagePlanKey ::
  -- | 'usagePlanId'
  Prelude.Text ->
  -- | 'keyId'
  Prelude.Text ->
  -- | 'keyType'
  Prelude.Text ->
  CreateUsagePlanKey
newCreateUsagePlanKey :: Text -> Text -> Text -> CreateUsagePlanKey
newCreateUsagePlanKey Text
pUsagePlanId_ Text
pKeyId_ Text
pKeyType_ =
  CreateUsagePlanKey' :: Text -> Text -> Text -> CreateUsagePlanKey
CreateUsagePlanKey'
    { $sel:usagePlanId:CreateUsagePlanKey' :: Text
usagePlanId = Text
pUsagePlanId_,
      $sel:keyId:CreateUsagePlanKey' :: Text
keyId = Text
pKeyId_,
      $sel:keyType:CreateUsagePlanKey' :: Text
keyType = Text
pKeyType_
    }

-- | [Required] The Id of the UsagePlan resource representing the usage plan
-- containing the to-be-created UsagePlanKey resource representing a plan
-- customer.
createUsagePlanKey_usagePlanId :: Lens.Lens' CreateUsagePlanKey Prelude.Text
createUsagePlanKey_usagePlanId :: (Text -> f Text) -> CreateUsagePlanKey -> f CreateUsagePlanKey
createUsagePlanKey_usagePlanId = (CreateUsagePlanKey -> Text)
-> (CreateUsagePlanKey -> Text -> CreateUsagePlanKey)
-> Lens CreateUsagePlanKey CreateUsagePlanKey Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUsagePlanKey' {Text
usagePlanId :: Text
$sel:usagePlanId:CreateUsagePlanKey' :: CreateUsagePlanKey -> Text
usagePlanId} -> Text
usagePlanId) (\s :: CreateUsagePlanKey
s@CreateUsagePlanKey' {} Text
a -> CreateUsagePlanKey
s {$sel:usagePlanId:CreateUsagePlanKey' :: Text
usagePlanId = Text
a} :: CreateUsagePlanKey)

-- | [Required] The identifier of a UsagePlanKey resource for a plan
-- customer.
createUsagePlanKey_keyId :: Lens.Lens' CreateUsagePlanKey Prelude.Text
createUsagePlanKey_keyId :: (Text -> f Text) -> CreateUsagePlanKey -> f CreateUsagePlanKey
createUsagePlanKey_keyId = (CreateUsagePlanKey -> Text)
-> (CreateUsagePlanKey -> Text -> CreateUsagePlanKey)
-> Lens CreateUsagePlanKey CreateUsagePlanKey Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUsagePlanKey' {Text
keyId :: Text
$sel:keyId:CreateUsagePlanKey' :: CreateUsagePlanKey -> Text
keyId} -> Text
keyId) (\s :: CreateUsagePlanKey
s@CreateUsagePlanKey' {} Text
a -> CreateUsagePlanKey
s {$sel:keyId:CreateUsagePlanKey' :: Text
keyId = Text
a} :: CreateUsagePlanKey)

-- | [Required] The type of a UsagePlanKey resource for a plan customer.
createUsagePlanKey_keyType :: Lens.Lens' CreateUsagePlanKey Prelude.Text
createUsagePlanKey_keyType :: (Text -> f Text) -> CreateUsagePlanKey -> f CreateUsagePlanKey
createUsagePlanKey_keyType = (CreateUsagePlanKey -> Text)
-> (CreateUsagePlanKey -> Text -> CreateUsagePlanKey)
-> Lens CreateUsagePlanKey CreateUsagePlanKey Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUsagePlanKey' {Text
keyType :: Text
$sel:keyType:CreateUsagePlanKey' :: CreateUsagePlanKey -> Text
keyType} -> Text
keyType) (\s :: CreateUsagePlanKey
s@CreateUsagePlanKey' {} Text
a -> CreateUsagePlanKey
s {$sel:keyType:CreateUsagePlanKey' :: Text
keyType = Text
a} :: CreateUsagePlanKey)

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

instance Prelude.Hashable CreateUsagePlanKey

instance Prelude.NFData CreateUsagePlanKey

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

instance Core.ToJSON CreateUsagePlanKey where
  toJSON :: CreateUsagePlanKey -> Value
toJSON CreateUsagePlanKey' {Text
keyType :: Text
keyId :: Text
usagePlanId :: Text
$sel:keyType:CreateUsagePlanKey' :: CreateUsagePlanKey -> Text
$sel:keyId:CreateUsagePlanKey' :: CreateUsagePlanKey -> Text
$sel:usagePlanId:CreateUsagePlanKey' :: CreateUsagePlanKey -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"keyId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
keyId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"keyType" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
keyType)
          ]
      )

instance Core.ToPath CreateUsagePlanKey where
  toPath :: CreateUsagePlanKey -> ByteString
toPath CreateUsagePlanKey' {Text
keyType :: Text
keyId :: Text
usagePlanId :: Text
$sel:keyType:CreateUsagePlanKey' :: CreateUsagePlanKey -> Text
$sel:keyId:CreateUsagePlanKey' :: CreateUsagePlanKey -> Text
$sel:usagePlanId:CreateUsagePlanKey' :: CreateUsagePlanKey -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/usageplans/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
usagePlanId, ByteString
"/keys"]

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