{-# 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.Proton.CancelServicePipelineDeployment
-- 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 cancel a service pipeline deployment on an
-- UpdateServicePipeline action, if the deployment is @IN_PROGRESS@. For
-- more information, see
-- <https://docs.aws.amazon.com/proton/latest/userguide/ag-svc-pipeline-update.html Update a service pipeline>
-- in the /Proton User guide/.
--
-- The following list includes potential cancellation scenarios.
--
-- -   If the cancellation attempt succeeds, the resulting deployment state
--     is @CANCELLED@.
--
-- -   If the cancellation attempt fails, the resulting deployment state is
--     @FAILED@.
--
-- -   If the current UpdateServicePipeline action succeeds before the
--     cancellation attempt starts, the resulting deployment state is
--     @SUCCEEDED@ and the cancellation attempt has no effect.
module Amazonka.Proton.CancelServicePipelineDeployment
  ( -- * Creating a Request
    CancelServicePipelineDeployment (..),
    newCancelServicePipelineDeployment,

    -- * Request Lenses
    cancelServicePipelineDeployment_serviceName,

    -- * Destructuring the Response
    CancelServicePipelineDeploymentResponse (..),
    newCancelServicePipelineDeploymentResponse,

    -- * Response Lenses
    cancelServicePipelineDeploymentResponse_httpStatus,
    cancelServicePipelineDeploymentResponse_pipeline,
  )
where

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 Amazonka.Proton.Types
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCancelServicePipelineDeployment' smart constructor.
data CancelServicePipelineDeployment = CancelServicePipelineDeployment'
  { -- | The name of the service with the service pipeline deployment to cancel.
    CancelServicePipelineDeployment -> Text
serviceName :: Prelude.Text
  }
  deriving (CancelServicePipelineDeployment
-> CancelServicePipelineDeployment -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelServicePipelineDeployment
-> CancelServicePipelineDeployment -> Bool
$c/= :: CancelServicePipelineDeployment
-> CancelServicePipelineDeployment -> Bool
== :: CancelServicePipelineDeployment
-> CancelServicePipelineDeployment -> Bool
$c== :: CancelServicePipelineDeployment
-> CancelServicePipelineDeployment -> Bool
Prelude.Eq, ReadPrec [CancelServicePipelineDeployment]
ReadPrec CancelServicePipelineDeployment
Int -> ReadS CancelServicePipelineDeployment
ReadS [CancelServicePipelineDeployment]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelServicePipelineDeployment]
$creadListPrec :: ReadPrec [CancelServicePipelineDeployment]
readPrec :: ReadPrec CancelServicePipelineDeployment
$creadPrec :: ReadPrec CancelServicePipelineDeployment
readList :: ReadS [CancelServicePipelineDeployment]
$creadList :: ReadS [CancelServicePipelineDeployment]
readsPrec :: Int -> ReadS CancelServicePipelineDeployment
$creadsPrec :: Int -> ReadS CancelServicePipelineDeployment
Prelude.Read, Int -> CancelServicePipelineDeployment -> ShowS
[CancelServicePipelineDeployment] -> ShowS
CancelServicePipelineDeployment -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelServicePipelineDeployment] -> ShowS
$cshowList :: [CancelServicePipelineDeployment] -> ShowS
show :: CancelServicePipelineDeployment -> String
$cshow :: CancelServicePipelineDeployment -> String
showsPrec :: Int -> CancelServicePipelineDeployment -> ShowS
$cshowsPrec :: Int -> CancelServicePipelineDeployment -> ShowS
Prelude.Show, forall x.
Rep CancelServicePipelineDeployment x
-> CancelServicePipelineDeployment
forall x.
CancelServicePipelineDeployment
-> Rep CancelServicePipelineDeployment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CancelServicePipelineDeployment x
-> CancelServicePipelineDeployment
$cfrom :: forall x.
CancelServicePipelineDeployment
-> Rep CancelServicePipelineDeployment x
Prelude.Generic)

-- |
-- Create a value of 'CancelServicePipelineDeployment' 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:
--
-- 'serviceName', 'cancelServicePipelineDeployment_serviceName' - The name of the service with the service pipeline deployment to cancel.
newCancelServicePipelineDeployment ::
  -- | 'serviceName'
  Prelude.Text ->
  CancelServicePipelineDeployment
newCancelServicePipelineDeployment :: Text -> CancelServicePipelineDeployment
newCancelServicePipelineDeployment Text
pServiceName_ =
  CancelServicePipelineDeployment'
    { $sel:serviceName:CancelServicePipelineDeployment' :: Text
serviceName =
        Text
pServiceName_
    }

-- | The name of the service with the service pipeline deployment to cancel.
cancelServicePipelineDeployment_serviceName :: Lens.Lens' CancelServicePipelineDeployment Prelude.Text
cancelServicePipelineDeployment_serviceName :: Lens' CancelServicePipelineDeployment Text
cancelServicePipelineDeployment_serviceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelServicePipelineDeployment' {Text
serviceName :: Text
$sel:serviceName:CancelServicePipelineDeployment' :: CancelServicePipelineDeployment -> Text
serviceName} -> Text
serviceName) (\s :: CancelServicePipelineDeployment
s@CancelServicePipelineDeployment' {} Text
a -> CancelServicePipelineDeployment
s {$sel:serviceName:CancelServicePipelineDeployment' :: Text
serviceName = Text
a} :: CancelServicePipelineDeployment)

instance
  Core.AWSRequest
    CancelServicePipelineDeployment
  where
  type
    AWSResponse CancelServicePipelineDeployment =
      CancelServicePipelineDeploymentResponse
  request :: (Service -> Service)
