{-# 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.UpdateMethod
-- 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 an existing Method resource.
module Amazonka.APIGateway.UpdateMethod
  ( -- * Creating a Request
    UpdateMethod (..),
    newUpdateMethod,

    -- * Request Lenses
    updateMethod_patchOperations,
    updateMethod_restApiId,
    updateMethod_resourceId,
    updateMethod_httpMethod,

    -- * Destructuring the Response
    Method (..),
    newMethod,

    -- * Response Lenses
    method_methodResponses,
    method_httpMethod,
    method_authorizationScopes,
    method_requestValidatorId,
    method_requestModels,
    method_requestParameters,
    method_authorizerId,
    method_operationName,
    method_authorizationType,
    method_apiKeyRequired,
    method_methodIntegration,
  )
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

-- | Request to update an existing Method resource.
--
-- /See:/ 'newUpdateMethod' smart constructor.
data UpdateMethod = UpdateMethod'
  { -- | A list of update operations to be applied to the specified resource and
    -- in the order specified in this list.
    UpdateMethod -> Maybe [PatchOperation]
patchOperations :: Prelude.Maybe [PatchOperation],
    -- | [Required] The string identifier of the associated RestApi.
    UpdateMethod -> Text
restApiId :: Prelude.Text,
    -- | [Required] The Resource identifier for the Method resource.
    UpdateMethod -> Text
resourceId :: Prelude.Text,
    -- | [Required] The HTTP verb of the Method resource.
    UpdateMethod -> Text
httpMethod :: Prelude.Text
  }
  deriving (UpdateMethod -> UpdateMethod -> Bool
(UpdateMethod -> UpdateMethod -> Bool)
-> (UpdateMethod -> UpdateMethod -> Bool) -> Eq UpdateMethod
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateMethod -> UpdateMethod -> Bool
$c/= :: UpdateMethod -> UpdateMethod -> Bool
== :: UpdateMethod -> UpdateMethod -> Bool
$c== :: UpdateMethod -> UpdateMethod -> Bool
Prelude.Eq, ReadPrec [UpdateMethod]
ReadPrec UpdateMethod
Int -> ReadS UpdateMethod
ReadS [UpdateMethod]
(Int -> ReadS UpdateMethod)
-> ReadS [UpdateMethod]
-> ReadPrec UpdateMethod
-> ReadPrec [UpdateMethod]
-> Read UpdateMethod
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateMethod]
$creadListPrec :: ReadPrec [UpdateMethod]
readPrec :: ReadPrec UpdateMethod
$creadPrec :: ReadPrec UpdateMethod
readList :: ReadS [UpdateMethod]
$creadList :: ReadS [UpdateMethod]
readsPrec :: Int -> ReadS UpdateMethod
$creadsPrec :: Int -> ReadS UpdateMethod
Prelude.Read, Int -> UpdateMethod -> ShowS
[UpdateMethod] -> ShowS
UpdateMethod -> String
(Int -> UpdateMethod -> ShowS)
-> (UpdateMethod -> String)
-> ([UpdateMethod] -> ShowS)
-> Show UpdateMethod
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateMethod] -> ShowS
$cshowList :: [UpdateMethod] -> ShowS
show :: UpdateMethod -> String
$cshow :: UpdateMethod -> String
showsPrec :: Int -> UpdateMethod -> ShowS
$cshowsPrec :: Int -> UpdateMethod -> ShowS
Prelude.Show, (forall x. UpdateMethod -> Rep UpdateMethod x)
-> (forall x. Rep UpdateMethod x -> UpdateMethod)
-> Generic UpdateMethod
forall x. Rep UpdateMethod x -> UpdateMethod
forall x. UpdateMethod -> Rep UpdateMethod x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateMethod x -> UpdateMethod
$cfrom :: forall x. UpdateMethod -> Rep UpdateMethod x
Prelude.Generic)

-- |
-- Create a value of 'UpdateMethod' 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', 'updateMethod_patchOperations' - A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
--
-- 'restApiId', 'updateMethod_restApiId' - [Required] The string identifier of the associated RestApi.
--
-- 'resourceId', 'updateMethod_resourceId' - [Required] The Resource identifier for the Method resource.
--
-- 'httpMethod', 'updateMethod_httpMethod' - [Required] The HTTP verb of the Method resource.
newUpdateMethod ::
  -- | 'restApiId'
  Prelude.Text ->
  -- | 'resourceId'
  Prelude.Text ->
  -- | 'httpMethod'
  Prelude.Text ->
  UpdateMethod
