{-# 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.DetachDisk
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Detaches a stopped block storage disk from a Lightsail instance. Make
-- sure to unmount any file systems on the device within your operating
-- system before stopping the instance and detaching the disk.
--
-- The @detach disk@ operation supports tag-based access control via
-- resource tags applied to the resource identified by @disk name@. For
-- more information, see the
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-controlling-access-using-tags Amazon Lightsail Developer Guide>.
module Amazonka.Lightsail.DetachDisk
  ( -- * Creating a Request
    DetachDisk (..),
    newDetachDisk,

    -- * Request Lenses
    detachDisk_diskName,

    -- * Destructuring the Response
    DetachDiskResponse (..),
    newDetachDiskResponse,

    -- * Response Lenses
    detachDiskResponse_operations,
    detachDiskResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Lightsail.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newDetachDisk' smart constructor.
data DetachDisk = DetachDisk'
  { -- | The unique name of the disk you want to detach from your instance (e.g.,
    -- @my-disk@).
    DetachDisk -> Text
diskName :: Prelude.Text
  }
  deriving (DetachDisk -> DetachDisk -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetachDisk -> DetachDisk -> Bool
$c/= :: DetachDisk -> DetachDisk -> Bool
== :: DetachDisk -> DetachDisk -> Bool
$c== :: DetachDisk -> DetachDisk -> Bool
Prelude.Eq, ReadPrec [DetachDisk]
ReadPrec DetachDisk
Int -> ReadS DetachDisk
ReadS [DetachDisk]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetachDisk]
$creadListPrec :: ReadPrec [DetachDisk]
readPrec :: ReadPrec DetachDisk
$creadPrec :: ReadPrec DetachDisk
readList :: ReadS [DetachDisk]
$creadList :: ReadS [DetachDisk]
readsPrec :: Int -> ReadS DetachDisk
$creadsPrec :: Int -> ReadS DetachDisk
Prelude.Read, Int -> DetachDisk -> ShowS
[DetachDisk] -> ShowS
DetachDisk -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetachDisk] -> ShowS
$cshowList :: [DetachDisk] -> ShowS
show :: DetachDisk -> String
$cshow :: DetachDisk -> String
showsPrec :: Int -> DetachDisk -> ShowS
$cshowsPrec :: Int -> DetachDisk -> ShowS
Prelude.Show, forall x. Rep DetachDisk x -> DetachDisk
forall x. DetachDisk -> Rep DetachDisk x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetachDisk x -> DetachDisk
$cfrom :: forall x. DetachDisk -> Rep DetachDisk x
Prelude.Generic)

-- |
-- Create a value of 'DetachDisk' 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:
--
-- 'diskName', 'detachDisk_diskName' - The unique name of the disk you want to detach from your instance (e.g.,
-- @my-disk@).
newDetachDisk ::
  -- | 'diskName'
  Prelude.Text ->
  DetachDisk
newDetachDisk :: Text -> DetachDisk
newDetachDisk Text
pDiskName_ =
  DetachDisk' {$sel:diskName:DetachDisk' :: Text
diskName = Text
pDiskName_}

-- | The unique name of the disk you want to detach from your instance (e.g.,
-- @my-disk@).
detachDisk_diskName :: Lens.Lens' DetachDisk Prelude.Text
detachDisk_diskName :: Lens' DetachDisk Text
detachDisk_diskName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachDisk' {Text
diskName :: Text
$sel:diskName:DetachDisk' :: DetachDisk -> Text
diskName} -> Text
diskName) (\s :: DetachDisk
s@DetachDisk' {} Text
a -> DetachDisk
s {$sel:diskName:DetachDisk' :: Text
diskName = Text
a} :: DetachDisk)

instance Core.AWSRequest DetachDisk where
  type AWSResponse DetachDisk = DetachDiskResponse
  request :: (Service -> Service) -> DetachDisk -> Request DetachDisk
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy DetachDisk
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetachDisk)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [Operation] -> Int -> DetachDiskResponse
DetachDiskResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"operations" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable DetachDisk where
  hashWithSalt :: Int -> DetachDisk -> Int
hashWithSalt Int
_salt DetachDisk' {Text
diskName :: Text
$sel:diskName:DetachDisk' :: DetachDisk -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
diskName

instance Prelude.NFData DetachDisk where
  rnf :: DetachDisk -> ()
