{-# 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.UpdateUsagePlan
-- 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)
--
-- Updates a usage plan of a given plan Id.
module Amazonka.APIGateway.UpdateUsagePlan
  ( -- * Creating a Request
    UpdateUsagePlan (..),
    newUpdateUsagePlan,

    -- * Request Lenses
    updateUsagePlan_patchOperations,
    updateUsagePlan_usagePlanId,

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

    -- * Response Lenses
    usagePlan_apiStages,
    usagePlan_name,
    usagePlan_id,
    usagePlan_throttle,
    usagePlan_quota,
    usagePlan_description,
    usagePlan_productCode,
    usagePlan_tags,
  )
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 PATCH request to update a usage plan of a given plan Id.
--
-- /See:/ 'newUpdateUsagePlan' smart constructor.
data UpdateUsagePlan = UpdateUsagePlan'
  { -- | A list of update operations to be applied to the specified resource and
    -- in the order specified in this list.
    UpdateUsagePlan -> Maybe [PatchOperation]
patchOperations :: Prelude.Maybe [PatchOperation],
    -- | [Required] The Id of the to-be-updated usage plan.
    UpdateUsagePlan -> Text
usagePlanId :: Prelude.Text
  }
  deriving (UpdateUsagePlan -> UpdateUsagePlan -> Bool
(UpdateUsagePlan -> UpdateUsagePlan -> Bool)
-> (UpdateUsagePlan -> UpdateUsagePlan -> Bool)
-> Eq UpdateUsagePlan
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateUsagePlan -> UpdateUsagePlan -> Bool
$c/= :: UpdateUsagePlan -> UpdateUsagePlan -> Bool
== :: UpdateUsagePlan -> UpdateUsagePlan -> Bool
$c== :: UpdateUsagePlan -> UpdateUsagePlan -> Bool
Prelude.Eq, ReadPrec [UpdateUsagePlan]
ReadPrec UpdateUsagePlan
Int -> ReadS UpdateUsagePlan
ReadS [UpdateUsagePlan]
(Int -> ReadS UpdateUsagePlan)
-> ReadS [UpdateUsagePlan]
-> ReadPrec UpdateUsagePlan
-> ReadPrec [UpdateUsagePlan]
-> Read UpdateUsagePlan
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateUsagePlan]
$creadListPrec :: ReadPrec [UpdateUsagePlan]
readPrec :: ReadPrec UpdateUsagePlan
$creadPrec :: ReadPrec UpdateUsagePlan
readList :: ReadS [UpdateUsagePlan]
$creadList :: ReadS [UpdateUsagePlan]
readsPrec :: Int -> ReadS UpdateUsagePlan
$creadsPrec :: Int -> ReadS UpdateUsagePlan
Prelude.Read, Int -> UpdateUsagePlan -> ShowS
[UpdateUsagePlan] -> ShowS
UpdateUsagePlan -> String
(Int -> UpdateUsagePlan -> ShowS)
-> (UpdateUsagePlan -> String)
-> ([UpdateUsagePlan] -> ShowS)
-> Show UpdateUsagePlan
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateUsagePlan] -> ShowS
$cshowList :: [UpdateUsagePlan] -> ShowS
show :: UpdateUsagePlan -> String
$cshow :: UpdateUsagePlan -> String
showsPrec :: Int -> UpdateUsagePlan -> ShowS
$cshowsPrec :: Int -> UpdateUsagePlan -> ShowS
Prelude.Show, (forall x. UpdateUsagePlan -> Rep UpdateUsagePlan x)
-> (forall x. Rep UpdateUsagePlan x -> UpdateUsagePlan)
-> Generic UpdateUsagePlan
forall x. Rep UpdateUsagePlan x -> UpdateUsagePlan
forall x. UpdateUsagePlan -> Rep UpdateUsagePlan x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateUsagePlan x -> UpdateUsagePlan
$cfrom :: forall x. UpdateUsagePlan -> Rep UpdateUsagePlan x
Prelude.Generic)

-- |
-- Create a value of 'UpdateUsagePlan' 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:
--
-- 'patchOperations', 'updateUsagePlan_patchOperations' - A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
--
-- 'usagePlanId', 'updateUsagePlan_usagePlanId' - [Required] The Id of the to-be-updated usage plan.
newUpdateUsagePlan ::
  -- | 'usagePlanId'
  Prelude.Text ->
  UpdateUsagePlan
newUpdateUsagePlan :: Text -> UpdateUsagePlan
newUpdateUsagePlan Text
pUsagePlanId_ =
  UpdateUsagePlan' :: Maybe [PatchOperation] -> Text -> UpdateUsagePlan
UpdateUsagePlan'
    { $sel:patchOperations:UpdateUsagePlan' :: Maybe [PatchOperation]
patchOperations = Maybe [PatchOperation]
forall a. Maybe a
Prelude.Nothing,
      $sel:usagePlanId:UpdateUsagePlan' :: Text
usagePlanId = Text
pUsagePlanId_
    }

