{-# 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.RespondActivityTaskCompleted
-- 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 workers to tell the service that the ActivityTask identified by
-- the @taskToken@ completed successfully with a @result@ (if provided).
-- The @result@ appears in the @ActivityTaskCompleted@ event in the
-- workflow history.
--
-- If the requested task doesn\'t complete successfully, use
-- RespondActivityTaskFailed instead. If the worker finds that the task is
-- canceled through the @canceled@ flag returned by
-- RecordActivityTaskHeartbeat, it should cancel the task, clean up and
-- then call RespondActivityTaskCanceled.
--
-- A task is considered open from the time that it is scheduled until it is
-- closed. Therefore a task is reported as open while a worker is
-- processing it. A task is closed after it has been specified in a call to
-- RespondActivityTaskCompleted, RespondActivityTaskCanceled,
-- RespondActivityTaskFailed, or the task has
-- <https://docs.aws.amazon.com/amazonswf/latest/developerguide/swf-dg-basic.html#swf-dev-timeout-types timed out>.
--
-- __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.RespondActivityTaskCompleted
  ( -- * Creating a Request
    RespondActivityTaskCompleted (..),
    newRespondActivityTaskCompleted,

    -- * Request Lenses
    respondActivityTaskCompleted_result,
    respondActivityTaskCompleted_taskToken,

    -- * Destructuring the Response
    RespondActivityTaskCompletedResponse (..),
    newRespondActivityTaskCompletedResponse,
  )
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:/ 'newRespondActivityTaskCompleted' smart constructor.
data RespondActivityTaskCompleted = RespondActivityTaskCompleted'
  { -- | The result of the activity task. It is a free form string that is
    -- implementation specific.
    RespondActivityTaskCompleted -> Maybe Text
result :: Prelude.Maybe Prelude.Text,
    -- | The @taskToken@ of the ActivityTask.
    --
    -- @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.
    RespondActivityTaskCompleted -> Text
taskToken :: Prelude.Text
  }
  deriving (RespondActivityTaskCompleted
-> RespondActivityTaskCompleted -> Bool
(RespondActivityTaskCompleted
 -> RespondActivityTaskCompleted -> Bool)
-> (RespondActivityTaskCompleted
    -> RespondActivityTaskCompleted -> Bool)
-> Eq RespondActivityTaskCompleted
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RespondActivityTaskCompleted
-> RespondActivityTaskCompleted -> Bool
$c/= :: RespondActivityTaskCompleted
-> RespondActivityTaskCompleted -> Bool
== :: RespondActivityTaskCompleted
-> RespondActivityTaskCompleted -> Bool
$c== :: RespondActivityTaskCompleted
-> RespondActivityTaskCompleted -> Bool
Prelude.Eq, ReadPrec [RespondActivityTaskCompleted]
ReadPrec RespondActivityTaskCompleted
Int -> ReadS RespondActivityTaskCompleted
ReadS [RespondActivityTaskCompleted]
(Int -> ReadS RespondActivityTaskCompleted)
-> ReadS [RespondActivityTaskCompleted]
-> ReadPrec RespondActivityTaskCompleted
-> ReadPrec [RespondActivityTaskCompleted]
-> Read RespondActivityTaskCompleted
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RespondActivityTaskCompleted]
$creadListPrec :: ReadPrec [RespondActivityTaskCompleted]
readPrec :: ReadPrec RespondActivityTaskCompleted
$creadPrec :: ReadPrec RespondActivityTaskCompleted
readList :: ReadS [RespondActivityTaskCompleted]
$creadList :: ReadS [RespondActivityTaskCompleted]
readsPrec :: Int -> ReadS RespondActivityTaskCompleted
$creadsPrec :: Int -> ReadS RespondActivityTaskCompleted
Prelude.Read, Int -> RespondActivityTaskCompleted -> ShowS
[RespondActivityTaskCompleted] -> ShowS
RespondActivityTaskCompleted -> String
(Int -> RespondActivityTaskCompleted -> ShowS)
-> (RespondActivityTaskCompleted -> String)
-> ([RespondActivityTaskCompleted] -> ShowS)
-> Show RespondActivityTaskCompleted
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RespondActivityTaskCompleted] -> ShowS
$cshowList :: [RespondActivityTaskCompleted] -> ShowS
show :: RespondActivityTaskCompleted -> String
$cshow :: RespondActivityTaskCompleted -> String
showsPrec :: Int -> RespondActivityTaskCompleted -> ShowS
$cshowsPrec :: Int -> RespondActivityTaskCompleted -> ShowS
Prelude.Show, (forall x.
 RespondActivityTaskCompleted -> Rep RespondActivityTaskCompleted x)
-> (forall x.
    Rep RespondActivityTaskCompleted x -> RespondActivityTaskCompleted)