-> CancelServicePipelineDeployment
-> Request CancelServicePipelineDeployment
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 CancelServicePipelineDeployment
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse CancelServicePipelineDeployment)))
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 ->
          Int -> ServicePipeline -> CancelServicePipelineDeploymentResponse
CancelServicePipelineDeploymentResponse'
            forall (f :: * -> *) a b. Functor 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))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"pipeline")
      )

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

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

instance
  Data.ToHeaders
    CancelServicePipelineDeployment
  where
  toHeaders :: CancelServicePipelineDeployment -> 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
"AwsProton20200720.CancelServicePipelineDeployment" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

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

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

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

-- | /See:/ 'newCancelServicePipelineDeploymentResponse' smart constructor.
data CancelServicePipelineDeploymentResponse = CancelServicePipelineDeploymentResponse'
  { -- | The response's http status code.
    CancelServicePipelineDeploymentResponse -> Int
httpStatus :: Prelude.Int,
    -- | The service pipeline detail data that\'s returned by Proton.
    CancelServicePipelineDeploymentResponse -> ServicePipeline
pipeline :: ServicePipeline
  }
  deriving (CancelServicePipelineDeploymentResponse
-> CancelServicePipelineDeploymentResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelServicePipelineDeploymentResponse
-> CancelServicePipelineDeploymentResponse -> Bool
$c/= :: CancelServicePipelineDeploymentResponse
-> CancelServicePipelineDeploymentResponse -> Bool
== :: CancelServicePipelineDeploymentResponse
-> CancelServicePipelineDeploymentResponse -> Bool
$c== :: CancelServicePipelineDeploymentResponse
-> CancelServicePipelineDeploymentResponse -> Bool
Prelude.Eq, Int -> CancelServicePipelineDeploymentResponse -> ShowS
[CancelServicePipelineDeploymentResponse] -> ShowS
CancelServicePipelineDeploymentResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelServicePipelineDeploymentResponse] -> ShowS
$cshowList :: [CancelServicePipelineDeploymentResponse] -> ShowS
show :: CancelServicePipelineDeploymentResponse -> String
$cshow :: CancelServicePipelineDeploymentResponse -> String
showsPrec :: Int -> CancelServicePipelineDeploymentResponse -> ShowS
$cshowsPrec :: Int -> CancelServicePipelineDeploymentResponse -> ShowS
Prelude.Show, forall x.
Rep CancelServicePipelineDeploymentResponse x
-> CancelServicePipelineDeploymentResponse
forall x.
CancelServicePipelineDeploymentResponse
-> Rep CancelServicePipelineDeploymentResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CancelServicePipelineDeploymentResponse x
-> CancelServicePipelineDeploymentResponse
$cfrom :: forall x.
CancelServicePipelineDeploymentResponse
-> Rep CancelServicePipelineDeploymentResponse x
Prelude.Generic)

-- |
-- Create a value of 'CancelServicePipelineDeploymentResponse' 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', 'cancelServicePipelineDeploymentResponse_httpStatus' - The response's http status code.
--
-- 'pipeline', 'cancelServicePipelineDeploymentResponse_pipeline' - The service pipeline detail data that\'s returned by Proton.
newCancelServicePipelineDeploymentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'pipeline'
  ServicePipeline ->
  CancelServicePipelineDeploymentResponse
newCancelServicePipelineDeploymentResponse :: Int -> ServicePipeline -> CancelServicePipelineDeploymentResponse
newCancelServicePipelineDeploymentResponse
  Int
pHttpStatus_
  ServicePipeline
pPipeline_ =
    CancelServicePipelineDeploymentResponse'
      { $sel:httpStatus:CancelServicePipelineDeploymentResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:pipeline:CancelServicePipelineDeploymentResponse' :: ServicePipeline
pipeline = ServicePipeline
pPipeline_
      }

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

-- | The service pipeline detail data that\'s returned by Proton.
cancelServicePipelineDeploymentResponse_pipeline :: Lens.Lens' CancelServicePipelineDeploymentResponse ServicePipeline
cancelServicePipelineDeploymentResponse_pipeline :: Lens' CancelServicePipelineDeploymentResponse ServicePipeline
cancelServicePipelineDeploymentResponse_pipeline = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelServicePipelineDeploymentResponse' {ServicePipeline
pipeline :: ServicePipeline
$sel:pipeline:CancelServicePipelineDeploymentResponse' :: CancelServicePipelineDeploymentResponse -> ServicePipeline
pipeline} -> ServicePipeline
pipeline) (\s :: CancelServicePipelineDeploymentResponse
s@CancelServicePipelineDeploymentResponse' {} ServicePipeline
a -> CancelServicePipelineDeploymentResponse
s {$sel:pipeline:CancelServicePipelineDeploymentResponse' :: ServicePipeline
pipeline = ServicePipeline
a} :: CancelServicePipelineDeploymentResponse)

instance
  Prelude.NFData
    CancelServicePipelineDeploymentResponse
  where
  rnf :: CancelServicePipelineDeploymentResponse -> ()
rnf CancelServicePipelineDeploymentResponse' {Int
ServicePipeline
pipeline :: ServicePipeline
httpStatus :: Int
$sel:pipeline:CancelServicePipelineDeploymentResponse' :: CancelServicePipelineDeploymentResponse -> ServicePipeline
$sel:httpStatus:CancelServicePipelineDeploymentResponse' :: CancelServicePipelineDeploymentResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ServicePipeline
pipeline