{-# 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.RespondDecisionTaskCompleted
-- 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)
--
-- Used by deciders to tell the service that the DecisionTask identified by
-- the @taskToken@ has successfully completed. The @decisions@ argument
-- specifies the list of decisions made while processing the task.
--
-- A @DecisionTaskCompleted@ event is added to the workflow history. The
-- @executionContext@ specified is attached to the event in the workflow
-- execution history.
--
-- __Access Control__
--
-- If an IAM policy grants permission to use
-- @RespondDecisionTaskCompleted@, it can express permissions for the list
-- of decisions in the @decisions@ parameter. Each of the decisions has one
-- or more parameters, much like a regular API call. To allow for policies
-- to be as readable as possible, you can express permissions on decisions
-- as if they were actual API calls, including applying conditions to some
-- parameters. For more information, 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.RespondDecisionTaskCompleted
  ( -- * Creating a Request
    RespondDecisionTaskCompleted (..),
    newRespondDecisionTaskCompleted,

    -- * Request Lenses
    respondDecisionTaskCompleted_decisions,
    respondDecisionTaskCompleted_executionContext,
    respondDecisionTaskCompleted_taskToken,

    -- * Destructuring the Response
    RespondDecisionTaskCompletedResponse (..),
    newRespondDecisionTaskCompletedResponse,
  )
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

-- | Input data for a TaskCompleted response to a decision task.
--
-- /See:/ 'newRespondDecisionTaskCompleted' smart constructor.
data RespondDecisionTaskCompleted = RespondDecisionTaskCompleted'
  { -- | The list of decisions (possibly empty) made by the decider while
    -- processing this decision task. See the docs for the Decision structure
    -- for details.
    RespondDecisionTaskCompleted -> Maybe [Decision]
decisions :: Prelude.Maybe [Decision],
    -- | User defined context to add to workflow execution.
    RespondDecisionTaskCompleted -> Maybe Text
executionContext :: Prelude.Maybe Prelude.Text,
    -- | The @taskToken@ from the DecisionTask.
    --
    -- @taskToken@ is generated by the service and should be treated as an
    -- opaque value. If the task is passed to another process, its @taskToken@
    -- must also be passed. This enables it to provide its progress and respond
    -- with results.
    RespondDecisionTaskCompleted -> Text
taskToken :: Prelude.Text
  }
  deriving (RespondDecisionTaskCompleted
-> RespondDecisionTaskCompleted -> Bool
(RespondDecisionTaskCompleted
 -> RespondDecisionTaskCompleted -> Bool)
-> (RespondDecisionTaskCompleted
    -> RespondDecisionTaskCompleted -> Bool)
-> Eq RespondDecisionTaskCompleted
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RespondDecisionTaskCompleted
-> RespondDecisionTaskCompleted -> Bool
$c/= :: RespondDecisionTaskCompleted
-> RespondDecisionTaskCompleted -> Bool
== :: RespondDecisionTaskCompleted
-> RespondDecisionTaskCompleted -> Bool
$c== :: RespondDecisionTaskCompleted
-> RespondDecisionTaskCompleted -> Bool
Prelude.Eq, ReadPrec [RespondDecisionTaskCompleted]
ReadPrec RespondDecisionTaskCompleted
Int -> ReadS RespondDecisionTaskCompleted
ReadS [RespondDecisionTaskCompleted]
(Int -> ReadS RespondDecisionTaskCompleted)
-> ReadS [RespondDecisionTaskCompleted]
-> ReadPrec RespondDecisionTaskCompleted
-> ReadPrec [RespondDecisionTaskCompleted]
-> Read RespondDecisionTaskCompleted
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RespondDecisionTaskCompleted]
$creadListPrec :: ReadPrec [RespondDecisionTaskCompleted]
readPrec :: ReadPrec RespondDecisionTaskCompleted
$creadPrec :: ReadPrec RespondDecisionTaskCompleted
readList :: ReadS [RespondDecisionTaskCompleted]
$creadList :: ReadS [RespondDecisionTaskCompleted]
readsPrec :: Int -> ReadS RespondDecisionTaskCompleted
$creadsPrec :: Int -> ReadS RespondDecisionTaskCompleted
Prelude.Read, Int -> RespondDecisionTaskCompleted -> ShowS
[RespondDecisionTaskCompleted] -> ShowS
RespondDecisionTaskCompleted -> String
(Int -> RespondDecisionTaskCompleted -> ShowS)
-> (RespondDecisionTaskCompleted -> String)
-> ([RespondDecisionTaskCompleted] -> ShowS)
-> Show RespondDecisionTaskCompleted
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RespondDecisionTaskCompleted] -> ShowS
$cshowList :: [RespondDecisionTaskCompleted] -> ShowS
show :: RespondDecisionTaskCompleted -> String
$cshow :: RespondDecisionTaskCompleted -> String
showsPrec :: Int -> RespondDecisionTaskCompleted -> ShowS
$cshowsPrec :: Int -> RespondDecisionTaskCompleted -> ShowS
Prelude.Show, (forall x.
 RespondDecisionTaskCompleted -> Rep RespondDecisionTaskCompleted x)
-> (forall x.
    Rep RespondDecisionTaskCompleted x -> RespondDecisionTaskCompleted)
-> Generic RespondDecisionTaskCompleted
forall x.
Rep RespondDecisionTaskCompleted x -> RespondDecisionTaskCompleted
forall x.
RespondDecisionTaskCompleted -> Rep RespondDecisionTaskCompleted x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RespondDecisionTaskCompleted x -> RespondDecisionTaskCompleted
$cfrom :: forall x.
RespondDecisionTaskCompleted -> Rep RespondDecisionTaskCompleted x
Prelude.Generic)

-- |
-- Create a value of 'RespondDecisionTaskCompleted' 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:
--
-- 'decisions', 'respondDecisionTaskCompleted_decisions' - The list of decisions (possibly empty) made by the decider while
-- processing this decision task. See the docs for the Decision structure
-- for details.
--
-- 'executionContext', 'respondDecisionTaskCompleted_executionContext' - User defined context to add to workflow execution.
--
-- 'taskToken', 'respondDecisionTaskCompleted_taskToken' - The @taskToken@ from the DecisionTask.
--
-- @taskToken@ is generated by the service and should be treated as an
-- opaque value. If the task is passed to another process, its @taskToken@
-- must also be passed. This enables it to provide its progress and respond
-- with results.
newRespondDecisionTaskCompleted ::
  -- | 'taskToken'
  Prelude.Text ->
  RespondDecisionTaskCompleted
newRespondDecisionTaskCompleted :: Text -> RespondDecisionTaskCompleted
newRespondDecisionTaskCompleted Text
pTaskToken_ =
  RespondDecisionTaskCompleted' :: Maybe [Decision]
-> Maybe Text -> Text -> RespondDecisionTaskCompleted
RespondDecisionTaskCompleted'
    { $sel:decisions:RespondDecisionTaskCompleted' :: Maybe [Decision]
decisions =
        Maybe [Decision]
forall a. Maybe a
Prelude.Nothing,
      $sel:executionContext:RespondDecisionTaskCompleted' :: Maybe Text
executionContext = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:taskToken:RespondDecisionTaskCompleted' :: Text
taskToken = Text
pTaskToken_
    }

-- | The list of decisions (possibly empty) made by the decider while
-- processing this decision task. See the docs for the Decision structure
-- for details.
respondDecisionTaskCompleted_decisions :: Lens.Lens' RespondDecisionTaskCompleted (Prelude.Maybe [Decision])
respondDecisionTaskCompleted_decisions :: (Maybe [Decision] -> f (Maybe [Decision]))
-> RespondDecisionTaskCompleted -> f RespondDecisionTaskCompleted
respondDecisionTaskCompleted_decisions = (RespondDecisionTaskCompleted -> Maybe [Decision])
-> (RespondDecisionTaskCompleted
    -> Maybe [Decision] -> RespondDecisionTaskCompleted)
-> Lens
     RespondDecisionTaskCompleted
     RespondDecisionTaskCompleted
     (Maybe [Decision])
     (Maybe [Decision])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RespondDecisionTaskCompleted' {Maybe [Decision]
decisions :: Maybe [Decision]
$sel:decisions:RespondDecisionTaskCompleted' :: RespondDecisionTaskCompleted -> Maybe [Decision]
decisions} -> Maybe [Decision]
decisions) (\s :: RespondDecisionTaskCompleted
s@RespondDecisionTaskCompleted' {} Maybe [Decision]
a -> RespondDecisionTaskCompleted
s {$sel:decisions:RespondDecisionTaskCompleted' :: Maybe [Decision]
decisions = Maybe [Decision]
a} :: RespondDecisionTaskCompleted) ((Maybe [Decision] -> f (Maybe [Decision]))
 -> RespondDecisionTaskCompleted -> f RespondDecisionTaskCompleted)
-> ((Maybe [Decision] -> f (Maybe [Decision]))
    -> Maybe [Decision] -> f (Maybe [Decision]))
-> (Maybe [Decision] -> f (Maybe [Decision]))
-> RespondDecisionTaskCompleted
-> f RespondDecisionTaskCompleted
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Decision] [Decision] [Decision] [Decision]
-> Iso
     (Maybe [Decision])
     (Maybe [Decision])
     (Maybe [Decision])
     (Maybe [Decision])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Decision] [Decision] [Decision] [Decision]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | User defined context to add to workflow execution.