-- | A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
updateUsagePlan_patchOperations :: Lens.Lens' UpdateUsagePlan (Prelude.Maybe [PatchOperation])
updateUsagePlan_patchOperations :: (Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> UpdateUsagePlan -> f UpdateUsagePlan
updateUsagePlan_patchOperations = (UpdateUsagePlan -> Maybe [PatchOperation])
-> (UpdateUsagePlan -> Maybe [PatchOperation] -> UpdateUsagePlan)
-> Lens
     UpdateUsagePlan
     UpdateUsagePlan
     (Maybe [PatchOperation])
     (Maybe [PatchOperation])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateUsagePlan' {Maybe [PatchOperation]
patchOperations :: Maybe [PatchOperation]
$sel:patchOperations:UpdateUsagePlan' :: UpdateUsagePlan -> Maybe [PatchOperation]
patchOperations} -> Maybe [PatchOperation]
patchOperations) (\s :: UpdateUsagePlan
s@UpdateUsagePlan' {} Maybe [PatchOperation]
a -> UpdateUsagePlan
s {$sel:patchOperations:UpdateUsagePlan' :: Maybe [PatchOperation]
patchOperations = Maybe [PatchOperation]
a} :: UpdateUsagePlan) ((Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
 -> UpdateUsagePlan -> f UpdateUsagePlan)
-> ((Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
    -> Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> (Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> UpdateUsagePlan
-> f UpdateUsagePlan
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [PatchOperation] [PatchOperation] [PatchOperation] [PatchOperation]
-> Iso
     (Maybe [PatchOperation])
     (Maybe [PatchOperation])
     (Maybe [PatchOperation])
     (Maybe [PatchOperation])
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 AnIso
  [PatchOperation] [PatchOperation] [PatchOperation] [PatchOperation]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | [Required] The Id of the to-be-updated usage plan.
updateUsagePlan_usagePlanId :: Lens.Lens' UpdateUsagePlan Prelude.Text
updateUsagePlan_usagePlanId :: (Text -> f Text) -> UpdateUsagePlan -> f UpdateUsagePlan
updateUsagePlan_usagePlanId = (UpdateUsagePlan -> Text)
-> (UpdateUsagePlan -> Text -> UpdateUsagePlan)
-> Lens UpdateUsagePlan UpdateUsagePlan Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateUsagePlan' {Text
usagePlanId :: Text
$sel:usagePlanId:UpdateUsagePlan' :: UpdateUsagePlan -> Text
usagePlanId} -> Text
usagePlanId) (\s :: UpdateUsagePlan
s@UpdateUsagePlan' {} Text
a -> UpdateUsagePlan
s {$sel:usagePlanId:UpdateUsagePlan' :: Text
usagePlanId = Text
a} :: UpdateUsagePlan)

instance Core.AWSRequest UpdateUsagePlan where
  type AWSResponse UpdateUsagePlan = UsagePlan
  request :: UpdateUsagePlan -> Request UpdateUsagePlan
request = Service -> UpdateUsagePlan -> Request UpdateUsagePlan
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.patchJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateUsagePlan
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateUsagePlan)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse UpdateUsagePlan))
-> Logger
-> Service
-> Proxy UpdateUsagePlan
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateUsagePlan)))
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 UsagePlan
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable UpdateUsagePlan

instance Prelude.NFData UpdateUsagePlan

instance Core.ToHeaders UpdateUsagePlan where
  toHeaders :: UpdateUsagePlan -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateUsagePlan -> 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 UpdateUsagePlan where
  toJSON :: UpdateUsagePlan -> Value
toJSON UpdateUsagePlan' {Maybe [PatchOperation]
Text
usagePlanId :: Text
patchOperations :: Maybe [PatchOperation]
$sel:usagePlanId:UpdateUsagePlan' :: UpdateUsagePlan -> Text
$sel:patchOperations:UpdateUsagePlan' :: UpdateUsagePlan -> Maybe [PatchOperation]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"patchOperations" Text -> [PatchOperation] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([PatchOperation] -> Pair) -> Maybe [PatchOperation] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [PatchOperation]
patchOperations
          ]
      )

instance Core.ToPath UpdateUsagePlan where
  toPath :: UpdateUsagePlan -> ByteString
toPath UpdateUsagePlan' {Maybe [PatchOperation]
Text
usagePlanId :: Text
patchOperations :: Maybe [PatchOperation]
$sel:usagePlanId:UpdateUsagePlan' :: UpdateUsagePlan -> Text
$sel:patchOperations:UpdateUsagePlan' :: UpdateUsagePlan -> Maybe [PatchOperation]
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/usageplans/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
usagePlanId]

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