{-# 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-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)
--
-- 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.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:/ '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
(DetachDisk -> DetachDisk -> Bool)
-> (DetachDisk -> DetachDisk -> Bool) -> Eq DetachDisk
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]
(Int -> ReadS DetachDisk)
-> ReadS [DetachDisk]
-> ReadPrec DetachDisk
-> ReadPrec [DetachDisk]
-> Read 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
(Int -> DetachDisk -> ShowS)
-> (DetachDisk -> String)
-> ([DetachDisk] -> ShowS)
-> Show DetachDisk
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. DetachDisk -> Rep DetachDisk x)
-> (forall x. Rep DetachDisk x -> DetachDisk) -> Generic DetachDisk
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' :: Text -> DetachDisk
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 :: (Text -> f Text) -> DetachDisk -> f DetachDisk
detachDisk_diskName = (DetachDisk -> Text)
-> (DetachDisk -> Text -> DetachDisk)
-> Lens DetachDisk DetachDisk Text Text
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 :: DetachDisk -> Request DetachDisk
request = Service -> DetachDisk -> Request DetachDisk
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DetachDisk
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetachDisk)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DetachDisk))
-> Logger
-> Service
-> Proxy DetachDisk
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetachDisk)))
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 -> DetachDiskResponse
DetachDiskResponse'
            (Maybe [Operation] -> Int -> DetachDiskResponse)
-> Either String (Maybe [Operation])
-> Either String (Int -> DetachDiskResponse)
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 -> DetachDiskResponse)
-> Either String Int -> Either String DetachDiskResponse
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 DetachDisk

instance Prelude.NFData DetachDisk

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

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

instance Core.ToQuery DetachDisk where
  toQuery :: DetachDisk -> QueryString
toQuery = QueryString -> DetachDisk -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(DetachDiskResponse -> DetachDiskResponse -> Bool)
-> (DetachDiskResponse -> DetachDiskResponse -> Bool)
-> Eq DetachDiskResponse
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]
(Int -> ReadS DetachDiskResponse)
-> ReadS [DetachDiskResponse]
-> ReadPrec DetachDiskResponse
-> ReadPrec [DetachDiskResponse]
-> Read 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
(Int -> DetachDiskResponse -> ShowS)
-> (DetachDiskResponse -> String)
-> ([DetachDiskResponse] -> ShowS)
-> Show DetachDiskResponse
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. DetachDiskResponse -> Rep DetachDiskResponse x)
-> (forall x. Rep DetachDiskResponse x -> DetachDiskResponse)
-> Generic DetachDiskResponse
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' :: Maybe [Operation] -> Int -> DetachDiskResponse
DetachDiskResponse'
    { $sel:operations:DetachDiskResponse' :: Maybe [Operation]
operations = Maybe [Operation]
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 :: (Maybe [Operation] -> f (Maybe [Operation]))
-> DetachDiskResponse -> f DetachDiskResponse
detachDiskResponse_operations = (DetachDiskResponse -> Maybe [Operation])
-> (DetachDiskResponse -> Maybe [Operation] -> DetachDiskResponse)
-> Lens
     DetachDiskResponse
     DetachDiskResponse
     (Maybe [Operation])
     (Maybe [Operation])
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) ((Maybe [Operation] -> f (Maybe [Operation]))
 -> DetachDiskResponse -> f DetachDiskResponse)
-> ((Maybe [Operation] -> f (Maybe [Operation]))
    -> Maybe [Operation] -> f (Maybe [Operation]))
-> (Maybe [Operation] -> f (Maybe [Operation]))
-> DetachDiskResponse
-> f DetachDiskResponse
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.
detachDiskResponse_httpStatus :: Lens.Lens' DetachDiskResponse Prelude.Int
detachDiskResponse_httpStatus :: (Int -> f Int) -> DetachDiskResponse -> f DetachDiskResponse
detachDiskResponse_httpStatus = (DetachDiskResponse -> Int)
-> (DetachDiskResponse -> Int -> DetachDiskResponse)
-> Lens DetachDiskResponse DetachDiskResponse Int Int
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