{-# 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.CancelServiceInstanceDeployment
-- 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 instance deployment on an
-- UpdateServiceInstance action, if the deployment is @IN_PROGRESS@. For
-- more information, see
-- <https://docs.aws.amazon.com/proton/latest/userguide/ag-svc-instance-update.html Update a service instance>
-- 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 UpdateServiceInstance action succeeds before the
--     cancellation attempt starts, the resulting deployment state is
--     @SUCCEEDED@ and the cancellation attempt has no effect.
module Amazonka.Proton.CancelServiceInstanceDeployment
  ( -- * Creating a Request
    CancelServiceInstanceDeployment (..),
    newCancelServiceInstanceDeployment,

    -- * Request Lenses
    cancelServiceInstanceDeployment_serviceInstanceName,
    cancelServiceInstanceDeployment_serviceName,

    -- * Destructuring the Response
    CancelServiceInstanceDeploymentResponse (..),
    newCancelServiceInstanceDeploymentResponse,

    -- * Response Lenses
    cancelServiceInstanceDeploymentResponse_httpStatus,
    cancelServiceInstanceDeploymentResponse_serviceInstance,
  )
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:/ 'newCancelServiceInstanceDeployment' smart constructor.
data CancelServiceInstanceDeployment = CancelServiceInstanceDeployment'
  { -- | The name of the service instance with the deployment to cancel.
    CancelServiceInstanceDeployment -> Text
serviceInstanceName :: Prelude.Text,
    -- | The name of the service with the service instance deployment to cancel.
    CancelServiceInstanceDeployment -> Text
serviceName :: Prelude.Text
  }
  deriving (CancelServiceInstanceDeployment
-> CancelServiceInstanceDeployment -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelServiceInstanceDeployment
-> CancelServiceInstanceDeployment -> Bool
$c/= :: CancelServiceInstanceDeployment
-> CancelServiceInstanceDeployment -> Bool
== :: CancelServiceInstanceDeployment
-> CancelServiceInstanceDeployment -> Bool
$c== :: CancelServiceInstanceDeployment
-> CancelServiceInstanceDeployment -> Bool
Prelude.Eq, ReadPrec [CancelServiceInstanceDeployment]
ReadPrec CancelServiceInstanceDeployment
Int -> ReadS CancelServiceInstanceDeployment
ReadS [CancelServiceInstanceDeployment]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelServiceInstanceDeployment]
$creadListPrec :: ReadPrec [CancelServiceInstanceDeployment]
readPrec :: ReadPrec CancelServiceInstanceDeployment
$creadPrec :: ReadPrec CancelServiceInstanceDeployment
readList :: ReadS [CancelServiceInstanceDeployment]
$creadList :: ReadS [CancelServiceInstanceDeployment]
readsPrec :: Int -> ReadS CancelServiceInstanceDeployment
$creadsPrec :: Int -> ReadS CancelServiceInstanceDeployment
Prelude.Read, Int -> CancelServiceInstanceDeployment -> ShowS
[CancelServiceInstanceDeployment] -> ShowS
CancelServiceInstanceDeployment -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelServiceInstanceDeployment] -> ShowS
$cshowList :: [CancelServiceInstanceDeployment] -> ShowS
show :: CancelServiceInstanceDeployment -> String
$cshow :: CancelServiceInstanceDeployment -> String
showsPrec :: Int -> CancelServiceInstanceDeployment -> ShowS
$cshowsPrec :: Int -> CancelServiceInstanceDeployment -> ShowS
Prelude.Show, forall x.
Rep CancelServiceInstanceDeployment x
-> CancelServiceInstanceDeployment
forall x.
CancelServiceInstanceDeployment
-> Rep CancelServiceInstanceDeployment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CancelServiceInstanceDeployment x
-> CancelServiceInstanceDeployment
$cfrom :: forall x.
CancelServiceInstanceDeployment
-> Rep CancelServiceInstanceDeployment x
Prelude.Generic)

-- |
-- Create a value of 'CancelServiceInstanceDeployment' 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:
--
-- 'serviceInstanceName', 'cancelServiceInstanceDeployment_serviceInstanceName' - The name of the service instance with the deployment to cancel.
--
-- 'serviceName', 'cancelServiceInstanceDeployment_serviceName' - The name of the service with the service instance deployment to cancel.
newCancelServiceInstanceDeployment ::
  -- | 'serviceInstanceName'
  Prelude.Text ->
  -- | 'serviceName'
  Prelude.Text ->
  CancelServiceInstanceDeployment
newCancelServiceInstanceDeployment :: Text -> Text -> CancelServiceInstanceDeployment
newCancelServiceInstanceDeployment
  Text
pServiceInstanceName_
  Text
pServiceName_ =
    CancelServiceInstanceDeployment'
      { $sel:serviceInstanceName:CancelServiceInstanceDeployment' :: Text
serviceInstanceName =
          Text
pServiceInstanceName_,
        $sel:serviceName:CancelServiceInstanceDeployment' :: Text
serviceName = Text
pServiceName_
      }

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

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

