{-# 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.CodeDeploy.StopDeployment
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Attempts to stop an ongoing deployment.
module Amazonka.CodeDeploy.StopDeployment
  ( -- * Creating a Request
    StopDeployment (..),
    newStopDeployment,

    -- * Request Lenses
    stopDeployment_autoRollbackEnabled,
    stopDeployment_deploymentId,

    -- * Destructuring the Response
    StopDeploymentResponse (..),
    newStopDeploymentResponse,

    -- * Response Lenses
    stopDeploymentResponse_status,
    stopDeploymentResponse_statusMessage,
    stopDeploymentResponse_httpStatus,
  )
where

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

-- | Represents the input of a @StopDeployment@ operation.
--
-- /See:/ 'newStopDeployment' smart constructor.
data StopDeployment = StopDeployment'
  { -- | Indicates, when a deployment is stopped, whether instances that have
    -- been updated should be rolled back to the previous version of the
    -- application revision.
    StopDeployment -> Maybe Bool
autoRollbackEnabled :: Prelude.Maybe Prelude.Bool,
    -- | The unique ID of a deployment.
    StopDeployment -> Text
deploymentId :: Prelude.Text
  }
  deriving (StopDeployment -> StopDeployment -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopDeployment -> StopDeployment -> Bool
$c/= :: StopDeployment -> StopDeployment -> Bool
== :: StopDeployment -> StopDeployment -> Bool
$c== :: StopDeployment -> StopDeployment -> Bool
Prelude.Eq, ReadPrec [StopDeployment]
ReadPrec StopDeployment
Int -> ReadS StopDeployment
ReadS [StopDeployment]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopDeployment]
$creadListPrec :: ReadPrec [StopDeployment]
readPrec :: ReadPrec StopDeployment
$creadPrec :: ReadPrec StopDeployment
readList :: ReadS [StopDeployment]
$creadList :: ReadS [StopDeployment]
readsPrec :: Int -> ReadS StopDeployment
$creadsPrec :: Int -> ReadS StopDeployment
Prelude.Read, Int -> StopDeployment -> ShowS
[StopDeployment] -> ShowS
StopDeployment -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopDeployment] -> ShowS
$cshowList :: [StopDeployment] -> ShowS
show :: StopDeployment -> String
$cshow :: StopDeployment -> String
showsPrec :: Int -> StopDeployment -> ShowS
$cshowsPrec :: Int -> StopDeployment -> ShowS
Prelude.Show, forall x. Rep StopDeployment x -> StopDeployment
forall x. StopDeployment -> Rep StopDeployment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopDeployment x -> StopDeployment
$cfrom :: forall x. StopDeployment -> Rep StopDeployment x
Prelude.Generic)

-- |
-- Create a value of 'StopDeployment' 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:
--
-- 'autoRollbackEnabled', 'stopDeployment_autoRollbackEnabled' - Indicates, when a deployment is stopped, whether instances that have
-- been updated should be rolled back to the previous version of the
-- application revision.
--
-- 'deploymentId', 'stopDeployment_deploymentId' - The unique ID of a deployment.
newStopDeployment ::
  -- | 'deploymentId'
  Prelude.Text ->
  StopDeployment
newStopDeployment :: Text -> StopDeployment
newStopDeployment Text
pDeploymentId_ =
  StopDeployment'
    { $sel:autoRollbackEnabled:StopDeployment' :: Maybe Bool
autoRollbackEnabled =
        forall a. Maybe a
Prelude.Nothing,
      $sel:deploymentId:StopDeployment' :: Text
deploymentId = Text
pDeploymentId_
    }

-- | Indicates, when a deployment is stopped, whether instances that have
-- been updated should be rolled back to the previous version of the
-- application revision.
stopDeployment_autoRollbackEnabled :: Lens.Lens' StopDeployment (Prelude.Maybe Prelude.Bool)
stopDeployment_autoRollbackEnabled :: Lens' StopDeployment (Maybe Bool)
stopDeployment_autoRollbackEnabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopDeployment' {Maybe Bool
autoRollbackEnabled :: Maybe Bool
$sel:autoRollbackEnabled:StopDeployment' :: StopDeployment -> Maybe Bool
autoRollbackEnabled} -> Maybe Bool
autoRollbackEnabled) (\s :: StopDeployment
s@StopDeployment' {} Maybe Bool
a -> StopDeployment
s {$sel:autoRollbackEnabled:StopDeployment' :: Maybe Bool
autoRollbackEnabled = Maybe Bool
a} :: StopDeployment)

