{-# 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.CloudHSMV2.DeleteHsm
-- 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 HSM. To specify an HSM, you can use its identifier
-- (ID), the IP address of the HSM\'s elastic network interface (ENI), or
-- the ID of the HSM\'s ENI. You need to specify only one of these values.
-- To find these values, use DescribeClusters.
module Amazonka.CloudHSMV2.DeleteHsm
  ( -- * Creating a Request
    DeleteHsm (..),
    newDeleteHsm,

    -- * Request Lenses
    deleteHsm_eniId,
    deleteHsm_hsmId,
    deleteHsm_eniIp,
    deleteHsm_clusterId,

    -- * Destructuring the Response
    DeleteHsmResponse (..),
    newDeleteHsmResponse,

    -- * Response Lenses
    deleteHsmResponse_hsmId,
    deleteHsmResponse_httpStatus,
  )
where

import Amazonka.CloudHSMV2.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

-- | /See:/ 'newDeleteHsm' smart constructor.
data DeleteHsm = DeleteHsm'
  { -- | The identifier (ID) of the elastic network interface (ENI) of the HSM
    -- that you are deleting.
    DeleteHsm -> Maybe Text
eniId :: Prelude.Maybe Prelude.Text,
    -- | The identifier (ID) of the HSM that you are deleting.
    DeleteHsm -> Maybe Text
hsmId :: Prelude.Maybe Prelude.Text,
    -- | The IP address of the elastic network interface (ENI) of the HSM that
    -- you are deleting.
    DeleteHsm -> Maybe Text
eniIp :: Prelude.Maybe Prelude.Text,
    -- | The identifier (ID) of the cluster that contains the HSM that you are
    -- deleting.
    DeleteHsm -> Text
clusterId :: Prelude.Text
  }
  deriving (DeleteHsm -> DeleteHsm -> Bool
(DeleteHsm -> DeleteHsm -> Bool)
-> (DeleteHsm -> DeleteHsm -> Bool) -> Eq DeleteHsm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteHsm -> DeleteHsm -> Bool
$c/= :: DeleteHsm -> DeleteHsm -> Bool
== :: DeleteHsm -> DeleteHsm -> Bool
$c== :: DeleteHsm -> DeleteHsm -> Bool
Prelude.Eq, ReadPrec [DeleteHsm]
ReadPrec DeleteHsm
Int -> ReadS DeleteHsm
ReadS [DeleteHsm]
(Int -> ReadS DeleteHsm)
-> ReadS [DeleteHsm]
-> ReadPrec DeleteHsm
-> ReadPrec [DeleteHsm]
-> Read DeleteHsm
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteHsm]
$creadListPrec :: ReadPrec [DeleteHsm]
readPrec :: ReadPrec DeleteHsm
$creadPrec :: ReadPrec DeleteHsm
readList :: ReadS [DeleteHsm]
$creadList :: ReadS [DeleteHsm]
readsPrec :: Int -> ReadS DeleteHsm
$creadsPrec :: Int -> ReadS DeleteHsm
Prelude.Read, Int -> DeleteHsm -> ShowS
[DeleteHsm] -> ShowS
DeleteHsm -> String
(Int -> DeleteHsm -> ShowS)
-> (DeleteHsm -> String)
-> ([DeleteHsm] -> ShowS)
-> Show DeleteHsm
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteHsm] -> ShowS
$cshowList :: [DeleteHsm] -> ShowS
show :: DeleteHsm -> String
$cshow :: DeleteHsm -> String
showsPrec :: Int -> DeleteHsm -> ShowS
$cshowsPrec :: Int -> DeleteHsm -> ShowS
Prelude.Show, (forall x. DeleteHsm -> Rep DeleteHsm x)
-> (forall x. Rep DeleteHsm x -> DeleteHsm) -> Generic DeleteHsm
forall x. Rep DeleteHsm x -> DeleteHsm
forall x. DeleteHsm -> Rep DeleteHsm x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteHsm x -> DeleteHsm
$cfrom :: forall x. DeleteHsm -> Rep DeleteHsm x
Prelude.Generic)

-- |
-- Create a value of 'DeleteHsm' 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:
--
-- 'eniId', 'deleteHsm_eniId' - The identifier (ID) of the elastic network interface (ENI) of the HSM
-- that you are deleting.
--
-- 'hsmId', 'deleteHsm_hsmId' - The identifier (ID) of the HSM that you are deleting.
--
-- 'eniIp', 'deleteHsm_eniIp' - The IP address of the elastic network interface (ENI) of the HSM that
-- you are deleting.
--
-- 'clusterId', 'deleteHsm_clusterId' - The identifier (ID) of the cluster that contains the HSM that you are
-- deleting.
newDeleteHsm ::
  -- | 'clusterId'
  Prelude.Text ->
  DeleteHsm
newDeleteHsm :: Text -> DeleteHsm
newDeleteHsm Text
pClusterId_ =
  DeleteHsm' :: Maybe Text -> Maybe Text -> Maybe Text -> Text -> DeleteHsm
DeleteHsm'
    { $sel:eniId:DeleteHsm' :: Maybe Text
eniId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:hsmId:DeleteHsm' :: Maybe Text
hsmId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:eniIp:DeleteHsm' :: Maybe Text
eniIp = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:clusterId:DeleteHsm' :: Text
clusterId = Text
pClusterId_
    }

-- | The identifier (ID) of the elastic network interface (ENI) of the HSM
-- that you are deleting.
deleteHsm_eniId :: Lens.Lens' DeleteHsm (Prelude.Maybe Prelude.Text)
deleteHsm_eniId :: (Maybe Text -> f (Maybe Text)) -> DeleteHsm -> f DeleteHsm
deleteHsm_eniId = (DeleteHsm -> Maybe Text)
-> (DeleteHsm -> Maybe Text -> DeleteHsm)
-> Lens DeleteHsm DeleteHsm (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteHsm' {Maybe Text
eniId :: Maybe Text
$sel:eniId:DeleteHsm' :: DeleteHsm -> Maybe Text
eniId} -> Maybe Text
eniId) (\s :: DeleteHsm
s@DeleteHsm' {} Maybe Text
a -> DeleteHsm
s {$sel:eniId:DeleteHsm' :: Maybe Text
eniId = Maybe Text
a} :: DeleteHsm)

-- | The identifier (ID) of the HSM that you are deleting.
deleteHsm_hsmId :: Lens.Lens' DeleteHsm (Prelude.Maybe Prelude.Text)
deleteHsm_hsmId :: (Maybe Text -> f (Maybe Text)) -> DeleteHsm -> f DeleteHsm
deleteHsm_hsmId = (DeleteHsm -> Maybe Text)
-> (DeleteHsm -> Maybe Text -> DeleteHsm)
-> Lens DeleteHsm DeleteHsm (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteHsm' {Maybe Text
hsmId :: Maybe Text
$sel:hsmId:DeleteHsm' :: DeleteHsm -> Maybe Text
hsmId} -> Maybe Text
hsmId) (\s :: DeleteHsm
s@DeleteHsm' {} Maybe Text
a -> DeleteHsm
s {$sel:hsmId:DeleteHsm' :: Maybe Text
hsmId = Maybe Text
a} :: DeleteHsm)

-- | The IP address of the elastic network interface (ENI) of the HSM that
-- you are deleting.
deleteHsm_eniIp :: Lens.Lens' DeleteHsm (Prelude.Maybe Prelude.Text)
deleteHsm_eniIp :: (Maybe Text -> f (Maybe Text)) -> DeleteHsm -> f DeleteHsm
deleteHsm_eniIp = (DeleteHsm -> Maybe Text)
-> (DeleteHsm -> Maybe Text -> DeleteHsm)
-> Lens DeleteHsm DeleteHsm (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteHsm' {Maybe Text
eniIp :: Maybe Text
$sel:eniIp:DeleteHsm' :: DeleteHsm -> Maybe Text
eniIp} -> Maybe Text
eniIp) (\s :: DeleteHsm
s@DeleteHsm' {} Maybe Text
a -> DeleteHsm
s {$sel:eniIp:DeleteHsm' :: Maybe Text
eniIp = Maybe Text
a} :: DeleteHsm)