newUpdateMethod :: Text -> Text -> Text -> UpdateMethod
newUpdateMethod Text
pRestApiId_ Text
pResourceId_ Text
pHttpMethod_ =
  UpdateMethod' :: Maybe [PatchOperation] -> Text -> Text -> Text -> UpdateMethod
UpdateMethod'
    { $sel:patchOperations:UpdateMethod' :: Maybe [PatchOperation]
patchOperations = Maybe [PatchOperation]
forall a. Maybe a
Prelude.Nothing,
      $sel:restApiId:UpdateMethod' :: Text
restApiId = Text
pRestApiId_,
      $sel:resourceId:UpdateMethod' :: Text
resourceId = Text
pResourceId_,
      $sel:httpMethod:UpdateMethod' :: Text
httpMethod = Text
pHttpMethod_
    }

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

-- | [Required] The Resource identifier for the Method resource.
updateMethod_resourceId :: Lens.Lens' UpdateMethod Prelude.Text
updateMethod_resourceId :: (Text -> f Text) -> UpdateMethod -> f UpdateMethod
updateMethod_resourceId = (UpdateMethod -> Text)
-> (UpdateMethod -> Text -> UpdateMethod)
-> Lens UpdateMethod UpdateMethod Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateMethod' {Text
resourceId :: Text
$sel:resourceId:UpdateMethod' :: UpdateMethod -> Text
resourceId} -> Text
resourceId) (\s :: UpdateMethod
s@UpdateMethod' {} Text
a -> UpdateMethod
s {$sel:resourceId:UpdateMethod' :: Text
resourceId = Text
a} :: UpdateMethod)

-- | [Required] The HTTP verb of the Method resource.
updateMethod_httpMethod :: Lens.Lens' UpdateMethod Prelude.Text
updateMethod_httpMethod :: (Text -> f Text) -> UpdateMethod -> f UpdateMethod
updateMethod_httpMethod = (UpdateMethod -> Text)
-> (UpdateMethod -> Text -> UpdateMethod)
-> Lens UpdateMethod UpdateMethod Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateMethod' {Text
httpMethod :: Text
$sel:httpMethod:UpdateMethod' :: UpdateMethod -> Text
httpMethod} -> Text
httpMethod) (\s :: UpdateMethod
s@UpdateMethod' {} Text
a -> UpdateMethod
s {$sel:httpMethod:UpdateMethod' :: Text
httpMethod = Text
a} :: UpdateMethod)

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

instance Prelude.Hashable UpdateMethod

instance Prelude.NFData UpdateMethod

instance Core.ToHeaders UpdateMethod where
  toHeaders :: UpdateMethod -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateMethod -> 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 UpdateMethod where
  toJSON :: UpdateMethod -> Value
toJSON UpdateMethod' {Maybe [PatchOperation]
Text
httpMethod :: Text
resourceId :: Text
restApiId :: Text
patchOperations :: Maybe [PatchOperation]
$sel:httpMethod:UpdateMethod' :: UpdateMethod -> Text
$sel:resourceId:UpdateMethod' :: UpdateMethod -> Text
$sel:restApiId:UpdateMethod' :: UpdateMethod -> Text
$sel:patchOperations:UpdateMethod' :: UpdateMethod -> 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 UpdateMethod where
  toPath :: UpdateMethod -> ByteString
toPath UpdateMethod' {Maybe [PatchOperation]
Text
httpMethod :: Text
resourceId :: Text
restApiId :: Text
patchOperations :: Maybe [PatchOperation]
$sel:httpMethod:UpdateMethod' :: UpdateMethod -> Text
$sel:resourceId:UpdateMethod' :: UpdateMethod -> Text
$sel:restApiId:UpdateMethod' :: UpdateMethod -> Text
$sel:patchOperations:UpdateMethod' :: UpdateMethod -> 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
"/resources/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
resourceId,
        ByteString
"/methods/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
httpMethod
      ]

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