{-# 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.UpdateIntegration
-- 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)
--
-- Represents an update integration.
module Amazonka.APIGateway.UpdateIntegration
  ( -- * Creating a Request
    UpdateIntegration (..),
    newUpdateIntegration,

    -- * Request Lenses
    updateIntegration_patchOperations,
    updateIntegration_restApiId,
    updateIntegration_resourceId,
    updateIntegration_httpMethod,

    -- * Destructuring the Response
    Integration (..),
    newIntegration,

    -- * Response Lenses
    integration_httpMethod,
    integration_requestTemplates,
    integration_credentials,
    integration_connectionId,
    integration_requestParameters,
    integration_contentHandling,
    integration_passthroughBehavior,
    integration_uri,
    integration_integrationResponses,
    integration_tlsConfig,
    integration_cacheNamespace,
    integration_timeoutInMillis,
    integration_type,
    integration_connectionType,
    integration_cacheKeyParameters,
  )
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

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

-- |
-- Create a value of 'UpdateIntegration' 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', 'updateIntegration_patchOperations' - A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
--
-- 'restApiId', 'updateIntegration_restApiId' - [Required] The string identifier of the associated RestApi.
--
-- 'resourceId', 'updateIntegration_resourceId' - [Required] Represents an update integration request\'s resource
-- identifier.
--
-- 'httpMethod', 'updateIntegration_httpMethod' - [Required] Represents an update integration request\'s HTTP method.
newUpdateIntegration ::
  -- | 'restApiId'
  Prelude.Text ->
  -- | 'resourceId'
  Prelude.Text ->
  -- | 'httpMethod'
  Prelude.Text ->
  UpdateIntegration
newUpdateIntegration :: Text -> Text -> Text -> UpdateIntegration
newUpdateIntegration
  Text
pRestApiId_
  Text
pResourceId_
  Text
pHttpMethod_ =
    UpdateIntegration' :: Maybe [PatchOperation] -> Text -> Text -> Text -> UpdateIntegration
UpdateIntegration'
      { $sel:patchOperations:UpdateIntegration' :: Maybe [PatchOperation]
patchOperations =
          Maybe [PatchOperation]
forall a. Maybe a
Prelude.Nothing,
        $sel:restApiId:UpdateIntegration' :: Text
restApiId = Text
pRestApiId_,
        $sel:resourceId:UpdateIntegration' :: Text
resourceId = Text
pResourceId_,
        $sel:httpMethod:UpdateIntegration' :: Text
httpMethod = Text
pHttpMethod_
      }

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

-- | [Required] Represents an update integration request\'s resource
-- identifier.
updateIntegration_resourceId :: Lens.Lens' UpdateIntegration Prelude.Text
updateIntegration_resourceId :: (Text -> f Text) -> UpdateIntegration -> f UpdateIntegration
updateIntegration_resourceId = (UpdateIntegration -> Text)
-> (UpdateIntegration -> Text -> UpdateIntegration)
-> Lens UpdateIntegration UpdateIntegration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateIntegration' {Text
resourceId :: Text
$sel:resourceId:UpdateIntegration' :: UpdateIntegration -> Text
resourceId} -> Text
resourceId) (\s :: UpdateIntegration
s@UpdateIntegration' {} Text
a -> UpdateIntegration
s {$sel:resourceId:UpdateIntegration' :: Text
resourceId = Text
a} :: UpdateIntegration)

-- | [Required] Represents an update integration request\'s HTTP method.
updateIntegration_httpMethod :: Lens.Lens' UpdateIntegration Prelude.Text
updateIntegration_httpMethod :: (Text -> f Text) -> UpdateIntegration -> f UpdateIntegration
updateIntegration_httpMethod = (UpdateIntegration -> Text)
-> (UpdateIntegration -> Text -> UpdateIntegration)
-> Lens UpdateIntegration UpdateIntegration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateIntegration' {Text
httpMethod :: Text
$sel:httpMethod:UpdateIntegration' :: UpdateIntegration -> Text
httpMethod} -> Text
httpMethod) (\s :: UpdateIntegration
s@UpdateIntegration' {} Text
a -> UpdateIntegration
s {$sel:httpMethod:UpdateIntegration' :: Text
httpMethod = Text
a} :: UpdateIntegration)

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

instance Prelude.Hashable UpdateIntegration

instance Prelude.NFData UpdateIntegration

instance Core.ToHeaders UpdateIntegration where
  toHeaders :: UpdateIntegration -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateIntegration -> 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 UpdateIntegration where
  toJSON :: UpdateIntegration -> Value
toJSON UpdateIntegration' {Maybe [PatchOperation]
Text
httpMethod :: Text
resourceId :: Text
restApiId :: Text
patchOperations :: Maybe [PatchOperation]
$sel:httpMethod:UpdateIntegration' :: UpdateIntegration -> Text
$sel:resourceId:UpdateIntegration' :: UpdateIntegration -> Text
$sel:restApiId:UpdateIntegration' :: UpdateIntegration -> Text
$sel:patchOperations:UpdateIntegration' :: UpdateIntegration -> 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 UpdateIntegration where
  toPath :: UpdateIntegration -> ByteString
toPath UpdateIntegration' {Maybe [PatchOperation]
Text
httpMethod :: Text
resourceId :: Text
restApiId :: Text
patchOperations :: Maybe [PatchOperation]
$sel:httpMethod:UpdateIntegration' :: UpdateIntegration -> Text
$sel:resourceId:UpdateIntegration' :: UpdateIntegration -> Text
$sel:restApiId:UpdateIntegration' :: UpdateIntegration -> Text
$sel:patchOperations:UpdateIntegration' :: UpdateIntegration -> 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
"/integration"
      ]

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