-- | The identifier (ID) of the cluster that contains the HSM that you are
-- deleting.
deleteHsm_clusterId :: Lens.Lens' DeleteHsm Prelude.Text
deleteHsm_clusterId :: (Text -> f Text) -> DeleteHsm -> f DeleteHsm
deleteHsm_clusterId = (DeleteHsm -> Text)
-> (DeleteHsm -> Text -> DeleteHsm)
-> Lens DeleteHsm DeleteHsm Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteHsm' {Text
clusterId :: Text
$sel:clusterId:DeleteHsm' :: DeleteHsm -> Text
clusterId} -> Text
clusterId) (\s :: DeleteHsm
s@DeleteHsm' {} Text
a -> DeleteHsm
s {$sel:clusterId:DeleteHsm' :: Text
clusterId = Text
a} :: DeleteHsm)

instance Core.AWSRequest DeleteHsm where
  type AWSResponse DeleteHsm = DeleteHsmResponse
  request :: DeleteHsm -> Request DeleteHsm
request = Service -> DeleteHsm -> Request DeleteHsm
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteHsm
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteHsm)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DeleteHsm))
-> Logger
-> Service
-> Proxy DeleteHsm
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteHsm)))
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 Text -> Int -> DeleteHsmResponse
DeleteHsmResponse'
            (Maybe Text -> Int -> DeleteHsmResponse)
-> Either String (Maybe Text)
-> Either String (Int -> DeleteHsmResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"HsmId")
            Either String (Int -> DeleteHsmResponse)
-> Either String Int -> Either String DeleteHsmResponse
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 DeleteHsm

instance Prelude.NFData DeleteHsm

instance Core.ToHeaders DeleteHsm where
  toHeaders :: DeleteHsm -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DeleteHsm -> 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
"BaldrApiService.DeleteHsm" :: 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 DeleteHsm where
  toJSON :: DeleteHsm -> Value
toJSON DeleteHsm' {Maybe Text
Text
clusterId :: Text
eniIp :: Maybe Text
hsmId :: Maybe Text
eniId :: Maybe Text
$sel:clusterId:DeleteHsm' :: DeleteHsm -> Text
$sel:eniIp:DeleteHsm' :: DeleteHsm -> Maybe Text
$sel:hsmId:DeleteHsm' :: DeleteHsm -> Maybe Text
$sel:eniId:DeleteHsm' :: DeleteHsm -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"EniId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
eniId,
            (Text
"HsmId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
hsmId,
            (Text
"EniIp" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
eniIp,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ClusterId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clusterId)
          ]
      )

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

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

