{-# 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.StorageGateway.DeleteVolume
-- 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 storage volume that you previously created using
-- the CreateCachediSCSIVolume or CreateStorediSCSIVolume API. This
-- operation is only supported in the cached volume and stored volume
-- types. For stored volume gateways, the local disk that was configured as
-- the storage volume is not deleted. You can reuse the local disk to
-- create another storage volume.
--
-- Before you delete a volume, make sure there are no iSCSI connections to
-- the volume you are deleting. You should also make sure there is no
-- snapshot in progress. You can use the Amazon Elastic Compute Cloud
-- (Amazon EC2) API to query snapshots on the volume you are deleting and
-- check the snapshot status. For more information, go to
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSnapshots.html DescribeSnapshots>
-- in the /Amazon Elastic Compute Cloud API Reference/.
--
-- In the request, you must provide the Amazon Resource Name (ARN) of the
-- storage volume you want to delete.
module Amazonka.StorageGateway.DeleteVolume
  ( -- * Creating a Request
    DeleteVolume (..),
    newDeleteVolume,

    -- * Request Lenses
    deleteVolume_volumeARN,

    -- * Destructuring the Response
    DeleteVolumeResponse (..),
    newDeleteVolumeResponse,

    -- * Response Lenses
    deleteVolumeResponse_volumeARN,
    deleteVolumeResponse_httpStatus,
  )
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.StorageGateway.Types

-- | A JSON object containing the DeleteVolumeInput$VolumeARN to delete.
--
-- /See:/ 'newDeleteVolume' smart constructor.
data DeleteVolume = DeleteVolume'
  { -- | The Amazon Resource Name (ARN) of the volume. Use the ListVolumes
    -- operation to return a list of gateway volumes.
    DeleteVolume -> Text
volumeARN :: Prelude.Text
  }
  deriving (DeleteVolume -> DeleteVolume -> Bool
(DeleteVolume -> DeleteVolume -> Bool)
-> (DeleteVolume -> DeleteVolume -> Bool) -> Eq DeleteVolume
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteVolume -> DeleteVolume -> Bool
$c/= :: DeleteVolume -> DeleteVolume -> Bool
== :: DeleteVolume -> DeleteVolume -> Bool
$c== :: DeleteVolume -> DeleteVolume -> Bool
Prelude.Eq, ReadPrec [DeleteVolume]
ReadPrec DeleteVolume
Int -> ReadS DeleteVolume
ReadS [DeleteVolume]
(Int -> ReadS DeleteVolume)
-> ReadS [DeleteVolume]
-> ReadPrec DeleteVolume
-> ReadPrec [DeleteVolume]
-> Read DeleteVolume
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteVolume]
$creadListPrec :: ReadPrec [DeleteVolume]
readPrec :: ReadPrec DeleteVolume
$creadPrec :: ReadPrec DeleteVolume
readList :: ReadS [DeleteVolume]
$creadList :: ReadS [DeleteVolume]
readsPrec :: Int -> ReadS DeleteVolume
$creadsPrec :: Int -> ReadS DeleteVolume
Prelude.Read, Int -> DeleteVolume -> ShowS
[DeleteVolume] -> ShowS
DeleteVolume -> String
(Int -> DeleteVolume -> ShowS)
-> (DeleteVolume -> String)
-> ([DeleteVolume] -> ShowS)
-> Show DeleteVolume
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteVolume] -> ShowS
$cshowList :: [DeleteVolume] -> ShowS
show :: DeleteVolume -> String
$cshow :: DeleteVolume -> String
showsPrec :: Int -> DeleteVolume -> ShowS
$cshowsPrec :: Int -> DeleteVolume -> ShowS
Prelude.Show, (forall x. DeleteVolume -> Rep DeleteVolume x)
-> (forall x. Rep DeleteVolume x -> DeleteVolume)
-> Generic DeleteVolume
forall x. Rep DeleteVolume x -> DeleteVolume
forall x. DeleteVolume -> Rep DeleteVolume x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteVolume x -> DeleteVolume
$cfrom :: forall x. DeleteVolume -> Rep DeleteVolume x
Prelude.Generic)

-- |
-- Create a value of 'DeleteVolume' 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:
--
-- 'volumeARN', 'deleteVolume_volumeARN' - The Amazon Resource Name (ARN) of the volume. Use the ListVolumes
-- operation to return a list of gateway volumes.
newDeleteVolume ::
  -- | 'volumeARN'
  Prelude.Text ->
  DeleteVolume
newDeleteVolume :: Text -> DeleteVolume
newDeleteVolume Text
pVolumeARN_ =
  DeleteVolume' :: Text -> DeleteVolume
DeleteVolume' {$sel:volumeARN:DeleteVolume' :: Text
volumeARN = Text
pVolumeARN_}

-- | The Amazon Resource Name (ARN) of the volume. Use the ListVolumes
-- operation to return a list of gateway volumes.
deleteVolume_volumeARN :: Lens.Lens' DeleteVolume Prelude.Text
deleteVolume_volumeARN :: (Text -> f Text) -> DeleteVolume -> f DeleteVolume
deleteVolume_volumeARN = (DeleteVolume -> Text)
-> (DeleteVolume -> Text -> DeleteVolume)
-> Lens DeleteVolume DeleteVolume Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteVolume' {Text
volumeARN :: Text
$sel:volumeARN:DeleteVolume' :: DeleteVolume -> Text
volumeARN} -> Text
volumeARN) (\s :: DeleteVolume
s@DeleteVolume' {} Text
a -> DeleteVolume
s {$sel:volumeARN:DeleteVolume' :: Text
volumeARN = Text
a} :: DeleteVolume)

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

