{-# 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.UpdateResource
-- 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 a Resource resource.
module Amazonka.APIGateway.UpdateResource
  ( -- * Creating a Request
    UpdateResource (..),
    newUpdateResource,

    -- * Request Lenses
    updateResource_patchOperations,
    updateResource_restApiId,
    updateResource_resourceId,

    -- * Destructuring the Response
    Resource (..),
    newResource,

    -- * Response Lenses
    resource_pathPart,
    resource_path,
    resource_id,
    resource_resourceMethods,
    resource_parentId,
  )
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 change information about a Resource resource.
--
-- /See:/ 'newUpdateResource' smart constructor.
data UpdateResource = UpdateResource'
  { -- | A list of update operations to be applied to the specified resource and
    -- in the order specified in this list.
    UpdateResource -> Maybe [PatchOperation]
patchOperations :: Prelude.Maybe [PatchOperation],
    -- | [Required] The string identifier of the associated RestApi.
    UpdateResource -> Text
restApiId :: Prelude.Text,
    -- | [Required] The identifier of the Resource resource.
    UpdateResource -> Text
resourceId :: Prelude.Text
  }
  deriving (UpdateResource -> UpdateResource -> Bool
(UpdateResource -> UpdateResource -> Bool)
-> (UpdateResource -> UpdateResource -> Bool) -> Eq UpdateResource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateResource -> UpdateResource -> Bool
$c/= :: UpdateResource -> UpdateResource -> Bool
== :: UpdateResource -> UpdateResource -> Bool
$c== :: UpdateResource -> UpdateResource -> Bool
Prelude.Eq, ReadPrec [UpdateResource]
ReadPrec UpdateResource
Int -> ReadS UpdateResource
ReadS [UpdateResource]
(Int -> ReadS UpdateResource)
-> ReadS [UpdateResource]
-> ReadPrec UpdateResource
-> ReadPrec [UpdateResource]
-> Read UpdateResource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateResource]
$creadListPrec :: ReadPrec [UpdateResource]
readPrec :: ReadPrec UpdateResource
$creadPrec :: ReadPrec UpdateResource
readList :: ReadS [UpdateResource]
$creadList :: ReadS [UpdateResource]
readsPrec :: Int -> ReadS UpdateResource
$creadsPrec :: Int -> ReadS UpdateResource
Prelude.Read, Int -> UpdateResource -> ShowS
[UpdateResource] -> ShowS
UpdateResource -> String
(Int -> UpdateResource -> ShowS)
-> (UpdateResource -> String)
-> ([UpdateResource] -> ShowS)
-> Show UpdateResource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateResource] -> ShowS
$cshowList :: [UpdateResource] -> ShowS
show :: UpdateResource -> String
$cshow :: UpdateResource -> String
showsPrec :: Int -> UpdateResource -> ShowS
$cshowsPrec :: Int -> UpdateResource -> ShowS
Prelude.Show, (forall x. UpdateResource -> Rep UpdateResource x)
-> (forall x. Rep UpdateResource x -> UpdateResource)
-> Generic UpdateResource
forall x. Rep UpdateResource x -> UpdateResource
forall x. UpdateResource -> Rep UpdateResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateResource x -> UpdateResource
$cfrom :: forall x. UpdateResource -> Rep UpdateResource x
Prelude.Generic)

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

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

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

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

instance Prelude.Hashable UpdateResource

instance Prelude.NFData UpdateResource

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

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