-- | /See:/ 'newDeleteHsmResponse' smart constructor.
data DeleteHsmResponse = DeleteHsmResponse'
  { -- | The identifier (ID) of the HSM that was deleted.
    DeleteHsmResponse -> Maybe Text
hsmId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    DeleteHsmResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DeleteHsmResponse -> DeleteHsmResponse -> Bool
(DeleteHsmResponse -> DeleteHsmResponse -> Bool)
-> (DeleteHsmResponse -> DeleteHsmResponse -> Bool)
-> Eq DeleteHsmResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteHsmResponse -> DeleteHsmResponse -> Bool
$c/= :: DeleteHsmResponse -> DeleteHsmResponse -> Bool
== :: DeleteHsmResponse -> DeleteHsmResponse -> Bool
$c== :: DeleteHsmResponse -> DeleteHsmResponse -> Bool
Prelude.Eq, ReadPrec [DeleteHsmResponse]
ReadPrec DeleteHsmResponse
Int -> ReadS DeleteHsmResponse
ReadS [DeleteHsmResponse]
(Int -> ReadS DeleteHsmResponse)
-> ReadS [DeleteHsmResponse]
-> ReadPrec DeleteHsmResponse
-> ReadPrec [DeleteHsmResponse]
-> Read DeleteHsmResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteHsmResponse]
$creadListPrec :: ReadPrec [DeleteHsmResponse]
readPrec :: ReadPrec DeleteHsmResponse
$creadPrec :: ReadPrec DeleteHsmResponse
readList :: ReadS [DeleteHsmResponse]
$creadList :: ReadS [DeleteHsmResponse]
readsPrec :: Int -> ReadS DeleteHsmResponse
$creadsPrec :: Int -> ReadS DeleteHsmResponse
Prelude.Read, Int -> DeleteHsmResponse -> ShowS
[DeleteHsmResponse] -> ShowS
DeleteHsmResponse -> String
(Int -> DeleteHsmResponse -> ShowS)
-> (DeleteHsmResponse -> String)
-> ([DeleteHsmResponse] -> ShowS)
-> Show DeleteHsmResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteHsmResponse] -> ShowS
$cshowList :: [DeleteHsmResponse] -> ShowS
show :: DeleteHsmResponse -> String
$cshow :: DeleteHsmResponse -> String
showsPrec :: Int -> DeleteHsmResponse -> ShowS
$cshowsPrec :: Int -> DeleteHsmResponse -> ShowS
Prelude.Show, (forall x. DeleteHsmResponse -> Rep DeleteHsmResponse x)
-> (forall x. Rep DeleteHsmResponse x -> DeleteHsmResponse)
-> Generic DeleteHsmResponse
forall x. Rep DeleteHsmResponse x -> DeleteHsmResponse
forall x. DeleteHsmResponse -> Rep DeleteHsmResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteHsmResponse x -> DeleteHsmResponse
$cfrom :: forall x. DeleteHsmResponse -> Rep DeleteHsmResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeleteHsmResponse' 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:
--
-- 'hsmId', 'deleteHsmResponse_hsmId' - The identifier (ID) of the HSM that was deleted.
--
-- 'httpStatus', 'deleteHsmResponse_httpStatus' - The response's http status code.
newDeleteHsmResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteHsmResponse
newDeleteHsmResponse :: Int -> DeleteHsmResponse
newDeleteHsmResponse Int
pHttpStatus_ =
  DeleteHsmResponse' :: Maybe Text -> Int -> DeleteHsmResponse
DeleteHsmResponse'
    { $sel:hsmId:DeleteHsmResponse' :: Maybe Text
hsmId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DeleteHsmResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The identifier (ID) of the HSM that was deleted.
deleteHsmResponse_hsmId :: Lens.Lens' DeleteHsmResponse (Prelude.Maybe Prelude.Text)
deleteHsmResponse_hsmId :: (Maybe Text -> f (Maybe Text))
-> DeleteHsmResponse -> f DeleteHsmResponse
deleteHsmResponse_hsmId = (DeleteHsmResponse -> Maybe Text)
-> (DeleteHsmResponse -> Maybe Text -> DeleteHsmResponse)
-> Lens
     DeleteHsmResponse DeleteHsmResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteHsmResponse' {Maybe Text
hsmId :: Maybe Text
$sel:hsmId:DeleteHsmResponse' :: DeleteHsmResponse -> Maybe Text
hsmId} -> Maybe Text
hsmId) (\s :: DeleteHsmResponse
s@DeleteHsmResponse' {} Maybe Text
a -> DeleteHsmResponse
s {$sel:hsmId:DeleteHsmResponse' :: Maybe Text
hsmId = Maybe Text
a} :: DeleteHsmResponse)

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

instance Prelude.NFData DeleteHsmResponse