{-# 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.DeleteCertificate
-- 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)
--
-- Deletes the specified certificate.
--
-- A certificate cannot be deleted if it has a policy or IoT thing attached
-- to it or if its status is set to ACTIVE. To delete a certificate, first
-- use the DetachPolicy action to detach all policies. Next, use the
-- UpdateCertificate action to set the certificate to the INACTIVE status.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions DeleteCertificate>
-- action.
module Amazonka.IoT.DeleteCertificate
  ( -- * Creating a Request
    DeleteCertificate (..),
    newDeleteCertificate,

    -- * Request Lenses
    deleteCertificate_forceDelete,
    deleteCertificate_certificateId,

    -- * Destructuring the Response
    DeleteCertificateResponse (..),
    newDeleteCertificateResponse,
  )
where

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

-- | The input for the DeleteCertificate operation.
--
-- /See:/ 'newDeleteCertificate' smart constructor.
data DeleteCertificate = DeleteCertificate'
  { -- | Forces the deletion of a certificate if it is inactive and is not
    -- attached to an IoT thing.
    DeleteCertificate -> Maybe Bool
forceDelete :: Prelude.Maybe Prelude.Bool,
    -- | The ID of the certificate. (The last part of the certificate ARN
    -- contains the certificate ID.)
    DeleteCertificate -> Text
certificateId :: Prelude.Text
  }
  deriving (DeleteCertificate -> DeleteCertificate -> Bool
(DeleteCertificate -> DeleteCertificate -> Bool)
-> (DeleteCertificate -> DeleteCertificate -> Bool)
-> Eq DeleteCertificate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteCertificate -> DeleteCertificate -> Bool
$c/= :: DeleteCertificate -> DeleteCertificate -> Bool
== :: DeleteCertificate -> DeleteCertificate -> Bool
$c== :: DeleteCertificate -> DeleteCertificate -> Bool
Prelude.Eq, ReadPrec [DeleteCertificate]
ReadPrec DeleteCertificate
Int -> ReadS DeleteCertificate
ReadS [DeleteCertificate]
(Int -> ReadS DeleteCertificate)
-> ReadS [DeleteCertificate]
-> ReadPrec DeleteCertificate
-> ReadPrec [DeleteCertificate]
-> Read DeleteCertificate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteCertificate]
$creadListPrec :: ReadPrec [DeleteCertificate]
readPrec :: ReadPrec DeleteCertificate
$creadPrec :: ReadPrec DeleteCertificate
readList :: ReadS [DeleteCertificate]
$creadList :: ReadS [DeleteCertificate]
readsPrec :: Int -> ReadS DeleteCertificate
$creadsPrec :: Int -> ReadS DeleteCertificate
Prelude.Read, Int -> DeleteCertificate -> ShowS
[DeleteCertificate] -> ShowS
DeleteCertificate -> String
(Int -> DeleteCertificate -> ShowS)
-> (DeleteCertificate -> String)
-> ([DeleteCertificate] -> ShowS)
-> Show DeleteCertificate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteCertificate] -> ShowS
$cshowList :: [DeleteCertificate] -> ShowS
show :: DeleteCertificate -> String
$cshow :: DeleteCertificate -> String
showsPrec :: Int -> DeleteCertificate -> ShowS
$cshowsPrec :: Int -> DeleteCertificate -> ShowS
Prelude.Show, (forall x. DeleteCertificate -> Rep DeleteCertificate x)
-> (forall x. Rep DeleteCertificate x -> DeleteCertificate)
-> Generic DeleteCertificate
forall x. Rep DeleteCertificate x -> DeleteCertificate
forall x. DeleteCertificate -> Rep DeleteCertificate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteCertificate x -> DeleteCertificate
$cfrom :: forall x. DeleteCertificate -> Rep DeleteCertificate x
Prelude.Generic)

-- |
-- Create a value of 'DeleteCertificate' 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:
--
-- 'forceDelete', 'deleteCertificate_forceDelete' - Forces the deletion of a certificate if it is inactive and is not
-- attached to an IoT thing.
--
-- 'certificateId', 'deleteCertificate_certificateId' - The ID of the certificate. (The last part of the certificate ARN
-- contains the certificate ID.)
newDeleteCertificate ::
  -- | 'certificateId'
  Prelude.Text ->
  DeleteCertificate
newDeleteCertificate :: Text -> DeleteCertificate
newDeleteCertificate Text
pCertificateId_ =
  DeleteCertificate' :: Maybe Bool -> Text -> DeleteCertificate
DeleteCertificate'
    { $sel:forceDelete:DeleteCertificate' :: Maybe Bool
forceDelete = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:certificateId:DeleteCertificate' :: Text
certificateId = Text
pCertificateId_
    }

-- | Forces the deletion of a certificate if it is inactive and is not
-- attached to an IoT thing.
deleteCertificate_forceDelete :: Lens.Lens' DeleteCertificate (Prelude.Maybe Prelude.Bool)
deleteCertificate_forceDelete :: (Maybe Bool -> f (Maybe Bool))
-> DeleteCertificate -> f DeleteCertificate
deleteCertificate_forceDelete = (DeleteCertificate -> Maybe Bool)
-> (DeleteCertificate -> Maybe Bool -> DeleteCertificate)
-> Lens
     DeleteCertificate DeleteCertificate (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteCertificate' {Maybe Bool
forceDelete :: Maybe Bool
$sel:forceDelete:DeleteCertificate' :: DeleteCertificate -> Maybe Bool
forceDelete} -> Maybe Bool
forceDelete) (\s :: DeleteCertificate
s@DeleteCertificate' {} Maybe Bool
a -> DeleteCertificate
s {$sel:forceDelete:DeleteCertificate' :: Maybe Bool
forceDelete = Maybe Bool
a} :: DeleteCertificate)

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

instance Core.AWSRequest DeleteCertificate where
  type
    AWSResponse DeleteCertificate =
      DeleteCertificateResponse
  request :: DeleteCertificate -> Request DeleteCertificate
request = Service -> DeleteCertificate -> Request DeleteCertificate
forall a. ToRequest a => Service -> a -> Request a
Request.delete Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteCertificate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeleteCertificate)))
response =
    AWSResponse DeleteCertificate
-> Logger
-> Service
-> Proxy DeleteCertificate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeleteCertificate)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse DeleteCertificate
DeleteCertificateResponse
DeleteCertificateResponse'

instance Prelude.Hashable DeleteCertificate

instance Prelude.NFData DeleteCertificate

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

instance Core.ToPath DeleteCertificate where
  toPath :: DeleteCertificate -> ByteString
toPath DeleteCertificate' {Maybe Bool
Text
certificateId :: Text
forceDelete :: Maybe Bool
$sel:certificateId:DeleteCertificate' :: DeleteCertificate -> Text
$sel:forceDelete:DeleteCertificate' :: DeleteCertificate -> Maybe Bool
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/certificates/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
certificateId]

instance Core.ToQuery DeleteCertificate where
  toQuery :: DeleteCertificate -> QueryString
toQuery DeleteCertificate' {Maybe Bool
Text
certificateId :: Text
forceDelete :: Maybe Bool
$sel:certificateId:DeleteCertificate' :: DeleteCertificate -> Text
$sel:forceDelete:DeleteCertificate' :: DeleteCertificate -> Maybe Bool
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"forceDelete" ByteString -> Maybe Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Bool
forceDelete]

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

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

instance Prelude.NFData DeleteCertificateResponse