-- | The unique ID of a deployment.
stopDeployment_deploymentId :: Lens.Lens' StopDeployment Prelude.Text
stopDeployment_deploymentId :: Lens' StopDeployment Text
stopDeployment_deploymentId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopDeployment' {Text
deploymentId :: Text
$sel:deploymentId:StopDeployment' :: StopDeployment -> Text
deploymentId} -> Text
deploymentId) (\s :: StopDeployment
s@StopDeployment' {} Text
a -> StopDeployment
s {$sel:deploymentId:StopDeployment' :: Text
deploymentId = Text
a} :: StopDeployment)

instance Core.AWSRequest StopDeployment where
  type
    AWSResponse StopDeployment =
      StopDeploymentResponse
  request :: (Service -> Service) -> StopDeployment -> Request StopDeployment
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 StopDeployment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopDeployment)))
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 StopStatus -> Maybe Text -> Int -> StopDeploymentResponse
StopDeploymentResponse'
            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
"status")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"statusMessage")
            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 StopDeployment where
  hashWithSalt :: Int -> StopDeployment -> Int
hashWithSalt Int
_salt StopDeployment' {Maybe Bool
Text
deploymentId :: Text
autoRollbackEnabled :: Maybe Bool
$sel:deploymentId:StopDeployment' :: StopDeployment -> Text
$sel:autoRollbackEnabled:StopDeployment' :: StopDeployment -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
autoRollbackEnabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
deploymentId

instance Prelude.NFData StopDeployment where
  rnf :: StopDeployment -> ()
rnf StopDeployment' {Maybe Bool
Text
deploymentId :: Text
autoRollbackEnabled :: Maybe Bool
$sel:deploymentId:StopDeployment' :: StopDeployment -> Text
$sel:autoRollbackEnabled:StopDeployment' :: StopDeployment -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
autoRollbackEnabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
deploymentId

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

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

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

-- | Represents the output of a @StopDeployment@ operation.
--
-- /See:/ 'newStopDeploymentResponse' smart constructor.
data StopDeploymentResponse = StopDeploymentResponse'
  { -- | The status of the stop deployment operation:
    --
    -- -   Pending: The stop operation is pending.
    --
    -- -   Succeeded: The stop operation was successful.
    StopDeploymentResponse -> Maybe StopStatus
status :: Prelude.Maybe StopStatus,
    -- | An accompanying status message.
    StopDeploymentResponse -> Maybe Text
statusMessage :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    StopDeploymentResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StopDeploymentResponse -> StopDeploymentResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopDeploymentResponse -> StopDeploymentResponse -> Bool
$c/= :: StopDeploymentResponse -> StopDeploymentResponse -> Bool
== :: StopDeploymentResponse -> StopDeploymentResponse -> Bool
$c== :: StopDeploymentResponse -> StopDeploymentResponse -> Bool
Prelude.Eq, ReadPrec [StopDeploymentResponse]
ReadPrec StopDeploymentResponse
Int -> ReadS StopDeploymentResponse
ReadS [StopDeploymentResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopDeploymentResponse]
$creadListPrec :: ReadPrec [StopDeploymentResponse]
readPrec :: ReadPrec StopDeploymentResponse
$creadPrec :: ReadPrec StopDeploymentResponse
readList :: ReadS [StopDeploymentResponse]
$creadList :: ReadS [StopDeploymentResponse]
readsPrec :: Int -> ReadS StopDeploymentResponse
$creadsPrec :: Int -> ReadS StopDeploymentResponse
Prelude.Read, Int -> StopDeploymentResponse -> ShowS
[StopDeploymentResponse] -> ShowS
StopDeploymentResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopDeploymentResponse] -> ShowS
$cshowList :: [StopDeploymentResponse] -> ShowS
show :: StopDeploymentResponse -> String
$cshow :: StopDeploymentResponse -> String
showsPrec :: Int -> StopDeploymentResponse -> ShowS
$cshowsPrec :: Int -> StopDeploymentResponse -> ShowS
Prelude.Show, forall x. Rep StopDeploymentResponse x -> StopDeploymentResponse
forall x. StopDeploymentResponse -> Rep StopDeploymentResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopDeploymentResponse x -> StopDeploymentResponse
$cfrom :: forall x. StopDeploymentResponse -> Rep StopDeploymentResponse x
Prelude.Generic)

