{-# 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-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)
--
-- 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.Lens as Lens
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
(StopDeployment -> StopDeployment -> Bool)
-> (StopDeployment -> StopDeployment -> Bool) -> Eq StopDeployment
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]
(Int -> ReadS StopDeployment)
-> ReadS [StopDeployment]
-> ReadPrec StopDeployment
-> ReadPrec [StopDeployment]
-> Read 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
(Int -> StopDeployment -> ShowS)
-> (StopDeployment -> String)
-> ([StopDeployment] -> ShowS)
-> Show StopDeployment
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. StopDeployment -> Rep StopDeployment x)
-> (forall x. Rep StopDeployment x -> StopDeployment)
-> Generic StopDeployment
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' :: Maybe Bool -> Text -> StopDeployment
StopDeployment'
    { $sel:autoRollbackEnabled:StopDeployment' :: Maybe Bool
autoRollbackEnabled =
        Maybe Bool
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 :: (Maybe Bool -> f (Maybe Bool))
-> StopDeployment -> f StopDeployment
stopDeployment_autoRollbackEnabled = (StopDeployment -> Maybe Bool)
-> (StopDeployment -> Maybe Bool -> StopDeployment)
-> Lens StopDeployment StopDeployment (Maybe Bool) (Maybe Bool)
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 :: (Text -> f Text) -> StopDeployment -> f StopDeployment
stopDeployment_deploymentId = (StopDeployment -> Text)
-> (StopDeployment -> Text -> StopDeployment)
-> Lens StopDeployment StopDeployment Text Text
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 :: StopDeployment -> Request StopDeployment
request = Service -> StopDeployment -> Request StopDeployment
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StopDeployment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopDeployment)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StopDeployment))
-> Logger
-> Service
-> Proxy StopDeployment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopDeployment)))
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 StopStatus -> Maybe Text -> Int -> StopDeploymentResponse
StopDeploymentResponse'
            (Maybe StopStatus -> Maybe Text -> Int -> StopDeploymentResponse)
-> Either String (Maybe StopStatus)
-> Either String (Maybe Text -> Int -> StopDeploymentResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe StopStatus)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"status")
            Either String (Maybe Text -> Int -> StopDeploymentResponse)
-> Either String (Maybe Text)
-> Either String (Int -> StopDeploymentResponse)
forall (f :: * -> *) a b. Applicative f => 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
"statusMessage")
            Either String (Int -> StopDeploymentResponse)
-> Either String Int -> Either String StopDeploymentResponse
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 StopDeployment

instance Prelude.NFData StopDeployment

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

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

instance Core.ToQuery StopDeployment where
  toQuery :: StopDeployment -> QueryString
toQuery = QueryString -> StopDeployment -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(StopDeploymentResponse -> StopDeploymentResponse -> Bool)
-> (StopDeploymentResponse -> StopDeploymentResponse -> Bool)
-> Eq StopDeploymentResponse
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]
(Int -> ReadS StopDeploymentResponse)
-> ReadS [StopDeploymentResponse]
-> ReadPrec StopDeploymentResponse
-> ReadPrec [StopDeploymentResponse]
-> Read 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
(Int -> StopDeploymentResponse -> ShowS)
-> (StopDeploymentResponse -> String)
-> ([StopDeploymentResponse] -> ShowS)
-> Show StopDeploymentResponse
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. StopDeploymentResponse -> Rep StopDeploymentResponse x)
-> (forall x.
    Rep StopDeploymentResponse x -> StopDeploymentResponse)
-> Generic StopDeploymentResponse
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' :: Maybe StopStatus -> Maybe Text -> Int -> StopDeploymentResponse
StopDeploymentResponse'
    { $sel:status:StopDeploymentResponse' :: Maybe StopStatus
status = Maybe StopStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:statusMessage:StopDeploymentResponse' :: Maybe Text
statusMessage = Maybe Text
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 :: (Maybe StopStatus -> f (Maybe StopStatus))
-> StopDeploymentResponse -> f StopDeploymentResponse
stopDeploymentResponse_status = (StopDeploymentResponse -> Maybe StopStatus)
-> (StopDeploymentResponse
    -> Maybe StopStatus -> StopDeploymentResponse)
-> Lens
     StopDeploymentResponse
     StopDeploymentResponse
     (Maybe StopStatus)
     (Maybe StopStatus)
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 :: (Maybe Text -> f (Maybe Text))
-> StopDeploymentResponse -> f StopDeploymentResponse
stopDeploymentResponse_statusMessage = (StopDeploymentResponse -> Maybe Text)
-> (StopDeploymentResponse -> Maybe Text -> StopDeploymentResponse)
-> Lens
     StopDeploymentResponse
     StopDeploymentResponse
     (Maybe Text)
     (Maybe Text)
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 :: (Int -> f Int)
-> StopDeploymentResponse -> f StopDeploymentResponse
stopDeploymentResponse_httpStatus = (StopDeploymentResponse -> Int)
-> (StopDeploymentResponse -> Int -> StopDeploymentResponse)
-> Lens StopDeploymentResponse StopDeploymentResponse Int Int
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