-> Generic RespondActivityTaskCompleted
forall x.
Rep RespondActivityTaskCompleted x -> RespondActivityTaskCompleted
forall x.
RespondActivityTaskCompleted -> Rep RespondActivityTaskCompleted x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RespondActivityTaskCompleted x -> RespondActivityTaskCompleted
$cfrom :: forall x.
RespondActivityTaskCompleted -> Rep RespondActivityTaskCompleted x
Prelude.Generic)

-- |
-- Create a value of 'RespondActivityTaskCompleted' 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:
--
-- 'result', 'respondActivityTaskCompleted_result' - The result of the activity task. It is a free form string that is
-- implementation specific.
--
-- 'taskToken', 'respondActivityTaskCompleted_taskToken' - The @taskToken@ of the ActivityTask.
--
-- @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.
newRespondActivityTaskCompleted ::
  -- | 'taskToken'
  Prelude.Text ->
  RespondActivityTaskCompleted
newRespondActivityTaskCompleted :: Text -> RespondActivityTaskCompleted
newRespondActivityTaskCompleted Text
pTaskToken_ =
  RespondActivityTaskCompleted' :: Maybe Text -> Text -> RespondActivityTaskCompleted
RespondActivityTaskCompleted'
    { $sel:result:RespondActivityTaskCompleted' :: Maybe Text
result =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:taskToken:RespondActivityTaskCompleted' :: Text
taskToken = Text
pTaskToken_
    }

-- | The result of the activity task. It is a free form string that is
-- implementation specific.
respondActivityTaskCompleted_result :: Lens.Lens' RespondActivityTaskCompleted (Prelude.Maybe Prelude.Text)
respondActivityTaskCompleted_result :: (Maybe Text -> f (Maybe Text))
-> RespondActivityTaskCompleted -> f RespondActivityTaskCompleted
respondActivityTaskCompleted_result = (RespondActivityTaskCompleted -> Maybe Text)
-> (RespondActivityTaskCompleted
    -> Maybe Text -> RespondActivityTaskCompleted)
-> Lens
     RespondActivityTaskCompleted
     RespondActivityTaskCompleted
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RespondActivityTaskCompleted' {Maybe Text
result :: Maybe Text
$sel:result:RespondActivityTaskCompleted' :: RespondActivityTaskCompleted -> Maybe Text
result} -> Maybe Text
result) (\s :: RespondActivityTaskCompleted
s@RespondActivityTaskCompleted' {} Maybe Text
a -> RespondActivityTaskCompleted
s {$sel:result:RespondActivityTaskCompleted' :: Maybe Text
result = Maybe Text
a} :: RespondActivityTaskCompleted)

-- | The @taskToken@ of the ActivityTask.
--
-- @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.
respondActivityTaskCompleted_taskToken :: Lens.Lens' RespondActivityTaskCompleted Prelude.Text
respondActivityTaskCompleted_taskToken :: (Text -> f Text)
-> RespondActivityTaskCompleted -> f RespondActivityTaskCompleted
respondActivityTaskCompleted_taskToken = (RespondActivityTaskCompleted -> Text)
-> (RespondActivityTaskCompleted
    -> Text -> RespondActivityTaskCompleted)
-> Lens
     RespondActivityTaskCompleted RespondActivityTaskCompleted Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RespondActivityTaskCompleted' {Text
taskToken :: Text
$sel:taskToken:RespondActivityTaskCompleted' :: RespondActivityTaskCompleted -> Text
taskToken} -> Text
taskToken) (\s :: RespondActivityTaskCompleted
s@RespondActivityTaskCompleted' {} Text
a -> RespondActivityTaskCompleted
s {$sel:taskToken:RespondActivityTaskCompleted' :: Text
taskToken = Text
a} :: RespondActivityTaskCompleted)

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

instance
  Prelude.Hashable
    RespondActivityTaskCompleted

instance Prelude.NFData RespondActivityTaskCompleted

instance Core.ToHeaders RespondActivityTaskCompleted where
  toHeaders :: RespondActivityTaskCompleted -> [Header]
toHeaders =
    [Header] -> RespondActivityTaskCompleted -> [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.RespondActivityTaskCompleted" ::
                          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 RespondActivityTaskCompleted where
  toJSON :: RespondActivityTaskCompleted -> Value
toJSON RespondActivityTaskCompleted' {Maybe Text
Text
taskToken :: Text
result :: Maybe Text
$sel:taskToken:RespondActivityTaskCompleted' :: RespondActivityTaskCompleted -> Text
$sel:result:RespondActivityTaskCompleted' :: RespondActivityTaskCompleted -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"result" 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
result,
            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 RespondActivityTaskCompleted where
  toPath :: RespondActivityTaskCompleted -> ByteString
toPath = ByteString -> RespondActivityTaskCompleted -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

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

instance
  Prelude.NFData
    RespondActivityTaskCompletedResponse