{-# 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.SWF.RequestCancelWorkflowExecution
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Records a @WorkflowExecutionCancelRequested@ event in the currently
-- running workflow execution identified by the given domain, workflowId,
-- and runId. This logically requests the cancellation of the workflow
-- execution as a whole. It is up to the decider to take appropriate
-- actions when it receives an execution history with this event.
--
-- If the runId isn\'t specified, the @WorkflowExecutionCancelRequested@
-- event is recorded in the history of the current open workflow execution
-- with the specified workflowId in the domain.
--
-- Because this action allows the workflow to properly clean up and
-- gracefully close, it should be used instead of
-- TerminateWorkflowExecution when possible.
--
-- __Access Control__
--
-- You can use IAM policies to control this action\'s access to Amazon SWF
-- resources as follows:
--
-- -   Use a @Resource@ element with the domain name to limit the action to
--     only specified domains.
--
-- -   Use an @Action@ element to allow or deny permission to call this
--     action.
--
-- -   You cannot use an IAM policy to constrain this action\'s parameters.
--
-- If the caller doesn\'t have sufficient permissions to invoke the action,
-- or the parameter values fall outside the specified constraints, the
-- action fails. The associated event attribute\'s @cause@ parameter is set
-- to @OPERATION_NOT_PERMITTED@. For details and example IAM policies, see
-- <https://docs.aws.amazon.com/amazonswf/latest/developerguide/swf-dev-iam.html Using IAM to Manage Access to Amazon SWF Workflows>
-- in the /Amazon SWF Developer Guide/.
module Amazonka.SWF.RequestCancelWorkflowExecution
  ( -- * Creating a Request
    RequestCancelWorkflowExecution (..),
    newRequestCancelWorkflowExecution,

    -- * Request Lenses
    requestCancelWorkflowExecution_runId,
    requestCancelWorkflowExecution_domain,
    requestCancelWorkflowExecution_workflowId,

    -- * Destructuring the Response
    RequestCancelWorkflowExecutionResponse (..),
    newRequestCancelWorkflowExecutionResponse,
  )
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 qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SWF.Types

-- | /See:/ 'newRequestCancelWorkflowExecution' smart constructor.
data RequestCancelWorkflowExecution = RequestCancelWorkflowExecution'
  { -- | The runId of the workflow execution to cancel.
    RequestCancelWorkflowExecution -> Maybe Text
runId :: Prelude.Maybe Prelude.Text,
    -- | The name of the domain containing the workflow execution to cancel.
    RequestCancelWorkflowExecution -> Text
domain :: Prelude.Text,
    -- | The workflowId of the workflow execution to cancel.
    RequestCancelWorkflowExecution -> Text
workflowId :: Prelude.Text
  }
  deriving (RequestCancelWorkflowExecution
-> RequestCancelWorkflowExecution -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RequestCancelWorkflowExecution
-> RequestCancelWorkflowExecution -> Bool
$c/= :: RequestCancelWorkflowExecution
-> RequestCancelWorkflowExecution -> Bool
== :: RequestCancelWorkflowExecution
-> RequestCancelWorkflowExecution -> Bool
$c== :: RequestCancelWorkflowExecution
-> RequestCancelWorkflowExecution -> Bool
Prelude.Eq, ReadPrec [RequestCancelWorkflowExecution]
ReadPrec RequestCancelWorkflowExecution
Int -> ReadS RequestCancelWorkflowExecution
ReadS [RequestCancelWorkflowExecution]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RequestCancelWorkflowExecution]
$creadListPrec :: ReadPrec [RequestCancelWorkflowExecution]
readPrec :: ReadPrec RequestCancelWorkflowExecution
$creadPrec :: ReadPrec RequestCancelWorkflowExecution
readList :: ReadS [RequestCancelWorkflowExecution]
$creadList :: ReadS [RequestCancelWorkflowExecution]
readsPrec :: Int -> ReadS RequestCancelWorkflowExecution
$creadsPrec :: Int -> ReadS RequestCancelWorkflowExecution
Prelude.Read, Int -> RequestCancelWorkflowExecution -> ShowS
[RequestCancelWorkflowExecution] -> ShowS
RequestCancelWorkflowExecution -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RequestCancelWorkflowExecution] -> ShowS
$cshowList :: [RequestCancelWorkflowExecution] -> ShowS
show :: RequestCancelWorkflowExecution -> String
$cshow :: RequestCancelWorkflowExecution -> String
showsPrec :: Int -> RequestCancelWorkflowExecution -> ShowS
$cshowsPrec :: Int -> RequestCancelWorkflowExecution -> ShowS
Prelude.Show, forall x.
Rep RequestCancelWorkflowExecution x
-> RequestCancelWorkflowExecution
forall x.
RequestCancelWorkflowExecution
-> Rep RequestCancelWorkflowExecution x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RequestCancelWorkflowExecution x
-> RequestCancelWorkflowExecution
$cfrom :: forall x.
RequestCancelWorkflowExecution
-> Rep RequestCancelWorkflowExecution x
Prelude.Generic)

-- |
-- Create a value of 'RequestCancelWorkflowExecution' 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:
--
-- 'runId', 'requestCancelWorkflowExecution_runId' - The runId of the workflow execution to cancel.
--
-- 'domain', 'requestCancelWorkflowExecution_domain' - The name of the domain containing the workflow execution to cancel.
--
-- 'workflowId', 'requestCancelWorkflowExecution_workflowId' - The workflowId of the workflow execution to cancel.
newRequestCancelWorkflowExecution ::
  -- | 'domain'
  Prelude.Text ->
  -- | 'workflowId'
  Prelude.Text ->
  RequestCancelWorkflowExecution
newRequestCancelWorkflowExecution :: Text -> Text -> RequestCancelWorkflowExecution
newRequestCancelWorkflowExecution
  Text
pDomain_
  Text
pWorkflowId_ =
    RequestCancelWorkflowExecution'
      { $sel:runId:RequestCancelWorkflowExecution' :: Maybe Text
runId =
          forall a. Maybe a
Prelude.Nothing,
        $sel:domain:RequestCancelWorkflowExecution' :: Text
domain = Text
pDomain_,
        $sel:workflowId:RequestCancelWorkflowExecution' :: Text
workflowId = Text
pWorkflowId_
      }

-- | The runId of the workflow execution to cancel.
requestCancelWorkflowExecution_runId :: Lens.Lens' RequestCancelWorkflowExecution (Prelude.Maybe Prelude.Text)
requestCancelWorkflowExecution_runId :: Lens' RequestCancelWorkflowExecution (Maybe Text)
requestCancelWorkflowExecution_runId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RequestCancelWorkflowExecution' {Maybe Text
runId :: Maybe Text
$sel:runId:RequestCancelWorkflowExecution' :: RequestCancelWorkflowExecution -> Maybe Text
runId} -> Maybe Text
runId) (\s :: RequestCancelWorkflowExecution
s@RequestCancelWorkflowExecution' {} Maybe Text
a -> RequestCancelWorkflowExecution
s {$sel:runId:RequestCancelWorkflowExecution' :: Maybe Text
runId = Maybe Text
a} :: RequestCancelWorkflowExecution)

-- | The name of the domain containing the workflow execution to cancel.
requestCancelWorkflowExecution_domain :: Lens.Lens' RequestCancelWorkflowExecution Prelude.Text
requestCancelWorkflowExecution_domain :: Lens' RequestCancelWorkflowExecution Text
requestCancelWorkflowExecution_domain = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RequestCancelWorkflowExecution' {Text
domain :: Text
$sel:domain:RequestCancelWorkflowExecution' :: RequestCancelWorkflowExecution -> Text
domain} -> Text
domain) (\s :: RequestCancelWorkflowExecution
s@RequestCancelWorkflowExecution' {} Text
a -> RequestCancelWorkflowExecution
s {$sel:domain:RequestCancelWorkflowExecution' :: Text
domain = Text
a} :: RequestCancelWorkflowExecution)