-- |
-- Create a value of 'StopDeploymentResponse' 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:
--
-- 'status', 'stopDeploymentResponse_status' - The status of the stop deployment operation:
--
-- -   Pending: The stop operation is pending.
--
-- -   Succeeded: The stop operation was successful.
--
-- 'statusMessage', 'stopDeploymentResponse_statusMessage' - An accompanying status message.
--
-- 'httpStatus', 'stopDeploymentResponse_httpStatus' - The response's http status code.
newStopDeploymentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StopDeploymentResponse
newStopDeploymentResponse :: Int -> StopDeploymentResponse
newStopDeploymentResponse Int
pHttpStatus_ =
  StopDeploymentResponse'
    { $sel:status:StopDeploymentResponse' :: Maybe StopStatus
status = forall a. Maybe a
Prelude.Nothing,
      $sel:statusMessage:StopDeploymentResponse' :: Maybe Text
statusMessage = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StopDeploymentResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The status of the stop deployment operation:
--
-- -   Pending: The stop operation is pending.
--
-- -   Succeeded: The stop operation was successful.
stopDeploymentResponse_status :: Lens.Lens' StopDeploymentResponse (Prelude.Maybe StopStatus)
stopDeploymentResponse_status :: Lens' StopDeploymentResponse (Maybe StopStatus)
stopDeploymentResponse_status = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopDeploymentResponse' {Maybe StopStatus
status :: Maybe StopStatus
$sel:status:StopDeploymentResponse' :: StopDeploymentResponse -> Maybe StopStatus
status} -> Maybe StopStatus
status) (\s :: StopDeploymentResponse
s@StopDeploymentResponse' {} Maybe StopStatus
a -> StopDeploymentResponse
s {$sel:status:StopDeploymentResponse' :: Maybe StopStatus
status = Maybe StopStatus
a} :: StopDeploymentResponse)

-- | An accompanying status message.
stopDeploymentResponse_statusMessage :: Lens.Lens' StopDeploymentResponse (Prelude.Maybe Prelude.Text)
stopDeploymentResponse_statusMessage :: Lens' StopDeploymentResponse (Maybe Text)
stopDeploymentResponse_statusMessage = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopDeploymentResponse' {Maybe Text
statusMessage :: Maybe Text
$sel:statusMessage:StopDeploymentResponse' :: StopDeploymentResponse -> Maybe Text
statusMessage} -> Maybe Text
statusMessage) (\s :: StopDeploymentResponse
s@StopDeploymentResponse' {} Maybe Text
a -> StopDeploymentResponse
s {$sel:statusMessage:StopDeploymentResponse' :: Maybe Text
statusMessage = Maybe Text
a} :: StopDeploymentResponse)

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

instance Prelude.NFData StopDeploymentResponse where
  rnf :: StopDeploymentResponse -> ()
rnf StopDeploymentResponse' {Int
Maybe Text
Maybe StopStatus
httpStatus :: Int
statusMessage :: Maybe Text
status :: Maybe StopStatus
$sel:httpStatus:StopDeploymentResponse' :: StopDeploymentResponse -> Int
$sel:statusMessage:StopDeploymentResponse' :: StopDeploymentResponse -> Maybe Text
$sel:status:StopDeploymentResponse' :: StopDeploymentResponse -> Maybe StopStatus
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe StopStatus
status
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
statusMessage
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus