{-# 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.StopExecution
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Stops an execution.
--
-- This API action is not supported by @EXPRESS@ state machines.
module Amazonka.StepFunctions.StopExecution
  ( -- * Creating a Request
    StopExecution (..),
    newStopExecution,

    -- * Request Lenses
    stopExecution_cause,
    stopExecution_error,
    stopExecution_executionArn,

    -- * Destructuring the Response
    StopExecutionResponse (..),
    newStopExecutionResponse,

    -- * Response Lenses
    stopExecutionResponse_httpStatus,
    stopExecutionResponse_stopDate,
  )
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:/ 'newStopExecution' smart constructor.
data StopExecution = StopExecution'
  { -- | A more detailed explanation of the cause of the failure.
    StopExecution -> Maybe (Sensitive Text)
cause :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | The error code of the failure.
    StopExecution -> Maybe (Sensitive Text)
error :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | The Amazon Resource Name (ARN) of the execution to stop.
    StopExecution -> Text
executionArn :: Prelude.Text
  }
  deriving (StopExecution -> StopExecution -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopExecution -> StopExecution -> Bool
$c/= :: StopExecution -> StopExecution -> Bool
== :: StopExecution -> StopExecution -> Bool
$c== :: StopExecution -> StopExecution -> Bool
Prelude.Eq, Int -> StopExecution -> ShowS
[StopExecution] -> ShowS
StopExecution -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopExecution] -> ShowS
$cshowList :: [StopExecution] -> ShowS
show :: StopExecution -> String
$cshow :: StopExecution -> String
showsPrec :: Int -> StopExecution -> ShowS
$cshowsPrec :: Int -> StopExecution -> ShowS
Prelude.Show, forall x. Rep StopExecution x -> StopExecution
forall x. StopExecution -> Rep StopExecution x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopExecution x -> StopExecution
$cfrom :: forall x. StopExecution -> Rep StopExecution x
Prelude.Generic)

-- |
-- Create a value of 'StopExecution' 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', 'stopExecution_cause' - A more detailed explanation of the cause of the failure.
--
-- 'error', 'stopExecution_error' - The error code of the failure.
--
-- 'executionArn', 'stopExecution_executionArn' - The Amazon Resource Name (ARN) of the execution to stop.
newStopExecution ::
  -- | 'executionArn'
  Prelude.Text ->
  StopExecution
newStopExecution :: Text -> StopExecution
newStopExecution Text
pExecutionArn_ =
  StopExecution'
    { $sel:cause:StopExecution' :: Maybe (Sensitive Text)
cause = forall a. Maybe a
Prelude.Nothing,
      $sel:error:StopExecution' :: Maybe (Sensitive Text)
error = forall a. Maybe a
Prelude.Nothing,
      $sel:executionArn:StopExecution' :: Text
executionArn = Text
pExecutionArn_
    }

-- | A more detailed explanation of the cause of the failure.
stopExecution_cause :: Lens.Lens' StopExecution (Prelude.Maybe Prelude.Text)
stopExecution_cause :: Lens' StopExecution (Maybe Text)
stopExecution_cause = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopExecution' {Maybe (Sensitive Text)
cause :: Maybe (Sensitive Text)
$sel:cause:StopExecution' :: StopExecution -> Maybe (Sensitive Text)
cause} -> Maybe (Sensitive Text)
cause) (\s :: StopExecution
s@StopExecution' {} Maybe (Sensitive Text)
a -> StopExecution
s {$sel:cause:StopExecution' :: Maybe (Sensitive Text)
cause = Maybe (Sensitive Text)
a} :: StopExecution) 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.
stopExecution_error :: Lens.Lens' StopExecution (Prelude.Maybe Prelude.Text)
stopExecution_error :: Lens' StopExecution (Maybe Text)
stopExecution_error = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopExecution' {Maybe (Sensitive Text)
error :: Maybe (Sensitive Text)
$sel:error:StopExecution' :: StopExecution -> Maybe (Sensitive Text)
error} -> Maybe (Sensitive Text)
error) (\s :: StopExecution
s@StopExecution' {} Maybe (Sensitive Text)
a -> StopExecution
s {$sel:error:StopExecution' :: Maybe (Sensitive Text)
error = Maybe (Sensitive Text)
a} :: StopExecution) 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 Amazon Resource Name (ARN) of the execution to stop.
stopExecution_executionArn :: Lens.Lens' StopExecution Prelude.Text
stopExecution_executionArn :: Lens' StopExecution Text
stopExecution_executionArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopExecution' {Text
executionArn :: Text
$sel:executionArn:StopExecution' :: StopExecution -> Text
executionArn} -> Text
executionArn) (\s :: StopExecution
s@StopExecution' {} Text
a -> StopExecution
s {$sel:executionArn:StopExecution' :: Text
executionArn = Text
a} :: StopExecution)

