{-# 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.UpdateStage
-- 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)
--
-- Changes information about a Stage resource.
module Amazonka.APIGateway.UpdateStage
  ( -- * Creating a Request
    UpdateStage (..),
    newUpdateStage,

    -- * Request Lenses
    updateStage_patchOperations,
    updateStage_restApiId,
    updateStage_stageName,

    -- * Destructuring the Response
    Stage (..),
    newStage,

    -- * Response Lenses
    stage_deploymentId,
    stage_variables,
    stage_accessLogSettings,
    stage_documentationVersion,
    stage_clientCertificateId,
    stage_tracingEnabled,
    stage_createdDate,
    stage_cacheClusterStatus,
    stage_methodSettings,
    stage_lastUpdatedDate,
    stage_cacheClusterSize,
    stage_webAclArn,
    stage_canarySettings,
    stage_cacheClusterEnabled,
    stage_stageName,
    stage_description,
    stage_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

-- | Requests API Gateway to change information about a Stage resource.
--
-- /See:/ 'newUpdateStage' smart constructor.
data UpdateStage = UpdateStage'
  { -- | A list of update operations to be applied to the specified resource and
    -- in the order specified in this list.
    UpdateStage -> Maybe [PatchOperation]
patchOperations :: Prelude.Maybe [PatchOperation],
    -- | [Required] The string identifier of the associated RestApi.
    UpdateStage -> Text
restApiId :: Prelude.Text,
    -- | [Required] The name of the Stage resource to change information about.
    UpdateStage -> Text
stageName :: Prelude.Text
  }
  deriving (UpdateStage -> UpdateStage -> Bool
(UpdateStage -> UpdateStage -> Bool)
-> (UpdateStage -> UpdateStage -> Bool) -> Eq UpdateStage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateStage -> UpdateStage -> Bool
$c/= :: UpdateStage -> UpdateStage -> Bool
== :: UpdateStage -> UpdateStage -> Bool
$c== :: UpdateStage -> UpdateStage -> Bool
Prelude.Eq, ReadPrec [UpdateStage]
ReadPrec UpdateStage
Int -> ReadS UpdateStage
ReadS [UpdateStage]
(Int -> ReadS UpdateStage)
-> ReadS [UpdateStage]
-> ReadPrec UpdateStage
-> ReadPrec [UpdateStage]
-> Read UpdateStage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateStage]
$creadListPrec :: ReadPrec [UpdateStage]
readPrec :: ReadPrec UpdateStage
$creadPrec :: ReadPrec UpdateStage
readList :: ReadS [UpdateStage]
$creadList :: ReadS [UpdateStage]
readsPrec :: Int -> ReadS UpdateStage
$creadsPrec :: Int -> ReadS UpdateStage
Prelude.Read, Int -> UpdateStage -> ShowS
[UpdateStage] -> ShowS
UpdateStage -> String
(Int -> UpdateStage -> ShowS)
-> (UpdateStage -> String)
-> ([UpdateStage] -> ShowS)
-> Show UpdateStage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateStage] -> ShowS
$cshowList :: [UpdateStage] -> ShowS
show :: UpdateStage -> String
$cshow :: UpdateStage -> String
showsPrec :: Int -> UpdateStage -> ShowS
$cshowsPrec :: Int -> UpdateStage -> ShowS
Prelude.Show, (forall x. UpdateStage -> Rep UpdateStage x)
-> (forall x. Rep UpdateStage x -> UpdateStage)
-> Generic UpdateStage
forall x. Rep UpdateStage x -> UpdateStage
forall x. UpdateStage -> Rep UpdateStage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateStage x -> UpdateStage
$cfrom :: forall x. UpdateStage -> Rep UpdateStage x
Prelude.Generic)

-- |
-- Create a value of 'UpdateStage' 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', 'updateStage_patchOperations' - A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
--
-- 'restApiId', 'updateStage_restApiId' - [Required] The string identifier of the associated RestApi.
--
-- 'stageName', 'updateStage_stageName' - [Required] The name of the Stage resource to change information about.
newUpdateStage ::
  -- | 'restApiId'
  Prelude.Text ->
  -- | 'stageName'
  Prelude.Text ->
  UpdateStage
newUpdateStage :: Text -> Text -> UpdateStage
newUpdateStage Text
pRestApiId_ Text
pStageName_ =
  UpdateStage' :: Maybe [PatchOperation] -> Text -> Text -> UpdateStage
