{-# 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.OpsWorksCM.DeleteServer
-- 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 server and the underlying AWS CloudFormation stacks
-- (including the server\'s EC2 instance). When you run this command, the
-- server state is updated to @DELETING@. After the server is deleted, it
-- is no longer returned by @DescribeServer@ requests. If the AWS
-- CloudFormation stack cannot be deleted, the server cannot be deleted.
--
-- This operation is asynchronous.
--
-- An @InvalidStateException@ is thrown when a server deletion is already
-- in progress. A @ResourceNotFoundException@ is thrown when the server
-- does not exist. A @ValidationException@ is raised when parameters of the
-- request are not valid.
module Amazonka.OpsWorksCM.DeleteServer
  ( -- * Creating a Request
    DeleteServer (..),
    newDeleteServer,

    -- * Request Lenses
    deleteServer_serverName,

    -- * Destructuring the Response
    DeleteServerResponse (..),
    newDeleteServerResponse,

    -- * Response Lenses
    deleteServerResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.OpsWorksCM.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

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

-- |
-- Create a value of 'DeleteServer' 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:
--
-- 'serverName', 'deleteServer_serverName' - The ID of the server to delete.
newDeleteServer ::
  -- | 'serverName'
  Prelude.Text ->
  DeleteServer
newDeleteServer :: Text -> DeleteServer
newDeleteServer Text
pServerName_ =
  DeleteServer' :: Text -> DeleteServer
DeleteServer' {$sel:serverName:DeleteServer' :: Text
serverName = Text
pServerName_}

-- | The ID of the server to delete.
deleteServer_serverName :: Lens.Lens' DeleteServer Prelude.Text
deleteServer_serverName :: (Text -> f Text) -> DeleteServer -> f DeleteServer
deleteServer_serverName = (DeleteServer -> Text)
-> (DeleteServer -> Text -> DeleteServer)
-> Lens DeleteServer DeleteServer Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteServer' {Text
serverName :: Text
$sel:serverName:DeleteServer' :: DeleteServer -> Text
serverName} -> Text
serverName) (\s :: DeleteServer
s@DeleteServer' {} Text
a -> DeleteServer
s {$sel:serverName:DeleteServer' :: Text
serverName = Text
a} :: DeleteServer)

instance Core.AWSRequest DeleteServer where
  type AWSResponse DeleteServer = DeleteServerResponse
  request :: DeleteServer -> Request DeleteServer
request = Service -> DeleteServer -> Request DeleteServer
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteServer
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteServer)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse DeleteServer))
-> Logger
-> Service
-> Proxy DeleteServer
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteServer)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> DeleteServerResponse
DeleteServerResponse'
            (Int -> DeleteServerResponse)
-> Either String Int -> Either String DeleteServerResponse
forall (f :: * -> *) a b. Functor 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 DeleteServer

instance Prelude.NFData DeleteServer

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

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

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

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

-- |
-- Create a value of 'DeleteServerResponse' 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:
--
-- 'httpStatus', 'deleteServerResponse_httpStatus' - The response's http status code.
newDeleteServerResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteServerResponse
newDeleteServerResponse :: Int -> DeleteServerResponse
newDeleteServerResponse Int
pHttpStatus_ =
  DeleteServerResponse' :: Int -> DeleteServerResponse
DeleteServerResponse' {$sel:httpStatus:DeleteServerResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData DeleteServerResponse