{-# 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.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 a Amazon Lightsail bucket.
--
-- When you delete your bucket, the bucket name is released and can be
-- reused for a new bucket in your account or another AWS account.
module Amazonka.Lightsail.DeleteBucket
  ( -- * Creating a Request
    DeleteBucket (..),
    newDeleteBucket,

    -- * Request Lenses
    deleteBucket_forceDelete,
    deleteBucket_bucketName,

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

    -- * Response Lenses
    deleteBucketResponse_operations,
    deleteBucketResponse_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:/ 'newDeleteBucket' smart constructor.
data DeleteBucket = DeleteBucket'
  { -- | A Boolean value that indicates whether to force delete the bucket.
    --
    -- You must force delete the bucket if it has one of the following
    -- conditions:
    --
    -- -   The bucket is the origin of a distribution.
    --
    -- -   The bucket has instances that were granted access to it using the
    --     SetResourceAccessForBucket action.
    --
    -- -   The bucket has objects.
    --
    -- -   The bucket has access keys.
    --
    -- Force deleting a bucket might impact other resources that rely on the
    -- bucket, such as instances, distributions, or software that use the
    -- issued access keys.
    DeleteBucket -> Maybe Bool
forceDelete :: Prelude.Maybe Prelude.Bool,
    -- | The name of the bucket to delete.
    --
    -- Use the GetBuckets action to get a list of bucket names that you can
    -- specify.
    DeleteBucket -> Text
bucketName :: Prelude.Text
  }
  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:
--
-- 'forceDelete', 'deleteBucket_forceDelete' - A Boolean value that indicates whether to force delete the bucket.
--
-- You must force delete the bucket if it has one of the following
-- conditions:
--
-- -   The bucket is the origin of a distribution.
--
-- -   The bucket has instances that were granted access to it using the
--     SetResourceAccessForBucket action.
--
-- -   The bucket has objects.
--
-- -   The bucket has access keys.
--
-- Force deleting a bucket might impact other resources that rely on the
-- bucket, such as instances, distributions, or software that use the
-- issued access keys.
--
-- 'bucketName', 'deleteBucket_bucketName' - The name of the bucket to delete.
--
-- Use the GetBuckets action to get a list of bucket names that you can
-- specify.
newDeleteBucket ::
  -- | 'bucketName'
  Prelude.Text ->
  DeleteBucket
newDeleteBucket :: Text -> DeleteBucket
newDeleteBucket Text
pBucketName_ =
  DeleteBucket' :: Maybe Bool -> Text -> DeleteBucket
DeleteBucket'
    { $sel:forceDelete:DeleteBucket' :: Maybe Bool
forceDelete = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:bucketName:DeleteBucket' :: Text
bucketName = Text
pBucketName_
    }

-- | A Boolean value that indicates whether to force delete the bucket.
--
-- You must force delete the bucket if it has one of the following
-- conditions:
--
-- -   The bucket is the origin of a distribution.
--
-- -   The bucket has instances that were granted access to it using the
--     SetResourceAccessForBucket action.
--
-- -   The bucket has objects.
--
-- -   The bucket has access keys.
--
-- Force deleting a bucket might impact other resources that rely on the
-- bucket, such as instances, distributions, or software that use the
-- issued access keys.
deleteBucket_forceDelete :: Lens.Lens' DeleteBucket (Prelude.Maybe Prelude.Bool)
deleteBucket_forceDelete :: (Maybe Bool -> f (Maybe Bool)) -> DeleteBucket -> f DeleteBucket
deleteBucket_forceDelete = (DeleteBucket -> Maybe Bool)
-> (DeleteBucket -> Maybe Bool -> DeleteBucket)
-> Lens DeleteBucket DeleteBucket (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteBucket' {Maybe Bool
forceDelete :: Maybe Bool
$sel:forceDelete:DeleteBucket' :: DeleteBucket -> Maybe Bool
forceDelete} -> Maybe Bool
forceDelete) (\s :: DeleteBucket
s@DeleteBucket' {} Maybe Bool
a -> DeleteBucket
s {$sel:forceDelete:DeleteBucket' :: Maybe Bool
forceDelete = Maybe Bool
a} :: DeleteBucket)

-- | The name of the bucket to delete.
--
-- Use the GetBuckets action to get a list of bucket names that you can
-- specify.
deleteBucket_bucketName :: Lens.Lens' DeleteBucket Prelude.Text
deleteBucket_bucketName :: (Text -> f Text) -> DeleteBucket -> f DeleteBucket
deleteBucket_bucketName = (DeleteBucket -> Text)
-> (DeleteBucket -> Text -> DeleteBucket)
-> Lens DeleteBucket DeleteBucket Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteBucket' {Text
bucketName :: Text
$sel:bucketName:DeleteBucket' :: DeleteBucket -> Text
bucketName} -> Text
bucketName) (\s :: DeleteBucket
s@DeleteBucket' {} Text
a -> DeleteBucket
s {$sel:bucketName:DeleteBucket' :: Text
bucketName = Text
a} :: DeleteBucket)

instance Core.AWSRequest DeleteBucket where
  type AWSResponse DeleteBucket = DeleteBucketResponse
  request :: DeleteBucket -> Request DeleteBucket
request = Service -> DeleteBucket -> Request DeleteBucket
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteBucket
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteBucket)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DeleteBucket))
-> Logger
-> Service
-> Proxy DeleteBucket
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteBucket)))
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 -> DeleteBucketResponse
DeleteBucketResponse'
            (Maybe [Operation] -> Int -> DeleteBucketResponse)
-> Either String (Maybe [Operation])
-> Either String (Int -> DeleteBucketResponse)
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 -> DeleteBucketResponse)
-> Either String Int -> Either String DeleteBucketResponse
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 DeleteBucket

instance Prelude.NFData DeleteBucket

instance Core.ToHeaders DeleteBucket where
  toHeaders :: DeleteBucket -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DeleteBucket -> 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.DeleteBucket" ::
                          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 DeleteBucket where
  toJSON :: DeleteBucket -> Value
toJSON DeleteBucket' {Maybe Bool
Text
bucketName :: Text
forceDelete :: Maybe Bool
$sel:bucketName:DeleteBucket' :: DeleteBucket -> Text
$sel:forceDelete:DeleteBucket' :: DeleteBucket -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"forceDelete" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
forceDelete,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"bucketName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
bucketName)
          ]
      )

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

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'
  { -- | 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.
    DeleteBucketResponse -> Maybe [Operation]
operations :: Prelude.Maybe [Operation],
    -- | The response's http status code.
    DeleteBucketResponse -> Int
httpStatus :: Prelude.Int
  }
  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.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'operations', 'deleteBucketResponse_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', 'deleteBucketResponse_httpStatus' - The response's http status code.
newDeleteBucketResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteBucketResponse
newDeleteBucketResponse :: Int -> DeleteBucketResponse
newDeleteBucketResponse Int
pHttpStatus_ =
  DeleteBucketResponse' :: Maybe [Operation] -> Int -> DeleteBucketResponse
DeleteBucketResponse'
    { $sel:operations:DeleteBucketResponse' :: Maybe [Operation]
operations = Maybe [Operation]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DeleteBucketResponse' :: 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.
deleteBucketResponse_operations :: Lens.Lens' DeleteBucketResponse (Prelude.Maybe [Operation])
deleteBucketResponse_operations :: (Maybe [Operation] -> f (Maybe [Operation]))
-> DeleteBucketResponse -> f DeleteBucketResponse
deleteBucketResponse_operations = (DeleteBucketResponse -> Maybe [Operation])
-> (DeleteBucketResponse
    -> Maybe [Operation] -> DeleteBucketResponse)
-> Lens
     DeleteBucketResponse
     DeleteBucketResponse
     (Maybe [Operation])
     (Maybe [Operation])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteBucketResponse' {Maybe [Operation]
operations :: Maybe [Operation]
$sel:operations:DeleteBucketResponse' :: DeleteBucketResponse -> Maybe [Operation]
operations} -> Maybe [Operation]
operations) (\s :: DeleteBucketResponse
s@DeleteBucketResponse' {} Maybe [Operation]
a -> DeleteBucketResponse
s {$sel:operations:DeleteBucketResponse' :: Maybe [Operation]
operations = Maybe [Operation]
a} :: DeleteBucketResponse) ((Maybe [Operation] -> f (Maybe [Operation]))
 -> DeleteBucketResponse -> f DeleteBucketResponse)
-> ((Maybe [Operation] -> f (Maybe [Operation]))
    -> Maybe [Operation] -> f (Maybe [Operation]))
-> (Maybe [Operation] -> f (Maybe [Operation]))
-> DeleteBucketResponse
-> f DeleteBucketResponse
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.
deleteBucketResponse_httpStatus :: Lens.Lens' DeleteBucketResponse Prelude.Int
deleteBucketResponse_httpStatus :: (Int -> f Int) -> DeleteBucketResponse -> f DeleteBucketResponse
deleteBucketResponse_httpStatus = (DeleteBucketResponse -> Int)
-> (DeleteBucketResponse -> Int -> DeleteBucketResponse)
-> Lens DeleteBucketResponse DeleteBucketResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteBucketResponse' {Int
httpStatus :: Int
$sel:httpStatus:DeleteBucketResponse' :: DeleteBucketResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: DeleteBucketResponse
s@DeleteBucketResponse' {} Int
a -> DeleteBucketResponse
s {$sel:httpStatus:DeleteBucketResponse' :: Int
httpStatus = Int
a} :: DeleteBucketResponse)

instance Prelude.NFData DeleteBucketResponse