{-# 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.Lightsail.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 an SSL\/TLS certificate for your Amazon Lightsail content
-- delivery network (CDN) distribution.
--
-- Certificates that are currently attached to a distribution cannot be
-- deleted. Use the @DetachCertificateFromDistribution@ action to detach a
-- certificate from a distribution.
module Amazonka.Lightsail.DeleteCertificate
  ( -- * Creating a Request
    DeleteCertificate (..),
    newDeleteCertificate,

    -- * Request Lenses
    deleteCertificate_certificateName,

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

    -- * Response Lenses
    deleteCertificateResponse_operations,
    deleteCertificateResponse_httpStatus,
  )
where

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

-- | /See:/ 'newDeleteCertificate' smart constructor.
data DeleteCertificate = DeleteCertificate'
  { -- | The name of the certificate to delete.
    --
    -- Use the @GetCertificates@ action to get a list of certificate names that
    -- you can specify.
    DeleteCertificate -> Text
certificateName :: 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:
--
-- 'certificateName', 'deleteCertificate_certificateName' - The name of the certificate to delete.
--
-- Use the @GetCertificates@ action to get a list of certificate names that
-- you can specify.
newDeleteCertificate ::
  -- | 'certificateName'
  Prelude.Text ->
  DeleteCertificate
newDeleteCertificate :: Text -> DeleteCertificate
newDeleteCertificate Text
pCertificateName_ =
  DeleteCertificate' :: Text -> DeleteCertificate
DeleteCertificate'
    { $sel:certificateName:DeleteCertificate' :: Text
certificateName =
        Text
pCertificateName_
    }

-- | The name of the certificate to delete.
--
-- Use the @GetCertificates@ action to get a list of certificate names that
-- you can specify.
deleteCertificate_certificateName :: Lens.Lens' DeleteCertificate Prelude.Text
deleteCertificate_certificateName :: (Text -> f Text) -> DeleteCertificate -> f DeleteCertificate
deleteCertificate_certificateName = (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
certificateName :: Text
$sel:certificateName:DeleteCertificate' :: DeleteCertificate -> Text
certificateName} -> Text
certificateName) (\s :: DeleteCertificate
s@DeleteCertificate' {} Text
a -> DeleteCertificate
s {$sel:certificateName:DeleteCertificate' :: Text
certificateName = 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, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteCertificate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeleteCertificate)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DeleteCertificate))
-> Logger
-> Service
-> Proxy DeleteCertificate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeleteCertificate)))
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 ->
          Maybe [Operation] -> Int -> DeleteCertificateResponse
DeleteCertificateResponse'
            (Maybe [Operation] -> Int -> DeleteCertificateResponse)
-> Either String (Maybe [Operation])
-> Either String (Int -> DeleteCertificateResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [Operation]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"operations" Either String (Maybe (Maybe [Operation]))
-> Maybe [Operation] -> Either String (Maybe [Operation])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Operation]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> DeleteCertificateResponse)
-> Either String Int -> Either String DeleteCertificateResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable DeleteCertificate

instance Prelude.NFData DeleteCertificate

instance Core.ToHeaders DeleteCertificate where
  toHeaders :: DeleteCertificate -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DeleteCertificate -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"Lightsail_20161128.DeleteCertificate" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON DeleteCertificate where
  toJSON :: DeleteCertificate -> Value
toJSON DeleteCertificate' {Text
certificateName :: Text
$sel:certificateName:DeleteCertificate' :: DeleteCertificate -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"certificateName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
certificateName)
          ]
      )

instance Core.ToPath DeleteCertificate where
  toPath :: DeleteCertificate -> ByteString
toPath = ByteString -> DeleteCertificate -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newDeleteCertificateResponse' smart constructor.
data DeleteCertificateResponse = DeleteCertificateResponse'
  { -- | An array of objects that describe the result of the action, such as the
    -- status of the request, the timestamp of the request, and the resources
    -- affected by the request.
    DeleteCertificateResponse -> Maybe [Operation]
operations :: Prelude.Maybe [Operation],
    -- | The response's http status code.
    DeleteCertificateResponse -> Int
httpStatus :: Prelude.Int
  }
  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.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'operations', 'deleteCertificateResponse_operations' - An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
--
-- 'httpStatus', 'deleteCertificateResponse_httpStatus' - The response's http status code.
newDeleteCertificateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteCertificateResponse
newDeleteCertificateResponse :: Int -> DeleteCertificateResponse
newDeleteCertificateResponse Int
pHttpStatus_ =
  DeleteCertificateResponse' :: Maybe [Operation] -> Int -> DeleteCertificateResponse
DeleteCertificateResponse'
    { $sel:operations:DeleteCertificateResponse' :: Maybe [Operation]
operations =
        Maybe [Operation]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DeleteCertificateResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
deleteCertificateResponse_operations :: Lens.Lens' DeleteCertificateResponse (Prelude.Maybe [Operation])
deleteCertificateResponse_operations :: (Maybe [Operation] -> f (Maybe [Operation]))
-> DeleteCertificateResponse -> f DeleteCertificateResponse
deleteCertificateResponse_operations = (DeleteCertificateResponse -> Maybe [Operation])
-> (DeleteCertificateResponse
    -> Maybe [Operation] -> DeleteCertificateResponse)
-> Lens
     DeleteCertificateResponse
     DeleteCertificateResponse
     (Maybe [Operation])
     (Maybe [Operation])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteCertificateResponse' {Maybe [Operation]
operations :: Maybe [Operation]
$sel:operations:DeleteCertificateResponse' :: DeleteCertificateResponse -> Maybe [Operation]
operations} -> Maybe [Operation]
operations) (\s :: DeleteCertificateResponse
s@DeleteCertificateResponse' {} Maybe [Operation]
a -> DeleteCertificateResponse
s {$sel:operations:DeleteCertificateResponse' :: Maybe [Operation]
operations = Maybe [Operation]
a} :: DeleteCertificateResponse) ((Maybe [Operation] -> f (Maybe [Operation]))
 -> DeleteCertificateResponse -> f DeleteCertificateResponse)
-> ((Maybe [Operation] -> f (Maybe [Operation]))
    -> Maybe [Operation] -> f (Maybe [Operation]))
-> (Maybe [Operation] -> f (Maybe [Operation]))
-> DeleteCertificateResponse
-> f DeleteCertificateResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Operation] [Operation] [Operation] [Operation]
-> Iso
     (Maybe [Operation])
     (Maybe [Operation])
     (Maybe [Operation])
     (Maybe [Operation])
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 [Operation] [Operation] [Operation] [Operation]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The response's http status code.
deleteCertificateResponse_httpStatus :: Lens.Lens' DeleteCertificateResponse Prelude.Int
deleteCertificateResponse_httpStatus :: (Int -> f Int)
-> DeleteCertificateResponse -> f DeleteCertificateResponse
deleteCertificateResponse_httpStatus = (DeleteCertificateResponse -> Int)
-> (DeleteCertificateResponse -> Int -> DeleteCertificateResponse)
-> Lens DeleteCertificateResponse DeleteCertificateResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteCertificateResponse' {Int
httpStatus :: Int
$sel:httpStatus:DeleteCertificateResponse' :: DeleteCertificateResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: DeleteCertificateResponse
s@DeleteCertificateResponse' {} Int
a -> DeleteCertificateResponse
s {$sel:httpStatus:DeleteCertificateResponse' :: Int
httpStatus = Int
a} :: DeleteCertificateResponse)

instance Prelude.NFData DeleteCertificateResponse