{-# 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-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)
--
-- 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.Lens as Lens
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
(RequestCancelWorkflowExecution
 -> RequestCancelWorkflowExecution -> Bool)
-> (RequestCancelWorkflowExecution
    -> RequestCancelWorkflowExecution -> Bool)
-> Eq RequestCancelWorkflowExecution
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]
(Int -> ReadS RequestCancelWorkflowExecution)
-> ReadS [RequestCancelWorkflowExecution]
-> ReadPrec RequestCancelWorkflowExecution
-> ReadPrec [RequestCancelWorkflowExecution]
-> Read 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
(Int -> RequestCancelWorkflowExecution -> ShowS)
-> (RequestCancelWorkflowExecution -> String)
-> ([RequestCancelWorkflowExecution] -> ShowS)
-> Show RequestCancelWorkflowExecution
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.
 RequestCancelWorkflowExecution
 -> Rep RequestCancelWorkflowExecution x)
-> (forall x.
    Rep RequestCancelWorkflowExecution x
    -> RequestCancelWorkflowExecution)
-> Generic RequestCancelWorkflowExecution
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' :: Maybe Text -> Text -> Text -> RequestCancelWorkflowExecution
RequestCancelWorkflowExecution'
      { $sel:runId:RequestCancelWorkflowExecution' :: Maybe Text
runId =
          Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> RequestCancelWorkflowExecution
-> f RequestCancelWorkflowExecution
requestCancelWorkflowExecution_runId = (RequestCancelWorkflowExecution -> Maybe Text)
-> (RequestCancelWorkflowExecution
    -> Maybe Text -> RequestCancelWorkflowExecution)
-> Lens
     RequestCancelWorkflowExecution
     RequestCancelWorkflowExecution
     (Maybe Text)
     (Maybe Text)
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 :: (Text -> f Text)
-> RequestCancelWorkflowExecution
-> f RequestCancelWorkflowExecution
requestCancelWorkflowExecution_domain = (RequestCancelWorkflowExecution -> Text)
-> (RequestCancelWorkflowExecution
    -> Text -> RequestCancelWorkflowExecution)
-> Lens
     RequestCancelWorkflowExecution
     RequestCancelWorkflowExecution
     Text
     Text
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 :: (Text -> f Text)
-> RequestCancelWorkflowExecution
-> f RequestCancelWorkflowExecution
requestCancelWorkflowExecution_workflowId = (RequestCancelWorkflowExecution -> Text)
-> (RequestCancelWorkflowExecution
    -> Text -> RequestCancelWorkflowExecution)
-> Lens
     RequestCancelWorkflowExecution
     RequestCancelWorkflowExecution
     Text
     Text
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 :: RequestCancelWorkflowExecution
-> Request RequestCancelWorkflowExecution
request = Service
-> RequestCancelWorkflowExecution
-> Request RequestCancelWorkflowExecution
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy RequestCancelWorkflowExecution
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse RequestCancelWorkflowExecution)))
response =
    AWSResponse RequestCancelWorkflowExecution
-> Logger
-> Service
-> Proxy RequestCancelWorkflowExecution
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse RequestCancelWorkflowExecution)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      AWSResponse RequestCancelWorkflowExecution
RequestCancelWorkflowExecutionResponse
RequestCancelWorkflowExecutionResponse'

instance
  Prelude.Hashable
    RequestCancelWorkflowExecution

instance
  Prelude.NFData
    RequestCancelWorkflowExecution

instance
  Core.ToHeaders
    RequestCancelWorkflowExecution
  where
  toHeaders :: RequestCancelWorkflowExecution -> [Header]
toHeaders =
    [Header] -> RequestCancelWorkflowExecution -> [Header]
forall a b. a -> b -> a
Prelude.const
      ( [[Header]] -> [Header]
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> [Header]
forall a. ToHeader a => HeaderName -> a -> [Header]
Core.=# ( ByteString
"SimpleWorkflowService.RequestCancelWorkflowExecution" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> [Header]
forall a. ToHeader a => HeaderName -> a -> [Header]
Core.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"runId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
runId,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"domain" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
domain),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"workflowId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
workflowId)
          ]
      )

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

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

-- | /See:/ 'newRequestCancelWorkflowExecutionResponse' smart constructor.
data RequestCancelWorkflowExecutionResponse = RequestCancelWorkflowExecutionResponse'
  {
  }
  deriving (RequestCancelWorkflowExecutionResponse
-> RequestCancelWorkflowExecutionResponse -> Bool
(RequestCancelWorkflowExecutionResponse
 -> RequestCancelWorkflowExecutionResponse -> Bool)
-> (RequestCancelWorkflowExecutionResponse
    -> RequestCancelWorkflowExecutionResponse -> Bool)
-> Eq RequestCancelWorkflowExecutionResponse
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]
(Int -> ReadS RequestCancelWorkflowExecutionResponse)
-> ReadS [RequestCancelWorkflowExecutionResponse]
-> ReadPrec RequestCancelWorkflowExecutionResponse
-> ReadPrec [RequestCancelWorkflowExecutionResponse]
-> Read 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
(Int -> RequestCancelWorkflowExecutionResponse -> ShowS)
-> (RequestCancelWorkflowExecutionResponse -> String)
-> ([RequestCancelWorkflowExecutionResponse] -> ShowS)
-> Show RequestCancelWorkflowExecutionResponse
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.
 RequestCancelWorkflowExecutionResponse
 -> Rep RequestCancelWorkflowExecutionResponse x)
-> (forall x.
    Rep RequestCancelWorkflowExecutionResponse x
    -> RequestCancelWorkflowExecutionResponse)
-> Generic RequestCancelWorkflowExecutionResponse
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