{-# 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.IoT.UpdateCertificate
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Updates the status of the specified certificate. This operation is
-- idempotent.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions UpdateCertificate>
-- action.
--
-- Certificates must be in the ACTIVE state to authenticate devices that
-- use a certificate to connect to IoT.
--
-- Within a few minutes of updating a certificate from the ACTIVE state to
-- any other state, IoT disconnects all devices that used that certificate
-- to connect. Devices cannot use a certificate that is not in the ACTIVE
-- state to reconnect.
module Amazonka.IoT.UpdateCertificate
  ( -- * Creating a Request
    UpdateCertificate (..),
    newUpdateCertificate,

    -- * Request Lenses
    updateCertificate_certificateId,
    updateCertificate_newStatus,

    -- * Destructuring the Response
    UpdateCertificateResponse (..),
    newUpdateCertificateResponse,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoT.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | The input for the UpdateCertificate operation.
--
-- /See:/ 'newUpdateCertificate' smart constructor.
data UpdateCertificate = UpdateCertificate'
  { -- | The ID of the certificate. (The last part of the certificate ARN
    -- contains the certificate ID.)
    UpdateCertificate -> Text
certificateId :: Prelude.Text,
    -- | The new status.
    --
    -- __Note:__ Setting the status to PENDING_TRANSFER or PENDING_ACTIVATION
    -- will result in an exception being thrown. PENDING_TRANSFER and
    -- PENDING_ACTIVATION are statuses used internally by IoT. They are not
    -- intended for developer use.
    --
    -- __Note:__ The status value REGISTER_INACTIVE is deprecated and should
    -- not be used.
    UpdateCertificate -> CertificateStatus
newStatus' :: CertificateStatus
  }
  deriving (UpdateCertificate -> UpdateCertificate -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateCertificate -> UpdateCertificate -> Bool
$c/= :: UpdateCertificate -> UpdateCertificate -> Bool
== :: UpdateCertificate -> UpdateCertificate -> Bool
$c== :: UpdateCertificate -> UpdateCertificate -> Bool
Prelude.Eq, ReadPrec [UpdateCertificate]
ReadPrec UpdateCertificate
Int -> ReadS UpdateCertificate
ReadS [UpdateCertificate]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateCertificate]
$creadListPrec :: ReadPrec [UpdateCertificate]
readPrec :: ReadPrec UpdateCertificate
$creadPrec :: ReadPrec UpdateCertificate
readList :: ReadS [UpdateCertificate]
$creadList :: ReadS [UpdateCertificate]
readsPrec :: Int -> ReadS UpdateCertificate
$creadsPrec :: Int -> ReadS UpdateCertificate
Prelude.Read, Int -> UpdateCertificate -> ShowS
[UpdateCertificate] -> ShowS
UpdateCertificate -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateCertificate] -> ShowS
$cshowList :: [UpdateCertificate] -> ShowS
show :: UpdateCertificate -> String
$cshow :: UpdateCertificate -> String
showsPrec :: Int -> UpdateCertificate -> ShowS
$cshowsPrec :: Int -> UpdateCertificate -> ShowS
Prelude.Show, forall x. Rep UpdateCertificate x -> UpdateCertificate
forall x. UpdateCertificate -> Rep UpdateCertificate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateCertificate x -> UpdateCertificate
$cfrom :: forall x. UpdateCertificate -> Rep UpdateCertificate x
Prelude.Generic)

-- |
-- Create a value of 'UpdateCertificate' 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:
--
-- 'certificateId', 'updateCertificate_certificateId' - The ID of the certificate. (The last part of the certificate ARN
-- contains the certificate ID.)
--
-- 'newStatus'', 'updateCertificate_newStatus' - The new status.
--
-- __Note:__ Setting the status to PENDING_TRANSFER or PENDING_ACTIVATION
-- will result in an exception being thrown. PENDING_TRANSFER and
-- PENDING_ACTIVATION are statuses used internally by IoT. They are not
-- intended for developer use.
--
-- __Note:__ The status value REGISTER_INACTIVE is deprecated and should
-- not be used.
newUpdateCertificate ::
  -- | 'certificateId'
  Prelude.Text ->
  -- | 'newStatus''
  CertificateStatus ->
  UpdateCertificate
newUpdateCertificate :: Text -> CertificateStatus -> UpdateCertificate
newUpdateCertificate Text
pCertificateId_ CertificateStatus
pNewStatus_ =
  UpdateCertificate'
    { $sel:certificateId:UpdateCertificate' :: Text
certificateId = Text
pCertificateId_,
      $sel:newStatus':UpdateCertificate' :: CertificateStatus
newStatus' = CertificateStatus
pNewStatus_
    }

-- | The ID of the certificate. (The last part of the certificate ARN
-- contains the certificate ID.)
updateCertificate_certificateId :: Lens.Lens' UpdateCertificate Prelude.Text
updateCertificate_certificateId :: Lens' UpdateCertificate Text
updateCertificate_certificateId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateCertificate' {Text
certificateId :: Text
$sel:certificateId:UpdateCertificate' :: UpdateCertificate -> Text
certificateId} -> Text
certificateId) (\s :: UpdateCertificate
s@UpdateCertificate' {} Text
a -> UpdateCertificate
s {$sel:certificateId:UpdateCertificate' :: Text
certificateId = Text
a} :: UpdateCertificate)

-- | The new status.
--
-- __Note:__ Setting the status to PENDING_TRANSFER or PENDING_ACTIVATION
-- will result in an exception being thrown. PENDING_TRANSFER and
-- PENDING_ACTIVATION are statuses used internally by IoT. They are not
-- intended for developer use.
--
-- __Note:__ The status value REGISTER_INACTIVE is deprecated and should
-- not be used.
updateCertificate_newStatus :: Lens.Lens' UpdateCertificate CertificateStatus
updateCertificate_newStatus :: Lens' UpdateCertificate CertificateStatus
updateCertificate_newStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateCertificate' {CertificateStatus
newStatus' :: CertificateStatus
$sel:newStatus':UpdateCertificate' :: UpdateCertificate -> CertificateStatus
newStatus'} -> CertificateStatus
newStatus') (\s :: UpdateCertificate
s@UpdateCertificate' {} CertificateStatus
a -> UpdateCertificate
s {$sel:newStatus':UpdateCertificate' :: CertificateStatus
newStatus' = CertificateStatus
a} :: UpdateCertificate)

instance Core.AWSRequest UpdateCertificate where
  type
    AWSResponse UpdateCertificate =
      UpdateCertificateResponse
  request :: (Service -> Service)
-> UpdateCertificate -> Request UpdateCertificate
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy UpdateCertificate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateCertificate)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull UpdateCertificateResponse
UpdateCertificateResponse'

instance Prelude.Hashable UpdateCertificate where
  hashWithSalt :: Int -> UpdateCertificate -> Int
hashWithSalt Int
_salt UpdateCertificate' {Text
CertificateStatus
newStatus' :: CertificateStatus
certificateId :: Text
$sel:newStatus':UpdateCertificate' :: UpdateCertificate -> CertificateStatus
$sel:certificateId:UpdateCertificate' :: UpdateCertificate -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
certificateId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` CertificateStatus
newStatus'

instance Prelude.NFData UpdateCertificate where
  rnf :: UpdateCertificate -> ()
rnf UpdateCertificate' {Text
CertificateStatus
newStatus' :: CertificateStatus
certificateId :: Text
$sel:newStatus':UpdateCertificate' :: UpdateCertificate -> CertificateStatus
$sel:certificateId:UpdateCertificate' :: UpdateCertificate -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
certificateId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf CertificateStatus
newStatus'

instance Data.ToHeaders UpdateCertificate where
  toHeaders :: UpdateCertificate -> [Header]
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

instance Data.ToJSON UpdateCertificate where
  toJSON :: UpdateCertificate -> Value
toJSON = forall a b. a -> b -> a
Prelude.const (Object -> Value
Data.Object forall a. Monoid a => a
Prelude.mempty)

instance Data.ToPath UpdateCertificate where
  toPath :: UpdateCertificate -> ByteString
toPath UpdateCertificate' {Text
CertificateStatus
newStatus' :: CertificateStatus
certificateId :: Text
$sel:newStatus':UpdateCertificate' :: UpdateCertificate -> CertificateStatus
$sel:certificateId:UpdateCertificate' :: UpdateCertificate -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/certificates/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
certificateId]

instance Data.ToQuery UpdateCertificate where
  toQuery :: UpdateCertificate -> QueryString
toQuery UpdateCertificate' {Text
CertificateStatus
newStatus' :: CertificateStatus
certificateId :: Text
$sel:newStatus':UpdateCertificate' :: UpdateCertificate -> CertificateStatus
$sel:certificateId:UpdateCertificate' :: UpdateCertificate -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"newStatus" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: CertificateStatus
newStatus']

-- | /See:/ 'newUpdateCertificateResponse' smart constructor.
data UpdateCertificateResponse = UpdateCertificateResponse'
  {
  }
  deriving (UpdateCertificateResponse -> UpdateCertificateResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateCertificateResponse -> UpdateCertificateResponse -> Bool
$c/= :: UpdateCertificateResponse -> UpdateCertificateResponse -> Bool
== :: UpdateCertificateResponse -> UpdateCertificateResponse -> Bool
$c== :: UpdateCertificateResponse -> UpdateCertificateResponse -> Bool
Prelude.Eq, ReadPrec [UpdateCertificateResponse]
ReadPrec UpdateCertificateResponse
Int -> ReadS UpdateCertificateResponse
ReadS [UpdateCertificateResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateCertificateResponse]
$creadListPrec :: ReadPrec [UpdateCertificateResponse]
readPrec :: ReadPrec UpdateCertificateResponse
$creadPrec :: ReadPrec UpdateCertificateResponse
readList :: ReadS [UpdateCertificateResponse]
$creadList :: ReadS [UpdateCertificateResponse]
readsPrec :: Int -> ReadS UpdateCertificateResponse
$creadsPrec :: Int -> ReadS UpdateCertificateResponse
Prelude.Read, Int -> UpdateCertificateResponse -> ShowS
[UpdateCertificateResponse] -> ShowS
UpdateCertificateResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateCertificateResponse] -> ShowS
$cshowList :: [UpdateCertificateResponse] -> ShowS
show :: UpdateCertificateResponse -> String
$cshow :: UpdateCertificateResponse -> String
showsPrec :: Int -> UpdateCertificateResponse -> ShowS
$cshowsPrec :: Int -> UpdateCertificateResponse -> ShowS
Prelude.Show, forall x.
Rep UpdateCertificateResponse x -> UpdateCertificateResponse
forall x.
UpdateCertificateResponse -> Rep UpdateCertificateResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdateCertificateResponse x -> UpdateCertificateResponse
$cfrom :: forall x.
UpdateCertificateResponse -> Rep UpdateCertificateResponse x
Prelude.Generic)

-- |
-- Create a value of 'UpdateCertificateResponse' 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.
newUpdateCertificateResponse ::
  UpdateCertificateResponse
newUpdateCertificateResponse :: UpdateCertificateResponse
newUpdateCertificateResponse =
  UpdateCertificateResponse
UpdateCertificateResponse'

instance Prelude.NFData UpdateCertificateResponse where
  rnf :: UpdateCertificateResponse -> ()
rnf UpdateCertificateResponse
_ = ()