instance Core.AWSRequest StopExecution where
  type
    AWSResponse StopExecution =
      StopExecutionResponse
  request :: (Service -> Service) -> StopExecution -> Request StopExecution
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 StopExecution
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopExecution)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> POSIX -> StopExecutionResponse
StopExecutionResponse'
            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))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"stopDate")
      )

instance Prelude.Hashable StopExecution where
  hashWithSalt :: Int -> StopExecution -> Int
hashWithSalt Int
_salt StopExecution' {Maybe (Sensitive Text)
Text
executionArn :: Text
error :: Maybe (Sensitive Text)
cause :: Maybe (Sensitive Text)
$sel:executionArn:StopExecution' :: StopExecution -> Text
$sel:error:StopExecution' :: StopExecution -> Maybe (Sensitive Text)
$sel:cause:StopExecution' :: StopExecution -> 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
executionArn

instance Prelude.NFData StopExecution where
  rnf :: StopExecution -> ()
rnf StopExecution' {Maybe (Sensitive Text)
Text
executionArn :: Text
error :: Maybe (Sensitive Text)
cause :: Maybe (Sensitive Text)
$sel:executionArn:StopExecution' :: StopExecution -> Text
$sel:error:StopExecution' :: StopExecution -> Maybe (Sensitive Text)
$sel:cause:StopExecution' :: StopExecution -> 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
executionArn

instance Data.ToHeaders StopExecution where
  toHeaders :: StopExecution -> 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.StopExecution" ::
                          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 StopExecution where
  toJSON :: StopExecution -> Value
toJSON StopExecution' {Maybe (Sensitive Text)
Text
executionArn :: Text
error :: Maybe (Sensitive Text)
cause :: Maybe (Sensitive Text)
$sel:executionArn:StopExecution' :: StopExecution -> Text
$sel:error:StopExecution' :: StopExecution -> Maybe (Sensitive Text)
$sel:cause:StopExecution' :: StopExecution -> 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
"executionArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
executionArn)
          ]
      )

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

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

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

-- |
-- Create a value of 'StopExecutionResponse' 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', 'stopExecutionResponse_httpStatus' - The response's http status code.
--
-- 'stopDate', 'stopExecutionResponse_stopDate' - The date the execution is stopped.
newStopExecutionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'stopDate'
  Prelude.UTCTime ->
  StopExecutionResponse
newStopExecutionResponse :: Int -> UTCTime -> StopExecutionResponse
newStopExecutionResponse Int
pHttpStatus_ UTCTime
pStopDate_ =
  StopExecutionResponse'
    { $sel:httpStatus:StopExecutionResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:stopDate:StopExecutionResponse' :: POSIX
stopDate = forall (a :: Format). Iso' (Time a) UTCTime
Data._Time forall t b. AReview t b -> b -> t
Lens.# UTCTime
pStopDate_
    }

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

-- | The date the execution is stopped.
stopExecutionResponse_stopDate :: Lens.Lens' StopExecutionResponse Prelude.UTCTime
stopExecutionResponse_stopDate :: Lens' StopExecutionResponse UTCTime
stopExecutionResponse_stopDate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopExecutionResponse' {POSIX
stopDate :: POSIX
$sel:stopDate:StopExecutionResponse' :: StopExecutionResponse -> POSIX
stopDate} -> POSIX
stopDate) (\s :: StopExecutionResponse
s@StopExecutionResponse' {} POSIX
a -> StopExecutionResponse
s {$sel:stopDate:StopExecutionResponse' :: POSIX
stopDate = POSIX
a} :: StopExecutionResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

instance Prelude.NFData StopExecutionResponse where
  rnf :: StopExecutionResponse -> ()
rnf StopExecutionResponse' {Int
POSIX
stopDate :: POSIX
httpStatus :: Int
$sel:stopDate:StopExecutionResponse' :: StopExecutionResponse -> POSIX
$sel:httpStatus:StopExecutionResponse' :: StopExecutionResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf POSIX
stopDate