{-# 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.S3.DeleteBucket
-- 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 S3 bucket. All objects (including all object versions and
-- delete markers) in the bucket must be deleted before the bucket itself
-- can be deleted.
--
-- __Related Resources__
--
-- -   <https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html CreateBucket>
--
-- -   <https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObject.html DeleteObject>
module Amazonka.S3.DeleteBucket
  ( -- * Creating a Request
    DeleteBucket (..),
    newDeleteBucket,

    -- * Request Lenses
    deleteBucket_expectedBucketOwner,
    deleteBucket_bucket,

    -- * Destructuring the Response
    DeleteBucketResponse (..),
    newDeleteBucketResponse,
  )
where

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
import Amazonka.S3.Types

-- | /See:/ 'newDeleteBucket' smart constructor.
data DeleteBucket = DeleteBucket'
  { -- | The account ID of the expected bucket owner. If the bucket is owned by a
    -- different account, the request will fail with an HTTP
    -- @403 (Access Denied)@ error.
    DeleteBucket -> Maybe Text
expectedBucketOwner :: Prelude.Maybe Prelude.Text,
    -- | Specifies the bucket being deleted.
    DeleteBucket -> BucketName
bucket :: BucketName
  }
  deriving (DeleteBucket -> DeleteBucket -> Bool
(DeleteBucket -> DeleteBucket -> Bool)
-> (DeleteBucket -> DeleteBucket -> Bool) -> Eq DeleteBucket
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteBucket -> DeleteBucket -> Bool
$c/= :: DeleteBucket -> DeleteBucket -> Bool
== :: DeleteBucket -> DeleteBucket -> Bool
$c== :: DeleteBucket -> DeleteBucket -> Bool
Prelude.Eq, ReadPrec [DeleteBucket]
ReadPrec DeleteBucket
Int -> ReadS DeleteBucket
ReadS [DeleteBucket]
(Int -> ReadS DeleteBucket)
-> ReadS [DeleteBucket]
-> ReadPrec DeleteBucket
-> ReadPrec [DeleteBucket]
-> Read DeleteBucket
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteBucket]
$creadListPrec :: ReadPrec [DeleteBucket]
readPrec :: ReadPrec DeleteBucket
$creadPrec :: ReadPrec DeleteBucket
readList :: ReadS [DeleteBucket]
$creadList :: ReadS [DeleteBucket]
readsPrec :: Int -> ReadS DeleteBucket
$creadsPrec :: Int -> ReadS DeleteBucket
Prelude.Read, Int -> DeleteBucket -> ShowS
[DeleteBucket] -> ShowS
DeleteBucket -> String
(Int -> DeleteBucket -> ShowS)
-> (DeleteBucket -> String)
-> ([DeleteBucket] -> ShowS)
-> Show DeleteBucket
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteBucket] -> ShowS
$cshowList :: [DeleteBucket] -> ShowS
show :: DeleteBucket -> String
$cshow :: DeleteBucket -> String
showsPrec :: Int -> DeleteBucket -> ShowS
$cshowsPrec :: Int -> DeleteBucket -> ShowS
Prelude.Show, (forall x. DeleteBucket -> Rep DeleteBucket x)
-> (forall x. Rep DeleteBucket x -> DeleteBucket)
-> Generic DeleteBucket
forall x. Rep DeleteBucket x -> DeleteBucket
forall x. DeleteBucket -> Rep DeleteBucket x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteBucket x -> DeleteBucket
$cfrom :: forall x. DeleteBucket -> Rep DeleteBucket x
Prelude.Generic)

-- |
-- Create a value of 'DeleteBucket' 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:
--
-- 'expectedBucketOwner', 'deleteBucket_expectedBucketOwner' - The account ID of the expected bucket owner. If the bucket is owned by a
-- different account, the request will fail with an HTTP
-- @403 (Access Denied)@ error.
--
-- 'bucket', 'deleteBucket_bucket' - Specifies the bucket being deleted.
newDeleteBucket ::
  -- | 'bucket'
  BucketName ->
  DeleteBucket
newDeleteBucket :: BucketName -> DeleteBucket
newDeleteBucket BucketName
pBucket_ =
  DeleteBucket' :: Maybe Text -> BucketName -> DeleteBucket
DeleteBucket'
    { $sel:expectedBucketOwner:DeleteBucket' :: Maybe Text
expectedBucketOwner =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:bucket:DeleteBucket' :: BucketName
bucket = BucketName
pBucket_
    }

-- | The account ID of the expected bucket owner. If the bucket is owned by a
-- different account, the request will fail with an HTTP
-- @403 (Access Denied)@ error.
deleteBucket_expectedBucketOwner :: Lens.Lens' DeleteBucket (Prelude.Maybe Prelude.Text)
deleteBucket_expectedBucketOwner :: (Maybe Text -> f (Maybe Text)) -> DeleteBucket -> f DeleteBucket
deleteBucket_expectedBucketOwner = (DeleteBucket -> Maybe Text)
-> (DeleteBucket -> Maybe Text -> DeleteBucket)
-> Lens DeleteBucket DeleteBucket (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteBucket' {Maybe Text
expectedBucketOwner :: Maybe Text
$sel:expectedBucketOwner:DeleteBucket' :: DeleteBucket -> Maybe Text
expectedBucketOwner} -> Maybe Text
expectedBucketOwner) (\s :: DeleteBucket
s@DeleteBucket' {} Maybe Text
a -> DeleteBucket
s {$sel:expectedBucketOwner:DeleteBucket' :: Maybe Text
expectedBucketOwner = Maybe Text
a} :: DeleteBucket)

-- | Specifies the bucket being deleted.
deleteBucket_bucket :: Lens.Lens' DeleteBucket BucketName
deleteBucket_bucket :: (BucketName -> f BucketName) -> DeleteBucket -> f DeleteBucket
deleteBucket_bucket = (DeleteBucket -> BucketName)
-> (DeleteBucket -> BucketName -> DeleteBucket)
-> Lens DeleteBucket DeleteBucket BucketName BucketName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteBucket' {BucketName
bucket :: BucketName
$sel:bucket:DeleteBucket' :: DeleteBucket -> BucketName
bucket} -> BucketName
bucket) (\s :: DeleteBucket
s@DeleteBucket' {} BucketName
a -> DeleteBucket
s {$sel:bucket:DeleteBucket' :: BucketName
bucket = BucketName
a} :: DeleteBucket)

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

instance Prelude.Hashable DeleteBucket

instance Prelude.NFData DeleteBucket

instance Core.ToHeaders DeleteBucket where
  toHeaders :: DeleteBucket -> [Header]
toHeaders DeleteBucket' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:DeleteBucket' :: DeleteBucket -> BucketName
$sel:expectedBucketOwner:DeleteBucket' :: DeleteBucket -> Maybe Text
..} =
    [[Header]] -> [Header]
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"x-amz-expected-bucket-owner"
          HeaderName -> Maybe Text -> [Header]
forall a. ToHeader a => HeaderName -> a -> [Header]
Core.=# Maybe Text
expectedBucketOwner
      ]

instance Core.ToPath DeleteBucket where
  toPath :: DeleteBucket -> ByteString
toPath DeleteBucket' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:DeleteBucket' :: DeleteBucket -> BucketName
$sel:expectedBucketOwner:DeleteBucket' :: DeleteBucket -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/", BucketName -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS BucketName
bucket]

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

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

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

instance Prelude.NFData DeleteBucketResponse