{-# 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.UpdateBasePathMapping
-- 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 the BasePathMapping resource.
module Amazonka.APIGateway.UpdateBasePathMapping
  ( -- * Creating a Request
    UpdateBasePathMapping (..),
    newUpdateBasePathMapping,

    -- * Request Lenses
    updateBasePathMapping_patchOperations,
    updateBasePathMapping_domainName,
    updateBasePathMapping_basePath,

    -- * Destructuring the Response
    BasePathMapping (..),
    newBasePathMapping,

    -- * Response Lenses
    basePathMapping_stage,
    basePathMapping_basePath,
    basePathMapping_restApiId,
  )
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

-- | A request to change information about the BasePathMapping resource.
--
-- /See:/ 'newUpdateBasePathMapping' smart constructor.
data UpdateBasePathMapping = UpdateBasePathMapping'
  { -- | A list of update operations to be applied to the specified resource and
    -- in the order specified in this list.
    UpdateBasePathMapping -> Maybe [PatchOperation]
patchOperations :: Prelude.Maybe [PatchOperation],
    -- | [Required] The domain name of the BasePathMapping resource to change.
    UpdateBasePathMapping -> Text
domainName :: Prelude.Text,
    -- | [Required] The base path of the BasePathMapping resource to change.
    --
    -- To specify an empty base path, set this parameter to @\'(none)\'@.
    UpdateBasePathMapping -> Text
basePath :: Prelude.Text
  }
  deriving (UpdateBasePathMapping -> UpdateBasePathMapping -> Bool
(UpdateBasePathMapping -> UpdateBasePathMapping -> Bool)
-> (UpdateBasePathMapping -> UpdateBasePathMapping -> Bool)
-> Eq UpdateBasePathMapping
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateBasePathMapping -> UpdateBasePathMapping -> Bool
$c/= :: UpdateBasePathMapping -> UpdateBasePathMapping -> Bool
== :: UpdateBasePathMapping -> UpdateBasePathMapping -> Bool
$c== :: UpdateBasePathMapping -> UpdateBasePathMapping -> Bool
Prelude.Eq, ReadPrec [UpdateBasePathMapping]
ReadPrec UpdateBasePathMapping
Int -> ReadS UpdateBasePathMapping
ReadS [UpdateBasePathMapping]
(Int -> ReadS UpdateBasePathMapping)
-> ReadS [UpdateBasePathMapping]
-> ReadPrec UpdateBasePathMapping
-> ReadPrec [UpdateBasePathMapping]
-> Read UpdateBasePathMapping
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateBasePathMapping]
$creadListPrec :: ReadPrec [UpdateBasePathMapping]
readPrec :: ReadPrec UpdateBasePathMapping
$creadPrec :: ReadPrec UpdateBasePathMapping
readList :: ReadS [UpdateBasePathMapping]
$creadList :: ReadS [UpdateBasePathMapping]
readsPrec :: Int -> ReadS UpdateBasePathMapping
$creadsPrec :: Int -> ReadS UpdateBasePathMapping
Prelude.Read, Int -> UpdateBasePathMapping -> ShowS
[UpdateBasePathMapping] -> ShowS
UpdateBasePathMapping -> String
(Int -> UpdateBasePathMapping -> ShowS)
-> (UpdateBasePathMapping -> String)
-> ([UpdateBasePathMapping] -> ShowS)
-> Show UpdateBasePathMapping
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateBasePathMapping] -> ShowS
$cshowList :: [UpdateBasePathMapping] -> ShowS
show :: UpdateBasePathMapping -> String
$cshow :: UpdateBasePathMapping -> String
showsPrec :: Int -> UpdateBasePathMapping -> ShowS
$cshowsPrec :: Int -> UpdateBasePathMapping -> ShowS
Prelude.Show, (forall x. UpdateBasePathMapping -> Rep UpdateBasePathMapping x)
-> (forall x. Rep UpdateBasePathMapping x -> UpdateBasePathMapping)
-> Generic UpdateBasePathMapping
forall x. Rep UpdateBasePathMapping x -> UpdateBasePathMapping
forall x. UpdateBasePathMapping -> Rep UpdateBasePathMapping x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateBasePathMapping x -> UpdateBasePathMapping
$cfrom :: forall x. UpdateBasePathMapping -> Rep UpdateBasePathMapping x
Prelude.Generic)

-- |
-- Create a value of 'UpdateBasePathMapping' 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', 'updateBasePathMapping_patchOperations' - A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
--
-- 'domainName', 'updateBasePathMapping_domainName' - [Required] The domain name of the BasePathMapping resource to change.
--
-- 'basePath', 'updateBasePathMapping_basePath' - [Required] The base path of the BasePathMapping resource to change.
--
-- To specify an empty base path, set this parameter to @\'(none)\'@.
newUpdateBasePathMapping ::
  -- | 'domainName'
  Prelude.Text ->
  -- | 'basePath'
  Prelude.Text ->
  UpdateBasePathMapping
