{-# 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.UpdateMethodResponse
-- 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 MethodResponse resource.
module Amazonka.APIGateway.UpdateMethodResponse
  ( -- * Creating a Request
    UpdateMethodResponse (..),
    newUpdateMethodResponse,

    -- * Request Lenses
    updateMethodResponse_patchOperations,
    updateMethodResponse_restApiId,
    updateMethodResponse_resourceId,
    updateMethodResponse_httpMethod,
    updateMethodResponse_statusCode,

    -- * Destructuring the Response
    MethodResponse (..),
    newMethodResponse,

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

-- |
-- Create a value of 'UpdateMethodResponse' 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', 'updateMethodResponse_patchOperations' - A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
--
-- 'restApiId', 'updateMethodResponse_restApiId' - [Required] The string identifier of the associated RestApi.
--
-- 'resourceId', 'updateMethodResponse_resourceId' - [Required] The Resource identifier for the MethodResponse resource.
--
-- 'httpMethod', 'updateMethodResponse_httpMethod' - [Required] The HTTP verb of the Method resource.
--
-- 'statusCode', 'updateMethodResponse_statusCode' - [Required] The status code for the MethodResponse resource.
newUpdateMethodResponse ::
  -- | 'restApiId'
  Prelude.Text ->
  -- | 'resourceId'
  Prelude.Text ->
  -- | 'httpMethod'
  Prelude.Text ->
  -- | 'statusCode'
  Prelude.Text ->
  UpdateMethodResponse
newUpdateMethodResponse :: Text -> Text -> Text -> Text -> UpdateMethodResponse
newUpdateMethodResponse
  Text
pRestApiId_
  Text
pResourceId_
  Text
pHttpMethod_
  Text
pStatusCode_ =
    UpdateMethodResponse' :: Maybe [PatchOperation]
-> Text -> Text -> Text -> Text -> UpdateMethodResponse
UpdateMethodResponse'
      { $sel:patchOperations:UpdateMethodResponse' :: Maybe [PatchOperation]
patchOperations =
          Maybe [PatchOperation]
forall a. Maybe a
Prelude.Nothing,
        $sel:restApiId:UpdateMethodResponse' :: Text
restApiId = Text
pRestApiId_,
        $sel:resourceId:UpdateMethodResponse' :: Text
resourceId = Text
pResourceId_,
        $sel:httpMethod:UpdateMethodResponse' :: Text
httpMethod = Text
pHttpMethod_,
        $sel:statusCode:UpdateMethodResponse' :: Text
statusCode = Text
pStatusCode_
      }

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

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

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

-- | [Required] The status code for the MethodResponse resource.
updateMethodResponse_statusCode :: Lens.Lens' UpdateMethodResponse Prelude.Text
updateMethodResponse_statusCode :: (Text -> f Text) -> UpdateMethodResponse -> f UpdateMethodResponse
updateMethodResponse_statusCode = (UpdateMethodResponse -> Text)
-> (UpdateMethodResponse -> Text -> UpdateMethodResponse)
-> Lens UpdateMethodResponse UpdateMethodResponse Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateMethodResponse' {Text
statusCode :: Text
$sel:statusCode:UpdateMethodResponse' :: UpdateMethodResponse -> Text
statusCode} -> Text
statusCode) (\s :: UpdateMethodResponse
s@UpdateMethodResponse' {} Text
a -> UpdateMethodResponse
s {$sel:statusCode:UpdateMethodResponse' :: Text
statusCode = Text
a} :: UpdateMethodResponse)

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

instance Prelude.Hashable UpdateMethodResponse

instance Prelude.NFData UpdateMethodResponse

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

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