UpdateStage'
    { $sel:patchOperations:UpdateStage' :: Maybe [PatchOperation]
patchOperations = Maybe [PatchOperation]
forall a. Maybe a
Prelude.Nothing,
      $sel:restApiId:UpdateStage' :: Text
restApiId = Text
pRestApiId_,
      $sel:stageName:UpdateStage' :: Text
stageName = Text
pStageName_
    }

-- | A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
updateStage_patchOperations :: Lens.Lens' UpdateStage (Prelude.Maybe [PatchOperation])
updateStage_patchOperations :: (Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> UpdateStage -> f UpdateStage
updateStage_patchOperations = (UpdateStage -> Maybe [PatchOperation])
-> (UpdateStage -> Maybe [PatchOperation] -> UpdateStage)
-> Lens
     UpdateStage
     UpdateStage
     (Maybe [PatchOperation])
     (Maybe [PatchOperation])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateStage' {Maybe [PatchOperation]
patchOperations :: Maybe [PatchOperation]
$sel:patchOperations:UpdateStage' :: UpdateStage -> Maybe [PatchOperation]
patchOperations} -> Maybe [PatchOperation]
patchOperations) (\s :: UpdateStage
s@UpdateStage' {} Maybe [PatchOperation]
a -> UpdateStage
s {$sel:patchOperations:UpdateStage' :: Maybe [PatchOperation]
patchOperations = Maybe [PatchOperation]
a} :: UpdateStage) ((Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
 -> UpdateStage -> f UpdateStage)
-> ((Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
    -> Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> (Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> UpdateStage
-> f UpdateStage
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 string identifier of the associated RestApi.
updateStage_restApiId :: Lens.Lens' UpdateStage Prelude.Text
updateStage_restApiId :: (Text -> f Text) -> UpdateStage -> f UpdateStage
updateStage_restApiId = (UpdateStage -> Text)
-> (UpdateStage -> Text -> UpdateStage)
-> Lens UpdateStage UpdateStage Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateStage' {Text
restApiId :: Text
$sel:restApiId:UpdateStage' :: UpdateStage -> Text
restApiId} -> Text
restApiId) (\s :: UpdateStage
s@UpdateStage' {} Text
a -> UpdateStage
s {$sel:restApiId:UpdateStage' :: Text
restApiId = Text
a} :: UpdateStage)

-- | [Required] The name of the Stage resource to change information about.
updateStage_stageName :: Lens.Lens' UpdateStage Prelude.Text
updateStage_stageName :: (Text -> f Text) -> UpdateStage -> f UpdateStage
updateStage_stageName = (UpdateStage -> Text)
-> (UpdateStage -> Text -> UpdateStage)
-> Lens UpdateStage UpdateStage Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateStage' {Text
stageName :: Text
$sel:stageName:UpdateStage' :: UpdateStage -> Text
stageName} -> Text
stageName) (\s :: UpdateStage
s@UpdateStage' {} Text
a -> UpdateStage
s {$sel:stageName:UpdateStage' :: Text
stageName = Text
a} :: UpdateStage)

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

instance Prelude.Hashable UpdateStage

instance Prelude.NFData UpdateStage

instance Core.ToHeaders UpdateStage where
  toHeaders :: UpdateStage -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateStage -> 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 UpdateStage where
  toJSON :: UpdateStage -> Value
toJSON UpdateStage' {Maybe [PatchOperation]
Text
stageName :: Text
restApiId :: Text
patchOperations :: Maybe [PatchOperation]
$sel:stageName:UpdateStage' :: UpdateStage -> Text
$sel:restApiId:UpdateStage' :: UpdateStage -> Text
$sel:patchOperations:UpdateStage' :: UpdateStage -> 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 UpdateStage where
  toPath :: UpdateStage -> ByteString
toPath UpdateStage' {Maybe [PatchOperation]
Text
stageName :: Text
restApiId :: Text
patchOperations :: Maybe [PatchOperation]
$sel:stageName:UpdateStage' :: UpdateStage -> Text
$sel:restApiId:UpdateStage' :: UpdateStage -> Text
$sel:patchOperations:UpdateStage' :: UpdateStage -> Maybe [PatchOperation]
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/restapis/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
restApiId,
        ByteString
"/stages/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
stageName
      ]

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