rnf DetachDisk' {Text
diskName :: Text
$sel:diskName:DetachDisk' :: DetachDisk -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
diskName

instance Data.ToHeaders DetachDisk where
  toHeaders :: DetachDisk -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"Lightsail_20161128.DetachDisk" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON DetachDisk where
  toJSON :: DetachDisk -> Value
toJSON DetachDisk' {Text
diskName :: Text
$sel:diskName:DetachDisk' :: DetachDisk -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"diskName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
diskName)]
      )

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

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

-- | /See:/ 'newDetachDiskResponse' smart constructor.
data DetachDiskResponse = DetachDiskResponse'
  { -- | 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.
    DetachDiskResponse -> Maybe [Operation]
operations :: Prelude.Maybe [Operation],
    -- | The response's http status code.
    DetachDiskResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DetachDiskResponse -> DetachDiskResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetachDiskResponse -> DetachDiskResponse -> Bool
$c/= :: DetachDiskResponse -> DetachDiskResponse -> Bool
== :: DetachDiskResponse -> DetachDiskResponse -> Bool
$c== :: DetachDiskResponse -> DetachDiskResponse -> Bool
Prelude.Eq, ReadPrec [DetachDiskResponse]
ReadPrec DetachDiskResponse
Int -> ReadS DetachDiskResponse
ReadS [DetachDiskResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetachDiskResponse]
$creadListPrec :: ReadPrec [DetachDiskResponse]
readPrec :: ReadPrec DetachDiskResponse
$creadPrec :: ReadPrec DetachDiskResponse
readList :: ReadS [DetachDiskResponse]
$creadList :: ReadS [DetachDiskResponse]
readsPrec :: Int -> ReadS DetachDiskResponse
$creadsPrec :: Int -> ReadS DetachDiskResponse
Prelude.Read, Int -> DetachDiskResponse -> ShowS
[DetachDiskResponse] -> ShowS
DetachDiskResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetachDiskResponse] -> ShowS
$cshowList :: [DetachDiskResponse] -> ShowS
show :: DetachDiskResponse -> String
$cshow :: DetachDiskResponse -> String
showsPrec :: Int -> DetachDiskResponse -> ShowS
$cshowsPrec :: Int -> DetachDiskResponse -> ShowS
Prelude.Show, forall x. Rep DetachDiskResponse x -> DetachDiskResponse
forall x. DetachDiskResponse -> Rep DetachDiskResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetachDiskResponse x -> DetachDiskResponse
$cfrom :: forall x. DetachDiskResponse -> Rep DetachDiskResponse x
Prelude.Generic)

-- |
-- Create a value of 'DetachDiskResponse' 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', 'detachDiskResponse_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', 'detachDiskResponse_httpStatus' - The response's http status code.
newDetachDiskResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DetachDiskResponse
newDetachDiskResponse :: Int -> DetachDiskResponse
newDetachDiskResponse Int
pHttpStatus_ =
  DetachDiskResponse'
    { $sel:operations:DetachDiskResponse' :: Maybe [Operation]
operations = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DetachDiskResponse' :: 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.
detachDiskResponse_operations :: Lens.Lens' DetachDiskResponse (Prelude.Maybe [Operation])
detachDiskResponse_operations :: Lens' DetachDiskResponse (Maybe [Operation])
detachDiskResponse_operations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachDiskResponse' {Maybe [Operation]
operations :: Maybe [Operation]
$sel:operations:DetachDiskResponse' :: DetachDiskResponse -> Maybe [Operation]
operations} -> Maybe [Operation]
operations) (\s :: DetachDiskResponse
s@DetachDiskResponse' {} Maybe [Operation]
a -> DetachDiskResponse
s {$sel:operations:DetachDiskResponse' :: Maybe [Operation]
operations = Maybe [Operation]
a} :: DetachDiskResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData DetachDiskResponse where
  rnf :: DetachDiskResponse -> ()
rnf DetachDiskResponse' {Int
Maybe [Operation]
httpStatus :: Int
operations :: Maybe [Operation]
$sel:httpStatus:DetachDiskResponse' :: DetachDiskResponse -> Int
$sel:operations:DetachDiskResponse' :: DetachDiskResponse -> Maybe [Operation]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Operation]
operations
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus