{-# 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.UpdateRestApi
-- 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 specified API.
module Amazonka.APIGateway.UpdateRestApi
  ( -- * Creating a Request
    UpdateRestApi (..),
    newUpdateRestApi,

    -- * Request Lenses
    updateRestApi_patchOperations,
    updateRestApi_restApiId,

    -- * Destructuring the Response
    RestApi (..),
    newRestApi,

    -- * Response Lenses
    restApi_minimumCompressionSize,
    restApi_disableExecuteApiEndpoint,
    restApi_binaryMediaTypes,
    restApi_warnings,
    restApi_createdDate,
    restApi_name,
    restApi_version,
    restApi_apiKeySource,
    restApi_id,
    restApi_policy,
    restApi_endpointConfiguration,
    restApi_description,
    restApi_tags,
  )
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 RestApi resource in your collection.
--
-- /See:/ 'newUpdateRestApi' smart constructor.
data UpdateRestApi = UpdateRestApi'
  { -- | A list of update operations to be applied to the specified resource and
    -- in the order specified in this list.
    UpdateRestApi -> Maybe [PatchOperation]
patchOperations :: Prelude.Maybe [PatchOperation],
    -- | [Required] The string identifier of the associated RestApi.
    UpdateRestApi -> Text
restApiId :: Prelude.Text
  }
  deriving (UpdateRestApi -> UpdateRestApi -> Bool
(UpdateRestApi -> UpdateRestApi -> Bool)
-> (UpdateRestApi -> UpdateRestApi -> Bool) -> Eq UpdateRestApi
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateRestApi -> UpdateRestApi -> Bool
$c/= :: UpdateRestApi -> UpdateRestApi -> Bool
== :: UpdateRestApi -> UpdateRestApi -> Bool
$c== :: UpdateRestApi -> UpdateRestApi -> Bool
Prelude.Eq, ReadPrec [UpdateRestApi]
ReadPrec UpdateRestApi
Int -> ReadS UpdateRestApi
ReadS [UpdateRestApi]
(Int -> ReadS UpdateRestApi)
-> ReadS [UpdateRestApi]
-> ReadPrec UpdateRestApi
-> ReadPrec [UpdateRestApi]
-> Read UpdateRestApi
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateRestApi]
$creadListPrec :: ReadPrec [UpdateRestApi]
readPrec :: ReadPrec UpdateRestApi
$creadPrec :: ReadPrec UpdateRestApi
readList :: ReadS [UpdateRestApi]
$creadList :: ReadS [UpdateRestApi]
readsPrec :: Int -> ReadS UpdateRestApi
$creadsPrec :: Int -> ReadS UpdateRestApi
Prelude.Read, Int -> UpdateRestApi -> ShowS
[UpdateRestApi] -> ShowS
UpdateRestApi -> String
(Int -> UpdateRestApi -> ShowS)
-> (UpdateRestApi -> String)
-> ([UpdateRestApi] -> ShowS)
-> Show UpdateRestApi
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateRestApi] -> ShowS
$cshowList :: [UpdateRestApi] -> ShowS
show :: UpdateRestApi -> String
$cshow :: UpdateRestApi -> String
showsPrec :: Int -> UpdateRestApi -> ShowS
$cshowsPrec :: Int -> UpdateRestApi -> ShowS
Prelude.Show, (forall x. UpdateRestApi -> Rep UpdateRestApi x)
-> (forall x. Rep UpdateRestApi x -> UpdateRestApi)
-> Generic UpdateRestApi
forall x. Rep UpdateRestApi x -> UpdateRestApi
forall x. UpdateRestApi -> Rep UpdateRestApi x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateRestApi x -> UpdateRestApi
$cfrom :: forall x. UpdateRestApi -> Rep UpdateRestApi x
Prelude.Generic)

-- |
-- Create a value of 'UpdateRestApi' 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', 'updateRestApi_patchOperations' - A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
--
-- 'restApiId', 'updateRestApi_restApiId' - [Required] The string identifier of the associated RestApi.
newUpdateRestApi ::
  -- | 'restApiId'
  Prelude.Text ->
  UpdateRestApi
newUpdateRestApi :: Text -> UpdateRestApi
newUpdateRestApi Text
pRestApiId_ =
  UpdateRestApi' :: Maybe [PatchOperation] -> Text -> UpdateRestApi
UpdateRestApi'
    { $sel:patchOperations:UpdateRestApi' :: Maybe [PatchOperation]
patchOperations = Maybe [PatchOperation]
forall a. Maybe a
Prelude.Nothing,
      $sel:restApiId:UpdateRestApi' :: Text
restApiId = Text
pRestApiId_
    }

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

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

instance Prelude.Hashable UpdateRestApi

instance Prelude.NFData UpdateRestApi

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

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