instance
  Core.AWSRequest
    CancelServiceInstanceDeployment
  where
  type
    AWSResponse CancelServiceInstanceDeployment =
      CancelServiceInstanceDeploymentResponse
  request :: (Service -> Service)
-> CancelServiceInstanceDeployment
-> Request CancelServiceInstanceDeployment
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 CancelServiceInstanceDeployment
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse CancelServiceInstanceDeployment)))
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 -> ServiceInstance -> CancelServiceInstanceDeploymentResponse
CancelServiceInstanceDeploymentResponse'
            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
"serviceInstance")
      )

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

instance
  Prelude.NFData
    CancelServiceInstanceDeployment
  where
  rnf :: CancelServiceInstanceDeployment -> ()
rnf CancelServiceInstanceDeployment' {Text
serviceName :: Text
serviceInstanceName :: Text
$sel:serviceName:CancelServiceInstanceDeployment' :: CancelServiceInstanceDeployment -> Text
$sel:serviceInstanceName:CancelServiceInstanceDeployment' :: CancelServiceInstanceDeployment -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
serviceInstanceName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
serviceName

instance
  Data.ToHeaders
    CancelServiceInstanceDeployment
  where
  toHeaders :: CancelServiceInstanceDeployment -> 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.CancelServiceInstanceDeployment" ::
                          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 CancelServiceInstanceDeployment where
  toJSON :: CancelServiceInstanceDeployment -> Value
toJSON CancelServiceInstanceDeployment' {Text
serviceName :: Text
serviceInstanceName :: Text
$sel:serviceName:CancelServiceInstanceDeployment' :: CancelServiceInstanceDeployment -> Text
$sel:serviceInstanceName:CancelServiceInstanceDeployment' :: CancelServiceInstanceDeployment -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"serviceInstanceName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
serviceInstanceName),
            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 CancelServiceInstanceDeployment where
  toPath :: CancelServiceInstanceDeployment -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

-- |
-- Create a value of 'CancelServiceInstanceDeploymentResponse' 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', 'cancelServiceInstanceDeploymentResponse_httpStatus' - The response's http status code.
--
-- 'serviceInstance', 'cancelServiceInstanceDeploymentResponse_serviceInstance' - The service instance summary data that\'s returned by Proton.
newCancelServiceInstanceDeploymentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'serviceInstance'
  ServiceInstance ->
  CancelServiceInstanceDeploymentResponse
newCancelServiceInstanceDeploymentResponse :: Int -> ServiceInstance -> CancelServiceInstanceDeploymentResponse
newCancelServiceInstanceDeploymentResponse
  Int
pHttpStatus_
  ServiceInstance
pServiceInstance_ =
    CancelServiceInstanceDeploymentResponse'
      { $sel:httpStatus:CancelServiceInstanceDeploymentResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:serviceInstance:CancelServiceInstanceDeploymentResponse' :: ServiceInstance
serviceInstance =
          ServiceInstance
pServiceInstance_
      }

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

-- | The service instance summary data that\'s returned by Proton.
cancelServiceInstanceDeploymentResponse_serviceInstance :: Lens.Lens' CancelServiceInstanceDeploymentResponse ServiceInstance
cancelServiceInstanceDeploymentResponse_serviceInstance :: Lens' CancelServiceInstanceDeploymentResponse ServiceInstance
cancelServiceInstanceDeploymentResponse_serviceInstance = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelServiceInstanceDeploymentResponse' {ServiceInstance
serviceInstance :: ServiceInstance
$sel:serviceInstance:CancelServiceInstanceDeploymentResponse' :: CancelServiceInstanceDeploymentResponse -> ServiceInstance
serviceInstance} -> ServiceInstance
serviceInstance) (\s :: CancelServiceInstanceDeploymentResponse
s@CancelServiceInstanceDeploymentResponse' {} ServiceInstance
a -> CancelServiceInstanceDeploymentResponse
s {$sel:serviceInstance:CancelServiceInstanceDeploymentResponse' :: ServiceInstance
serviceInstance = ServiceInstance
a} :: CancelServiceInstanceDeploymentResponse)

instance
  Prelude.NFData
    CancelServiceInstanceDeploymentResponse
  where
  rnf :: CancelServiceInstanceDeploymentResponse -> ()
rnf CancelServiceInstanceDeploymentResponse' {Int
ServiceInstance
serviceInstance :: ServiceInstance
httpStatus :: Int
$sel:serviceInstance:CancelServiceInstanceDeploymentResponse' :: CancelServiceInstanceDeploymentResponse -> ServiceInstance
$sel:httpStatus:CancelServiceInstanceDeploymentResponse' :: CancelServiceInstanceDeploymentResponse -> 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 ServiceInstance
serviceInstance