newUpdateBasePathMapping :: Text -> Text -> UpdateBasePathMapping
newUpdateBasePathMapping Text
pDomainName_ Text
pBasePath_ =
  UpdateBasePathMapping' :: Maybe [PatchOperation] -> Text -> Text -> UpdateBasePathMapping
UpdateBasePathMapping'
    { $sel:patchOperations:UpdateBasePathMapping' :: Maybe [PatchOperation]
patchOperations =
        Maybe [PatchOperation]
forall a. Maybe a
Prelude.Nothing,
      $sel:domainName:UpdateBasePathMapping' :: Text
domainName = Text
pDomainName_,
      $sel:basePath:UpdateBasePathMapping' :: Text
basePath = Text
pBasePath_
    }

-- | A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
updateBasePathMapping_patchOperations :: Lens.Lens' UpdateBasePathMapping (Prelude.Maybe [PatchOperation])
updateBasePathMapping_patchOperations :: (Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> UpdateBasePathMapping -> f UpdateBasePathMapping
updateBasePathMapping_patchOperations = (UpdateBasePathMapping -> Maybe [PatchOperation])
-> (UpdateBasePathMapping
    -> Maybe [PatchOperation] -> UpdateBasePathMapping)
-> Lens
     UpdateBasePathMapping
     UpdateBasePathMapping
     (Maybe [PatchOperation])
     (Maybe [PatchOperation])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateBasePathMapping' {Maybe [PatchOperation]
patchOperations :: Maybe [PatchOperation]
$sel:patchOperations:UpdateBasePathMapping' :: UpdateBasePathMapping -> Maybe [PatchOperation]
patchOperations} -> Maybe [PatchOperation]
patchOperations) (\s :: UpdateBasePathMapping
s@UpdateBasePathMapping' {} Maybe [PatchOperation]
a -> UpdateBasePathMapping
s {$sel:patchOperations:UpdateBasePathMapping' :: Maybe [PatchOperation]
patchOperations = Maybe [PatchOperation]
a} :: UpdateBasePathMapping) ((Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
 -> UpdateBasePathMapping -> f UpdateBasePathMapping)
-> ((Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
    -> Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> (Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> UpdateBasePathMapping
-> f UpdateBasePathMapping
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 domain name of the BasePathMapping resource to change.
updateBasePathMapping_domainName :: Lens.Lens' UpdateBasePathMapping Prelude.Text
updateBasePathMapping_domainName :: (Text -> f Text)
-> UpdateBasePathMapping -> f UpdateBasePathMapping
updateBasePathMapping_domainName = (UpdateBasePathMapping -> Text)
-> (UpdateBasePathMapping -> Text -> UpdateBasePathMapping)
-> Lens UpdateBasePathMapping UpdateBasePathMapping Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateBasePathMapping' {Text
domainName :: Text
$sel:domainName:UpdateBasePathMapping' :: UpdateBasePathMapping -> Text
domainName} -> Text
domainName) (\s :: UpdateBasePathMapping
s@UpdateBasePathMapping' {} Text
a -> UpdateBasePathMapping
s {$sel:domainName:UpdateBasePathMapping' :: Text
domainName = Text
a} :: UpdateBasePathMapping)

-- | [Required] The base path of the BasePathMapping resource to change.
--
-- To specify an empty base path, set this parameter to @\'(none)\'@.
updateBasePathMapping_basePath :: Lens.Lens' UpdateBasePathMapping Prelude.Text
updateBasePathMapping_basePath :: (Text -> f Text)
-> UpdateBasePathMapping -> f UpdateBasePathMapping
updateBasePathMapping_basePath = (UpdateBasePathMapping -> Text)
-> (UpdateBasePathMapping -> Text -> UpdateBasePathMapping)
-> Lens UpdateBasePathMapping UpdateBasePathMapping Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateBasePathMapping' {Text
basePath :: Text
$sel:basePath:UpdateBasePathMapping' :: UpdateBasePathMapping -> Text
basePath} -> Text
basePath) (\s :: UpdateBasePathMapping
s@UpdateBasePathMapping' {} Text
a -> UpdateBasePathMapping
s {$sel:basePath:UpdateBasePathMapping' :: Text
basePath = Text
a} :: UpdateBasePathMapping)

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

instance Prelude.Hashable UpdateBasePathMapping

instance Prelude.NFData UpdateBasePathMapping

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

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