-- | The workflowId of the workflow execution to cancel.
requestCancelWorkflowExecution_workflowId :: Lens.Lens' RequestCancelWorkflowExecution Prelude.Text
requestCancelWorkflowExecution_workflowId :: Lens' RequestCancelWorkflowExecution Text
requestCancelWorkflowExecution_workflowId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RequestCancelWorkflowExecution' {Text
workflowId :: Text
$sel:workflowId:RequestCancelWorkflowExecution' :: RequestCancelWorkflowExecution -> Text
workflowId} -> Text
workflowId) (\s :: RequestCancelWorkflowExecution
s@RequestCancelWorkflowExecution' {} Text
a -> RequestCancelWorkflowExecution
s {$sel:workflowId:RequestCancelWorkflowExecution' :: Text
workflowId = Text
a} :: RequestCancelWorkflowExecution)

instance
  Core.AWSRequest
    RequestCancelWorkflowExecution
  where
  type
    AWSResponse RequestCancelWorkflowExecution =
      RequestCancelWorkflowExecutionResponse
  request :: (Service -> Service)
-> RequestCancelWorkflowExecution
-> Request RequestCancelWorkflowExecution
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 RequestCancelWorkflowExecution
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse RequestCancelWorkflowExecution)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      RequestCancelWorkflowExecutionResponse
RequestCancelWorkflowExecutionResponse'

instance
  Prelude.Hashable
    RequestCancelWorkflowExecution
  where
  hashWithSalt :: Int -> RequestCancelWorkflowExecution -> Int
hashWithSalt
    Int
_salt
    RequestCancelWorkflowExecution' {Maybe Text
Text
workflowId :: Text
domain :: Text
runId :: Maybe Text
$sel:workflowId:RequestCancelWorkflowExecution' :: RequestCancelWorkflowExecution -> Text
$sel:domain:RequestCancelWorkflowExecution' :: RequestCancelWorkflowExecution -> Text
$sel:runId:RequestCancelWorkflowExecution' :: RequestCancelWorkflowExecution -> Maybe Text
..} =
      Int
_salt
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
runId
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
domain
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
workflowId

instance
  Prelude.NFData
    RequestCancelWorkflowExecution
  where
  rnf :: RequestCancelWorkflowExecution -> ()
rnf RequestCancelWorkflowExecution' {Maybe Text
Text
workflowId :: Text
domain :: Text
runId :: Maybe Text
$sel:workflowId:RequestCancelWorkflowExecution' :: RequestCancelWorkflowExecution -> Text
$sel:domain:RequestCancelWorkflowExecution' :: RequestCancelWorkflowExecution -> Text
$sel:runId:RequestCancelWorkflowExecution' :: RequestCancelWorkflowExecution -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
runId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
domain
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
workflowId

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

instance Data.ToJSON RequestCancelWorkflowExecution where
  toJSON :: RequestCancelWorkflowExecution -> Value
toJSON RequestCancelWorkflowExecution' {Maybe Text
Text
workflowId :: Text
domain :: Text
runId :: Maybe Text
$sel:workflowId:RequestCancelWorkflowExecution' :: RequestCancelWorkflowExecution -> Text
$sel:domain:RequestCancelWorkflowExecution' :: RequestCancelWorkflowExecution -> Text
$sel:runId:RequestCancelWorkflowExecution' :: RequestCancelWorkflowExecution -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"runId" 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 Text
runId,
            forall a. a -> Maybe a
Prelude.Just (Key
"domain" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
domain),
            forall a. a -> Maybe a
Prelude.Just (Key
"workflowId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
workflowId)
          ]
      )

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

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

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

-- |
-- Create a value of 'RequestCancelWorkflowExecutionResponse' 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.
newRequestCancelWorkflowExecutionResponse ::
  RequestCancelWorkflowExecutionResponse
newRequestCancelWorkflowExecutionResponse :: RequestCancelWorkflowExecutionResponse
newRequestCancelWorkflowExecutionResponse =
  RequestCancelWorkflowExecutionResponse
RequestCancelWorkflowExecutionResponse'

instance
  Prelude.NFData
    RequestCancelWorkflowExecutionResponse
  where
  rnf :: RequestCancelWorkflowExecutionResponse -> ()
rnf RequestCancelWorkflowExecutionResponse
_ = ()