instance Prelude.NFData DeleteVolume

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

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

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

-- | A JSON object containing the Amazon Resource Name (ARN) of the storage
-- volume that was deleted.
--
-- /See:/ 'newDeleteVolumeResponse' smart constructor.
data DeleteVolumeResponse = DeleteVolumeResponse'
  { -- | The Amazon Resource Name (ARN) of the storage volume that was deleted.
    -- It is the same ARN you provided in the request.
    DeleteVolumeResponse -> Maybe Text
volumeARN :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    DeleteVolumeResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DeleteVolumeResponse -> DeleteVolumeResponse -> Bool
(DeleteVolumeResponse -> DeleteVolumeResponse -> Bool)
-> (DeleteVolumeResponse -> DeleteVolumeResponse -> Bool)
-> Eq DeleteVolumeResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteVolumeResponse -> DeleteVolumeResponse -> Bool
$c/= :: DeleteVolumeResponse -> DeleteVolumeResponse -> Bool
== :: DeleteVolumeResponse -> DeleteVolumeResponse -> Bool
$c== :: DeleteVolumeResponse -> DeleteVolumeResponse -> Bool
Prelude.Eq, ReadPrec [DeleteVolumeResponse]
ReadPrec DeleteVolumeResponse
Int -> ReadS DeleteVolumeResponse
ReadS [DeleteVolumeResponse]
(Int -> ReadS DeleteVolumeResponse)
-> ReadS [DeleteVolumeResponse]
-> ReadPrec DeleteVolumeResponse
-> ReadPrec [DeleteVolumeResponse]
-> Read DeleteVolumeResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteVolumeResponse]
$creadListPrec :: ReadPrec [DeleteVolumeResponse]
readPrec :: ReadPrec DeleteVolumeResponse
$creadPrec :: ReadPrec DeleteVolumeResponse
readList :: ReadS [DeleteVolumeResponse]
$creadList :: ReadS [DeleteVolumeResponse]
readsPrec :: Int -> ReadS DeleteVolumeResponse
$creadsPrec :: Int -> ReadS DeleteVolumeResponse
Prelude.Read, Int -> DeleteVolumeResponse -> ShowS
[DeleteVolumeResponse] -> ShowS
DeleteVolumeResponse -> String
(Int -> DeleteVolumeResponse -> ShowS)
-> (DeleteVolumeResponse -> String)
-> ([DeleteVolumeResponse] -> ShowS)
-> Show DeleteVolumeResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteVolumeResponse] -> ShowS
$cshowList :: [DeleteVolumeResponse] -> ShowS
show :: DeleteVolumeResponse -> String
$cshow :: DeleteVolumeResponse -> String
showsPrec :: Int -> DeleteVolumeResponse -> ShowS
$cshowsPrec :: Int -> DeleteVolumeResponse -> ShowS
Prelude.Show, (forall x. DeleteVolumeResponse -> Rep DeleteVolumeResponse x)
-> (forall x. Rep DeleteVolumeResponse x -> DeleteVolumeResponse)
-> Generic DeleteVolumeResponse
forall x. Rep DeleteVolumeResponse x -> DeleteVolumeResponse
forall x. DeleteVolumeResponse -> Rep DeleteVolumeResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteVolumeResponse x -> DeleteVolumeResponse
$cfrom :: forall x. DeleteVolumeResponse -> Rep DeleteVolumeResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeleteVolumeResponse' 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:
--
-- 'volumeARN', 'deleteVolumeResponse_volumeARN' - The Amazon Resource Name (ARN) of the storage volume that was deleted.
-- It is the same ARN you provided in the request.
--
-- 'httpStatus', 'deleteVolumeResponse_httpStatus' - The response's http status code.
newDeleteVolumeResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteVolumeResponse
newDeleteVolumeResponse :: Int -> DeleteVolumeResponse
newDeleteVolumeResponse Int
pHttpStatus_ =
  DeleteVolumeResponse' :: Maybe Text -> Int -> DeleteVolumeResponse
DeleteVolumeResponse'
    { $sel:volumeARN:DeleteVolumeResponse' :: Maybe Text
volumeARN = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DeleteVolumeResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon Resource Name (ARN) of the storage volume that was deleted.
-- It is the same ARN you provided in the request.
deleteVolumeResponse_volumeARN :: Lens.Lens' DeleteVolumeResponse (Prelude.Maybe Prelude.Text)
deleteVolumeResponse_volumeARN :: (Maybe Text -> f (Maybe Text))
-> DeleteVolumeResponse -> f DeleteVolumeResponse
deleteVolumeResponse_volumeARN = (DeleteVolumeResponse -> Maybe Text)
-> (DeleteVolumeResponse -> Maybe Text -> DeleteVolumeResponse)
-> Lens
     DeleteVolumeResponse DeleteVolumeResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteVolumeResponse' {Maybe Text
volumeARN :: Maybe Text
$sel:volumeARN:DeleteVolumeResponse' :: DeleteVolumeResponse -> Maybe Text
volumeARN} -> Maybe Text
volumeARN) (\s :: DeleteVolumeResponse
s@DeleteVolumeResponse' {} Maybe Text
a -> DeleteVolumeResponse
s {$sel:volumeARN:DeleteVolumeResponse' :: Maybe Text
volumeARN = Maybe Text
a} :: DeleteVolumeResponse)

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

instance Prelude.NFData DeleteVolumeResponse