respondDecisionTaskCompleted_executionContext :: Lens.Lens' RespondDecisionTaskCompleted (Prelude.Maybe Prelude.Text)
respondDecisionTaskCompleted_executionContext :: (Maybe Text -> f (Maybe Text))
-> RespondDecisionTaskCompleted -> f RespondDecisionTaskCompleted
respondDecisionTaskCompleted_executionContext = (RespondDecisionTaskCompleted -> Maybe Text)
-> (RespondDecisionTaskCompleted
    -> Maybe Text -> RespondDecisionTaskCompleted)
-> Lens
     RespondDecisionTaskCompleted
     RespondDecisionTaskCompleted
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RespondDecisionTaskCompleted' {Maybe Text
executionContext :: Maybe Text
$sel:executionContext:RespondDecisionTaskCompleted' :: RespondDecisionTaskCompleted -> Maybe Text
executionContext} -> Maybe Text
executionContext) (\s :: RespondDecisionTaskCompleted
s@RespondDecisionTaskCompleted' {} Maybe Text
a -> RespondDecisionTaskCompleted
s {$sel:executionContext:RespondDecisionTaskCompleted' :: Maybe Text
executionContext = Maybe Text
a} :: RespondDecisionTaskCompleted)

-- | The @taskToken@ from the DecisionTask.
--
-- @taskToken@ is generated by the service and should be treated as an
-- opaque value. If the task is passed to another process, its @taskToken@
-- must also be passed. This enables it to provide its progress and respond
-- with results.
respondDecisionTaskCompleted_taskToken :: Lens.Lens' RespondDecisionTaskCompleted Prelude.Text
respondDecisionTaskCompleted_taskToken :: (Text -> f Text)
-> RespondDecisionTaskCompleted -> f RespondDecisionTaskCompleted
respondDecisionTaskCompleted_taskToken = (RespondDecisionTaskCompleted -> Text)
-> (RespondDecisionTaskCompleted
    -> Text -> RespondDecisionTaskCompleted)
-> Lens
     RespondDecisionTaskCompleted RespondDecisionTaskCompleted Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RespondDecisionTaskCompleted' {Text
taskToken :: Text
$sel:taskToken:RespondDecisionTaskCompleted' :: RespondDecisionTaskCompleted -> Text
taskToken} -> Text
taskToken) (\s :: RespondDecisionTaskCompleted
s@RespondDecisionTaskCompleted' {} Text
a -> RespondDecisionTaskCompleted
s {$sel:taskToken:RespondDecisionTaskCompleted' :: Text
taskToken = Text
a} :: RespondDecisionTaskCompleted)

instance Core.AWSRequest RespondDecisionTaskCompleted where
  type
    AWSResponse RespondDecisionTaskCompleted =
      RespondDecisionTaskCompletedResponse
  request :: RespondDecisionTaskCompleted
-> Request RespondDecisionTaskCompleted
request = Service
-> RespondDecisionTaskCompleted
-> Request RespondDecisionTaskCompleted
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy RespondDecisionTaskCompleted
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse RespondDecisionTaskCompleted)))
response =
    AWSResponse RespondDecisionTaskCompleted
-> Logger
-> Service
-> Proxy RespondDecisionTaskCompleted
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse RespondDecisionTaskCompleted)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      AWSResponse RespondDecisionTaskCompleted
RespondDecisionTaskCompletedResponse
RespondDecisionTaskCompletedResponse'

instance
  Prelude.Hashable
    RespondDecisionTaskCompleted

instance Prelude.NFData RespondDecisionTaskCompleted

instance Core.ToHeaders RespondDecisionTaskCompleted where
  toHeaders :: RespondDecisionTaskCompleted -> [Header]
toHeaders =
    [Header] -> RespondDecisionTaskCompleted -> [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.RespondDecisionTaskCompleted" ::
                          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 RespondDecisionTaskCompleted where
  toJSON :: RespondDecisionTaskCompleted -> Value
toJSON RespondDecisionTaskCompleted' {Maybe [Decision]
Maybe Text
Text
taskToken :: Text
executionContext :: Maybe Text
decisions :: Maybe [Decision]
$sel:taskToken:RespondDecisionTaskCompleted' :: RespondDecisionTaskCompleted -> Text
$sel:executionContext:RespondDecisionTaskCompleted' :: RespondDecisionTaskCompleted -> Maybe Text
$sel:decisions:RespondDecisionTaskCompleted' :: RespondDecisionTaskCompleted -> Maybe [Decision]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"decisions" Text -> [Decision] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Decision] -> Pair) -> Maybe [Decision] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Decision]
decisions,
            (Text
"executionContext" 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
executionContext,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"taskToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
taskToken)
          ]
      )

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

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

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

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

instance
  Prelude.NFData
    RespondDecisionTaskCompletedResponse