{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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_apiKeyRequired,
    method_authorizationScopes,
    method_authorizationType,
    method_authorizerId,
    method_httpMethod,
    method_methodIntegration,
    method_methodResponses,
    method_operationName,
    method_requestModels,
    method_requestParameters,
    method_requestValidatorId,
  )
where

import Amazonka.APIGateway.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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'
  { -- | For more information about supported patch operations, see
    -- <https://docs.aws.amazon.com/apigateway/latest/api/patch-operations.html Patch Operations>.
    UpdateMethod -> Maybe [PatchOperation]
patchOperations :: Prelude.Maybe [PatchOperation],
    -- | The string identifier of the associated RestApi.
    UpdateMethod -> Text
restApiId :: Prelude.Text,
    -- | The Resource identifier for the Method resource.
    UpdateMethod -> Text
resourceId :: Prelude.Text,
    -- | The HTTP verb of the Method resource.
    UpdateMethod -> Text
httpMethod :: Prelude.Text
  }
  deriving (UpdateMethod -> UpdateMethod -> Bool
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]
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
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. 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' - For more information about supported patch operations, see
-- <https://docs.aws.amazon.com/apigateway/latest/api/patch-operations.html Patch Operations>.
--
-- 'restApiId', 'updateMethod_restApiId' - The string identifier of the associated RestApi.
--
-- 'resourceId', 'updateMethod_resourceId' - The Resource identifier for the Method resource.
--
-- 'httpMethod', 'updateMethod_httpMethod' - 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'
    { $sel:patchOperations:UpdateMethod' :: Maybe [PatchOperation]
patchOperations = 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_
    }

-- | For more information about supported patch operations, see
-- <https://docs.aws.amazon.com/apigateway/latest/api/patch-operations.html Patch Operations>.
updateMethod_patchOperations :: Lens.Lens' UpdateMethod (Prelude.Maybe [PatchOperation])
updateMethod_patchOperations :: Lens' UpdateMethod (Maybe [PatchOperation])
updateMethod_patchOperations = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The string identifier of the associated RestApi.
updateMethod_restApiId :: Lens.Lens' UpdateMethod Prelude.Text
updateMethod_restApiId :: Lens' UpdateMethod Text
updateMethod_restApiId = 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)

-- | The Resource identifier for the Method resource.
updateMethod_resourceId :: Lens.Lens' UpdateMethod Prelude.Text
updateMethod_resourceId :: Lens' UpdateMethod Text
updateMethod_resourceId = 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)

-- | The HTTP verb of the Method resource.
updateMethod_httpMethod :: Lens.Lens' UpdateMethod Prelude.Text
updateMethod_httpMethod :: Lens' UpdateMethod Text
updateMethod_httpMethod = 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 :: (Service -> Service) -> UpdateMethod -> Request UpdateMethod
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.patchJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy UpdateMethod
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateMethod)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> forall a. FromJSON a => Object -> Either String a
Data.eitherParseJSON Object
x)

instance Prelude.Hashable UpdateMethod where
  hashWithSalt :: Int -> UpdateMethod -> Int
hashWithSalt Int
_salt 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]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [PatchOperation]
patchOperations
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
restApiId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
resourceId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
httpMethod

instance Prelude.NFData UpdateMethod where
  rnf :: UpdateMethod -> ()
rnf 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]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [PatchOperation]
patchOperations
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
restApiId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
resourceId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
httpMethod

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

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"patchOperations" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [PatchOperation]
patchOperations
          ]
      )

instance Data.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]
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/restapis/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
restApiId,
        ByteString
"/resources/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
resourceId,
        ByteString
"/methods/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
httpMethod
      ]

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