{-# 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.DeleteBackup
-- 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 a specified AWS CloudHSM backup. A backup can be restored up to
-- 7 days after the DeleteBackup request is made. For more information on
-- restoring a backup, see RestoreBackup.
module Amazonka.CloudHSMV2.DeleteBackup
  ( -- * Creating a Request
    DeleteBackup (..),
    newDeleteBackup,

    -- * Request Lenses
    deleteBackup_backupId,

    -- * Destructuring the Response
    DeleteBackupResponse (..),
    newDeleteBackupResponse,

    -- * Response Lenses
    deleteBackupResponse_backup,
    deleteBackupResponse_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:/ 'newDeleteBackup' smart constructor.
data DeleteBackup = DeleteBackup'
  { -- | The ID of the backup to be deleted. To find the ID of a backup, use the
    -- DescribeBackups operation.
    DeleteBackup -> Text
backupId :: Prelude.Text
  }
  deriving (DeleteBackup -> DeleteBackup -> Bool
(DeleteBackup -> DeleteBackup -> Bool)
-> (DeleteBackup -> DeleteBackup -> Bool) -> Eq DeleteBackup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteBackup -> DeleteBackup -> Bool
$c/= :: DeleteBackup -> DeleteBackup -> Bool
== :: DeleteBackup -> DeleteBackup -> Bool
$c== :: DeleteBackup -> DeleteBackup -> Bool
Prelude.Eq, ReadPrec [DeleteBackup]
ReadPrec DeleteBackup
Int -> ReadS DeleteBackup
ReadS [DeleteBackup]
(Int -> ReadS DeleteBackup)
-> ReadS [DeleteBackup]
-> ReadPrec DeleteBackup
-> ReadPrec [DeleteBackup]
-> Read DeleteBackup
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteBackup]
$creadListPrec :: ReadPrec [DeleteBackup]
readPrec :: ReadPrec DeleteBackup
$creadPrec :: ReadPrec DeleteBackup
readList :: ReadS [DeleteBackup]
$creadList :: ReadS [DeleteBackup]
readsPrec :: Int -> ReadS DeleteBackup
$creadsPrec :: Int -> ReadS DeleteBackup
Prelude.Read, Int -> DeleteBackup -> ShowS
[DeleteBackup] -> ShowS
DeleteBackup -> String
(Int -> DeleteBackup -> ShowS)
-> (DeleteBackup -> String)
-> ([DeleteBackup] -> ShowS)
-> Show DeleteBackup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteBackup] -> ShowS
$cshowList :: [DeleteBackup] -> ShowS
show :: DeleteBackup -> String
$cshow :: DeleteBackup -> String
showsPrec :: Int -> DeleteBackup -> ShowS
$cshowsPrec :: Int -> DeleteBackup -> ShowS
Prelude.Show, (forall x. DeleteBackup -> Rep DeleteBackup x)
-> (forall x. Rep DeleteBackup x -> DeleteBackup)
-> Generic DeleteBackup
forall x. Rep DeleteBackup x -> DeleteBackup
forall x. DeleteBackup -> Rep DeleteBackup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteBackup x -> DeleteBackup
$cfrom :: forall x. DeleteBackup -> Rep DeleteBackup x
Prelude.Generic)

-- |
-- Create a value of 'DeleteBackup' 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:
--
-- 'backupId', 'deleteBackup_backupId' - The ID of the backup to be deleted. To find the ID of a backup, use the
-- DescribeBackups operation.
newDeleteBackup ::
  -- | 'backupId'
  Prelude.Text ->
  DeleteBackup
newDeleteBackup :: Text -> DeleteBackup
newDeleteBackup Text
pBackupId_ =
  DeleteBackup' :: Text -> DeleteBackup
DeleteBackup' {$sel:backupId:DeleteBackup' :: Text
backupId = Text
pBackupId_}

-- | The ID of the backup to be deleted. To find the ID of a backup, use the
-- DescribeBackups operation.
deleteBackup_backupId :: Lens.Lens' DeleteBackup Prelude.Text
deleteBackup_backupId :: (Text -> f Text) -> DeleteBackup -> f DeleteBackup
deleteBackup_backupId = (DeleteBackup -> Text)
-> (DeleteBackup -> Text -> DeleteBackup)
-> Lens DeleteBackup DeleteBackup Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteBackup' {Text
backupId :: Text
$sel:backupId:DeleteBackup' :: DeleteBackup -> Text
backupId} -> Text
backupId) (\s :: DeleteBackup
s@DeleteBackup' {} Text
a -> DeleteBackup
s {$sel:backupId:DeleteBackup' :: Text
backupId = Text
a} :: DeleteBackup)

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

instance Prelude.NFData DeleteBackup

instance Core.ToHeaders DeleteBackup where
  toHeaders :: DeleteBackup -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DeleteBackup -> 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.DeleteBackup" ::
                          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 DeleteBackup where
  toJSON :: DeleteBackup -> Value
toJSON DeleteBackup' {Text
backupId :: Text
$sel:backupId:DeleteBackup' :: DeleteBackup -> 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
"BackupId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
backupId)]
      )

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

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

-- | /See:/ 'newDeleteBackupResponse' smart constructor.
data DeleteBackupResponse = DeleteBackupResponse'
  { -- | Information on the @Backup@ object deleted.
    DeleteBackupResponse -> Maybe Backup
backup :: Prelude.Maybe Backup,
    -- | The response's http status code.
    DeleteBackupResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DeleteBackupResponse -> DeleteBackupResponse -> Bool
(DeleteBackupResponse -> DeleteBackupResponse -> Bool)
-> (DeleteBackupResponse -> DeleteBackupResponse -> Bool)
-> Eq DeleteBackupResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteBackupResponse -> DeleteBackupResponse -> Bool
$c/= :: DeleteBackupResponse -> DeleteBackupResponse -> Bool
== :: DeleteBackupResponse -> DeleteBackupResponse -> Bool
$c== :: DeleteBackupResponse -> DeleteBackupResponse -> Bool
Prelude.Eq, ReadPrec [DeleteBackupResponse]
ReadPrec DeleteBackupResponse
Int -> ReadS DeleteBackupResponse
ReadS [DeleteBackupResponse]
(Int -> ReadS DeleteBackupResponse)
-> ReadS [DeleteBackupResponse]
-> ReadPrec DeleteBackupResponse
-> ReadPrec [DeleteBackupResponse]
-> Read DeleteBackupResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteBackupResponse]
$creadListPrec :: ReadPrec [DeleteBackupResponse]
readPrec :: ReadPrec DeleteBackupResponse
$creadPrec :: ReadPrec DeleteBackupResponse
readList :: ReadS [DeleteBackupResponse]
$creadList :: ReadS [DeleteBackupResponse]
readsPrec :: Int -> ReadS DeleteBackupResponse
$creadsPrec :: Int -> ReadS DeleteBackupResponse
Prelude.Read, Int -> DeleteBackupResponse -> ShowS
[DeleteBackupResponse] -> ShowS
DeleteBackupResponse -> String
(Int -> DeleteBackupResponse -> ShowS)
-> (DeleteBackupResponse -> String)
-> ([DeleteBackupResponse] -> ShowS)
-> Show DeleteBackupResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteBackupResponse] -> ShowS
$cshowList :: [DeleteBackupResponse] -> ShowS
show :: DeleteBackupResponse -> String
$cshow :: DeleteBackupResponse -> String
showsPrec :: Int -> DeleteBackupResponse -> ShowS
$cshowsPrec :: Int -> DeleteBackupResponse -> ShowS
Prelude.Show, (forall x. DeleteBackupResponse -> Rep DeleteBackupResponse x)
-> (forall x. Rep DeleteBackupResponse x -> DeleteBackupResponse)
-> Generic DeleteBackupResponse
forall x. Rep DeleteBackupResponse x -> DeleteBackupResponse
forall x. DeleteBackupResponse -> Rep DeleteBackupResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteBackupResponse x -> DeleteBackupResponse
$cfrom :: forall x. DeleteBackupResponse -> Rep DeleteBackupResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeleteBackupResponse' 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:
--
-- 'backup', 'deleteBackupResponse_backup' - Information on the @Backup@ object deleted.
--
-- 'httpStatus', 'deleteBackupResponse_httpStatus' - The response's http status code.
newDeleteBackupResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteBackupResponse
newDeleteBackupResponse :: Int -> DeleteBackupResponse
newDeleteBackupResponse Int
pHttpStatus_ =
  DeleteBackupResponse' :: Maybe Backup -> Int -> DeleteBackupResponse
DeleteBackupResponse'
    { $sel:backup:DeleteBackupResponse' :: Maybe Backup
backup = Maybe Backup
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DeleteBackupResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information on the @Backup@ object deleted.
deleteBackupResponse_backup :: Lens.Lens' DeleteBackupResponse (Prelude.Maybe Backup)
deleteBackupResponse_backup :: (Maybe Backup -> f (Maybe Backup))
-> DeleteBackupResponse -> f DeleteBackupResponse
deleteBackupResponse_backup = (DeleteBackupResponse -> Maybe Backup)
-> (DeleteBackupResponse -> Maybe Backup -> DeleteBackupResponse)
-> Lens
     DeleteBackupResponse
     DeleteBackupResponse
     (Maybe Backup)
     (Maybe Backup)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteBackupResponse' {Maybe Backup
backup :: Maybe Backup
$sel:backup:DeleteBackupResponse' :: DeleteBackupResponse -> Maybe Backup
backup} -> Maybe Backup
backup) (\s :: DeleteBackupResponse
s@DeleteBackupResponse' {} Maybe Backup
a -> DeleteBackupResponse
s {$sel:backup:DeleteBackupResponse' :: Maybe Backup
backup = Maybe Backup
a} :: DeleteBackupResponse)

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

instance Prelude.NFData DeleteBackupResponse