{-# 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.UpdateApiKey
-- 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 an ApiKey resource.
module Amazonka.APIGateway.UpdateApiKey
  ( -- * Creating a Request
    UpdateApiKey (..),
    newUpdateApiKey,

    -- * Request Lenses
    updateApiKey_patchOperations,
    updateApiKey_apiKey,

    -- * Destructuring the Response
    ApiKey (..),
    newApiKey,

    -- * Response Lenses
    apiKey_enabled,
    apiKey_value,
    apiKey_customerId,
    apiKey_createdDate,
    apiKey_name,
    apiKey_id,
    apiKey_stageKeys,
    apiKey_lastUpdatedDate,
    apiKey_description,
    apiKey_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

-- | A request to change information about an ApiKey resource.
--
-- /See:/ 'newUpdateApiKey' smart constructor.
data UpdateApiKey = UpdateApiKey'
  { -- | A list of update operations to be applied to the specified resource and
    -- in the order specified in this list.
    UpdateApiKey -> Maybe [PatchOperation]
patchOperations :: Prelude.Maybe [PatchOperation],
    -- | [Required] The identifier of the ApiKey resource to be updated.
    UpdateApiKey -> Text
apiKey :: Prelude.Text
  }
  deriving (UpdateApiKey -> UpdateApiKey -> Bool
(UpdateApiKey -> UpdateApiKey -> Bool)
-> (UpdateApiKey -> UpdateApiKey -> Bool) -> Eq UpdateApiKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateApiKey -> UpdateApiKey -> Bool
$c/= :: UpdateApiKey -> UpdateApiKey -> Bool
== :: UpdateApiKey -> UpdateApiKey -> Bool
$c== :: UpdateApiKey -> UpdateApiKey -> Bool
Prelude.Eq, ReadPrec [UpdateApiKey]
ReadPrec UpdateApiKey
Int -> ReadS UpdateApiKey
ReadS [UpdateApiKey]
(Int -> ReadS UpdateApiKey)
-> ReadS [UpdateApiKey]
-> ReadPrec UpdateApiKey
-> ReadPrec [UpdateApiKey]
-> Read UpdateApiKey
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateApiKey]
$creadListPrec :: ReadPrec [UpdateApiKey]
readPrec :: ReadPrec UpdateApiKey
$creadPrec :: ReadPrec UpdateApiKey
readList :: ReadS [UpdateApiKey]
$creadList :: ReadS [UpdateApiKey]
readsPrec :: Int -> ReadS UpdateApiKey
$creadsPrec :: Int -> ReadS UpdateApiKey
Prelude.Read, Int -> UpdateApiKey -> ShowS
[UpdateApiKey] -> ShowS
UpdateApiKey -> String
(Int -> UpdateApiKey -> ShowS)
-> (UpdateApiKey -> String)
-> ([UpdateApiKey] -> ShowS)
-> Show UpdateApiKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateApiKey] -> ShowS
$cshowList :: [UpdateApiKey] -> ShowS
show :: UpdateApiKey -> String
$cshow :: UpdateApiKey -> String
showsPrec :: Int -> UpdateApiKey -> ShowS
$cshowsPrec :: Int -> UpdateApiKey -> ShowS
Prelude.Show, (forall x. UpdateApiKey -> Rep UpdateApiKey x)
-> (forall x. Rep UpdateApiKey x -> UpdateApiKey)
-> Generic UpdateApiKey
forall x. Rep UpdateApiKey x -> UpdateApiKey
forall x. UpdateApiKey -> Rep UpdateApiKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateApiKey x -> UpdateApiKey
$cfrom :: forall x. UpdateApiKey -> Rep UpdateApiKey x
Prelude.Generic)

-- |
-- Create a value of 'UpdateApiKey' 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', 'updateApiKey_patchOperations' - A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
--
-- 'apiKey', 'updateApiKey_apiKey' - [Required] The identifier of the ApiKey resource to be updated.
newUpdateApiKey ::
  -- | 'apiKey'
  Prelude.Text ->
  UpdateApiKey
newUpdateApiKey :: Text -> UpdateApiKey
newUpdateApiKey Text
pApiKey_ =
  UpdateApiKey' :: Maybe [PatchOperation] -> Text -> UpdateApiKey
UpdateApiKey'
    { $sel:patchOperations:UpdateApiKey' :: Maybe [PatchOperation]
patchOperations = Maybe [PatchOperation]
forall a. Maybe a
Prelude.Nothing,
      $sel:apiKey:UpdateApiKey' :: Text
apiKey = Text
pApiKey_
    }

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

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

instance Prelude.Hashable UpdateApiKey

instance Prelude.NFData UpdateApiKey

instance Core.ToHeaders UpdateApiKey where
  toHeaders :: UpdateApiKey -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateApiKey -> 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 UpdateApiKey where
  toJSON :: UpdateApiKey -> Value
toJSON UpdateApiKey' {Maybe [PatchOperation]
Text
apiKey :: Text
patchOperations :: Maybe [PatchOperation]
$sel:apiKey:UpdateApiKey' :: UpdateApiKey -> Text
$sel:patchOperations:UpdateApiKey' :: UpdateApiKey -> 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 UpdateApiKey where
  toPath :: UpdateApiKey -> ByteString
toPath UpdateApiKey' {Maybe [PatchOperation]
Text
apiKey :: Text
patchOperations :: Maybe [PatchOperation]
$sel:apiKey:UpdateApiKey' :: UpdateApiKey -> Text
$sel:patchOperations:UpdateApiKey' :: UpdateApiKey -> Maybe [PatchOperation]
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/apikeys/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
apiKey]

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