{-# 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.StepFunctions.SendTaskFailure
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Used by activity workers and task states using the
-- <https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html#connect-wait-token callback>
-- pattern to report that the task identified by the @taskToken@ failed.
module Amazonka.StepFunctions.SendTaskFailure
  ( -- * Creating a Request
    SendTaskFailure (..),
    newSendTaskFailure,

    -- * Request Lenses
    sendTaskFailure_cause,
    sendTaskFailure_error,
    sendTaskFailure_taskToken,

    -- * Destructuring the Response
    SendTaskFailureResponse (..),
    newSendTaskFailureResponse,

    -- * Response Lenses
    sendTaskFailureResponse_httpStatus,
  )
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.StepFunctions.Types

-- | /See:/ 'newSendTaskFailure' smart constructor.
data SendTaskFailure = SendTaskFailure'
  { -- | A more detailed explanation of the cause of the failure.
    SendTaskFailure -> Maybe (Sensitive Text)
cause :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | The error code of the failure.
    SendTaskFailure -> Maybe (Sensitive Text)
error :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | The token that represents this task. Task tokens are generated by Step
    -- Functions when tasks are assigned to a worker, or in the
    -- <https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html context object>
    -- when a workflow enters a task state. See
    -- GetActivityTaskOutput$taskToken.
    SendTaskFailure -> Text
taskToken :: Prelude.Text
  }
  deriving (SendTaskFailure -> SendTaskFailure -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SendTaskFailure -> SendTaskFailure -> Bool
$c/= :: SendTaskFailure -> SendTaskFailure -> Bool
== :: SendTaskFailure -> SendTaskFailure -> Bool
$c== :: SendTaskFailure -> SendTaskFailure -> Bool
Prelude.Eq, Int -> SendTaskFailure -> ShowS
[SendTaskFailure] -> ShowS
SendTaskFailure -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SendTaskFailure] -> ShowS
$cshowList :: [SendTaskFailure] -> ShowS
show :: SendTaskFailure -> String
$cshow :: SendTaskFailure -> String
showsPrec :: Int -> SendTaskFailure -> ShowS
$cshowsPrec :: Int -> SendTaskFailure -> ShowS
Prelude.Show, forall x. Rep SendTaskFailure x -> SendTaskFailure
forall x. SendTaskFailure -> Rep SendTaskFailure x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SendTaskFailure x -> SendTaskFailure
$cfrom :: forall x. SendTaskFailure -> Rep SendTaskFailure x
Prelude.Generic)

-- |
-- Create a value of 'SendTaskFailure' 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:
--
-- 'cause', 'sendTaskFailure_cause' - A more detailed explanation of the cause of the failure.
--
-- 'error', 'sendTaskFailure_error' - The error code of the failure.
--
-- 'taskToken', 'sendTaskFailure_taskToken' - The token that represents this task. Task tokens are generated by Step
-- Functions when tasks are assigned to a worker, or in the
-- <https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html context object>
-- when a workflow enters a task state. See
-- GetActivityTaskOutput$taskToken.
newSendTaskFailure ::
  -- | 'taskToken'
  Prelude.Text ->
  SendTaskFailure
newSendTaskFailure :: Text -> SendTaskFailure
newSendTaskFailure Text
pTaskToken_ =
  SendTaskFailure'
    { $sel:cause:SendTaskFailure' :: Maybe (Sensitive Text)
cause = forall a. Maybe a
Prelude.Nothing,
      $sel:error:SendTaskFailure' :: Maybe (Sensitive Text)
error = forall a. Maybe a
Prelude.Nothing,
      $sel:taskToken:SendTaskFailure' :: Text
taskToken = Text
pTaskToken_
    }

-- | A more detailed explanation of the cause of the failure.
sendTaskFailure_cause :: Lens.Lens' SendTaskFailure (Prelude.Maybe Prelude.Text)
sendTaskFailure_cause :: Lens' SendTaskFailure (Maybe Text)
sendTaskFailure_cause = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendTaskFailure' {Maybe (Sensitive Text)
cause :: Maybe (Sensitive Text)
$sel:cause:SendTaskFailure' :: SendTaskFailure -> Maybe (Sensitive Text)
cause} -> Maybe (Sensitive Text)
cause) (\s :: SendTaskFailure
s@SendTaskFailure' {} Maybe (Sensitive Text)
a -> SendTaskFailure
s {$sel:cause:SendTaskFailure' :: Maybe (Sensitive Text)
cause = Maybe (Sensitive Text)
a} :: SendTaskFailure) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | The error code of the failure.
sendTaskFailure_error :: Lens.Lens' SendTaskFailure (Prelude.Maybe Prelude.Text)
sendTaskFailure_error :: Lens' SendTaskFailure (Maybe Text)
sendTaskFailure_error = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendTaskFailure' {Maybe (Sensitive Text)
error :: Maybe (Sensitive Text)
$sel:error:SendTaskFailure' :: SendTaskFailure -> Maybe (Sensitive Text)
error} -> Maybe (Sensitive Text)
error) (\s :: SendTaskFailure
s@SendTaskFailure' {} Maybe (Sensitive Text)
a -> SendTaskFailure
s {$sel:error:SendTaskFailure' :: Maybe (Sensitive Text)
error = Maybe (Sensitive Text)
a} :: SendTaskFailure) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | The token that represents this task. Task tokens are generated by Step
-- Functions when tasks are assigned to a worker, or in the
-- <https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html context object>
-- when a workflow enters a task state. See
-- GetActivityTaskOutput$taskToken.
sendTaskFailure_taskToken :: Lens.Lens' SendTaskFailure Prelude.Text
sendTaskFailure_taskToken :: Lens' SendTaskFailure Text
sendTaskFailure_taskToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendTaskFailure' {Text
taskToken :: Text
$sel:taskToken:SendTaskFailure' :: SendTaskFailure -> Text
taskToken} -> Text
taskToken) (\s :: SendTaskFailure
s@SendTaskFailure' {} Text
a -> SendTaskFailure
s {$sel:taskToken:SendTaskFailure' :: Text
taskToken = Text
a} :: SendTaskFailure)

instance Core.AWSRequest SendTaskFailure where
  type
    AWSResponse SendTaskFailure =
      SendTaskFailureResponse
  request :: (Service -> Service) -> SendTaskFailure -> Request SendTaskFailure
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 SendTaskFailure
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SendTaskFailure)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> SendTaskFailureResponse
SendTaskFailureResponse'
            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))
      )

instance Prelude.Hashable SendTaskFailure where
  hashWithSalt :: Int -> SendTaskFailure -> Int
hashWithSalt Int
_salt SendTaskFailure' {Maybe (Sensitive Text)
Text
taskToken :: Text
error :: Maybe (Sensitive Text)
cause :: Maybe (Sensitive Text)
$sel:taskToken:SendTaskFailure' :: SendTaskFailure -> Text
$sel:error:SendTaskFailure' :: SendTaskFailure -> Maybe (Sensitive Text)
$sel:cause:SendTaskFailure' :: SendTaskFailure -> Maybe (Sensitive Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
cause
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
error
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
taskToken

instance Prelude.NFData SendTaskFailure where
  rnf :: SendTaskFailure -> ()
rnf SendTaskFailure' {Maybe (Sensitive Text)
Text
taskToken :: Text
error :: Maybe (Sensitive Text)
cause :: Maybe (Sensitive Text)
$sel:taskToken:SendTaskFailure' :: SendTaskFailure -> Text
$sel:error:SendTaskFailure' :: SendTaskFailure -> Maybe (Sensitive Text)
$sel:cause:SendTaskFailure' :: SendTaskFailure -> Maybe (Sensitive Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
cause
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
error
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
taskToken

instance Data.ToHeaders SendTaskFailure where
  toHeaders :: SendTaskFailure -> 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
"AWSStepFunctions.SendTaskFailure" ::
                          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 SendTaskFailure where
  toJSON :: SendTaskFailure -> Value
toJSON SendTaskFailure' {Maybe (Sensitive Text)
Text
taskToken :: Text
error :: Maybe (Sensitive Text)
cause :: Maybe (Sensitive Text)
$sel:taskToken:SendTaskFailure' :: SendTaskFailure -> Text
$sel:error:SendTaskFailure' :: SendTaskFailure -> Maybe (Sensitive Text)
$sel:cause:SendTaskFailure' :: SendTaskFailure -> Maybe (Sensitive Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"cause" 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 (Sensitive Text)
cause,
            (Key
"error" 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 (Sensitive Text)
error,
            forall a. a -> Maybe a
Prelude.Just (Key
"taskToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
taskToken)
          ]
      )

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

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

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

-- |
-- Create a value of 'SendTaskFailureResponse' 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', 'sendTaskFailureResponse_httpStatus' - The response's http status code.
newSendTaskFailureResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  SendTaskFailureResponse
newSendTaskFailureResponse :: Int -> SendTaskFailureResponse
newSendTaskFailureResponse Int
pHttpStatus_ =
  SendTaskFailureResponse' {$sel:httpStatus:SendTaskFailureResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData SendTaskFailureResponse where
  rnf :: SendTaskFailureResponse -> ()
rnf SendTaskFailureResponse' {Int
httpStatus :: Int
$sel:httpStatus:SendTaskFailureResponse' :: SendTaskFailureResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus