{-# 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.Athena.StopCalculationExecution
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Requests the cancellation of a calculation. A @StopCalculationExecution@
-- call on a calculation that is already in a terminal state (for example,
-- @STOPPED@, @FAILED@, or @COMPLETED@) succeeds but has no effect.
--
-- Cancelling a calculation is done on a best effort basis. If a
-- calculation cannot be cancelled, you can be charged for its completion.
-- If you are concerned about being charged for a calculation that cannot
-- be cancelled, consider terminating the session in which the calculation
-- is running.
module Amazonka.Athena.StopCalculationExecution
  ( -- * Creating a Request
    StopCalculationExecution (..),
    newStopCalculationExecution,

    -- * Request Lenses
    stopCalculationExecution_calculationExecutionId,

    -- * Destructuring the Response
    StopCalculationExecutionResponse (..),
    newStopCalculationExecutionResponse,

    -- * Response Lenses
    stopCalculationExecutionResponse_state,
    stopCalculationExecutionResponse_httpStatus,
  )
where

import Amazonka.Athena.Types
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

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

-- |
-- Create a value of 'StopCalculationExecution' 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:
--
-- 'calculationExecutionId', 'stopCalculationExecution_calculationExecutionId' - The calculation execution UUID.
newStopCalculationExecution ::
  -- | 'calculationExecutionId'
  Prelude.Text ->
  StopCalculationExecution
newStopCalculationExecution :: Text -> StopCalculationExecution
newStopCalculationExecution Text
pCalculationExecutionId_ =
  StopCalculationExecution'
    { $sel:calculationExecutionId:StopCalculationExecution' :: Text
calculationExecutionId =
        Text
pCalculationExecutionId_
    }

-- | The calculation execution UUID.
stopCalculationExecution_calculationExecutionId :: Lens.Lens' StopCalculationExecution Prelude.Text
stopCalculationExecution_calculationExecutionId :: Lens' StopCalculationExecution Text
stopCalculationExecution_calculationExecutionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopCalculationExecution' {Text
calculationExecutionId :: Text
$sel:calculationExecutionId:StopCalculationExecution' :: StopCalculationExecution -> Text
calculationExecutionId} -> Text
calculationExecutionId) (\s :: StopCalculationExecution
s@StopCalculationExecution' {} Text
a -> StopCalculationExecution
s {$sel:calculationExecutionId:StopCalculationExecution' :: Text
calculationExecutionId = Text
a} :: StopCalculationExecution)

instance Core.AWSRequest StopCalculationExecution where
  type
    AWSResponse StopCalculationExecution =
      StopCalculationExecutionResponse
  request :: (Service -> Service)
-> StopCalculationExecution -> Request StopCalculationExecution
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 StopCalculationExecution
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StopCalculationExecution)))
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 ->
          Maybe CalculationExecutionState
-> Int -> StopCalculationExecutionResponse
StopCalculationExecutionResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"State")
            forall (f :: * -> *) a b. Applicative f => 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 StopCalculationExecution where
  hashWithSalt :: Int -> StopCalculationExecution -> Int
hashWithSalt Int
_salt StopCalculationExecution' {Text
calculationExecutionId :: Text
$sel:calculationExecutionId:StopCalculationExecution' :: StopCalculationExecution -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
calculationExecutionId

instance Prelude.NFData StopCalculationExecution where
  rnf :: StopCalculationExecution -> ()
rnf StopCalculationExecution' {Text
calculationExecutionId :: Text
$sel:calculationExecutionId:StopCalculationExecution' :: StopCalculationExecution -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
calculationExecutionId

instance Data.ToHeaders StopCalculationExecution where
  toHeaders :: StopCalculationExecution -> 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
"AmazonAthena.StopCalculationExecution" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON StopCalculationExecution where
  toJSON :: StopCalculationExecution -> Value
toJSON StopCalculationExecution' {Text
calculationExecutionId :: Text
$sel:calculationExecutionId:StopCalculationExecution' :: StopCalculationExecution -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              ( Key
"CalculationExecutionId"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
calculationExecutionId
              )
          ]
      )

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

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

-- | /See:/ 'newStopCalculationExecutionResponse' smart constructor.
data StopCalculationExecutionResponse = StopCalculationExecutionResponse'
  { -- | @CREATING@ - The calculation is in the process of being created.
    --
    -- @CREATED@ - The calculation has been created and is ready to run.
    --
    -- @QUEUED@ - The calculation has been queued for processing.
    --
    -- @RUNNING@ - The calculation is running.
    --
    -- @CANCELING@ - A request to cancel the calculation has been received and
    -- the system is working to stop it.
    --
    -- @CANCELED@ - The calculation is no longer running as the result of a
    -- cancel request.
    --
    -- @COMPLETED@ - The calculation has completed without error.
    --
    -- @FAILED@ - The calculation failed and is no longer running.
    StopCalculationExecutionResponse -> Maybe CalculationExecutionState
state :: Prelude.Maybe CalculationExecutionState,
    -- | The response's http status code.
    StopCalculationExecutionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StopCalculationExecutionResponse
-> StopCalculationExecutionResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopCalculationExecutionResponse
-> StopCalculationExecutionResponse -> Bool
$c/= :: StopCalculationExecutionResponse
-> StopCalculationExecutionResponse -> Bool
== :: StopCalculationExecutionResponse
-> StopCalculationExecutionResponse -> Bool
$c== :: StopCalculationExecutionResponse
-> StopCalculationExecutionResponse -> Bool
Prelude.Eq, ReadPrec [StopCalculationExecutionResponse]
ReadPrec StopCalculationExecutionResponse
Int -> ReadS StopCalculationExecutionResponse
ReadS [StopCalculationExecutionResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopCalculationExecutionResponse]
$creadListPrec :: ReadPrec [StopCalculationExecutionResponse]
readPrec :: ReadPrec StopCalculationExecutionResponse
$creadPrec :: ReadPrec StopCalculationExecutionResponse
readList :: ReadS [StopCalculationExecutionResponse]
$creadList :: ReadS [StopCalculationExecutionResponse]
readsPrec :: Int -> ReadS StopCalculationExecutionResponse
$creadsPrec :: Int -> ReadS StopCalculationExecutionResponse
Prelude.Read, Int -> StopCalculationExecutionResponse -> ShowS
[StopCalculationExecutionResponse] -> ShowS
StopCalculationExecutionResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopCalculationExecutionResponse] -> ShowS
$cshowList :: [StopCalculationExecutionResponse] -> ShowS
show :: StopCalculationExecutionResponse -> String
$cshow :: StopCalculationExecutionResponse -> String
showsPrec :: Int -> StopCalculationExecutionResponse -> ShowS
$cshowsPrec :: Int -> StopCalculationExecutionResponse -> ShowS
Prelude.Show, forall x.
Rep StopCalculationExecutionResponse x
-> StopCalculationExecutionResponse
forall x.
StopCalculationExecutionResponse
-> Rep StopCalculationExecutionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StopCalculationExecutionResponse x
-> StopCalculationExecutionResponse
$cfrom :: forall x.
StopCalculationExecutionResponse
-> Rep StopCalculationExecutionResponse x
Prelude.Generic)

-- |
-- Create a value of 'StopCalculationExecutionResponse' 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:
--
-- 'state', 'stopCalculationExecutionResponse_state' - @CREATING@ - The calculation is in the process of being created.
--
-- @CREATED@ - The calculation has been created and is ready to run.
--
-- @QUEUED@ - The calculation has been queued for processing.
--
-- @RUNNING@ - The calculation is running.
--
-- @CANCELING@ - A request to cancel the calculation has been received and
-- the system is working to stop it.
--
-- @CANCELED@ - The calculation is no longer running as the result of a
-- cancel request.
--
-- @COMPLETED@ - The calculation has completed without error.
--
-- @FAILED@ - The calculation failed and is no longer running.
--
-- 'httpStatus', 'stopCalculationExecutionResponse_httpStatus' - The response's http status code.
newStopCalculationExecutionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StopCalculationExecutionResponse
newStopCalculationExecutionResponse :: Int -> StopCalculationExecutionResponse
newStopCalculationExecutionResponse Int
pHttpStatus_ =
  StopCalculationExecutionResponse'
    { $sel:state:StopCalculationExecutionResponse' :: Maybe CalculationExecutionState
state =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StopCalculationExecutionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | @CREATING@ - The calculation is in the process of being created.
--
-- @CREATED@ - The calculation has been created and is ready to run.
--
-- @QUEUED@ - The calculation has been queued for processing.
--
-- @RUNNING@ - The calculation is running.
--
-- @CANCELING@ - A request to cancel the calculation has been received and
-- the system is working to stop it.
--
-- @CANCELED@ - The calculation is no longer running as the result of a
-- cancel request.
--
-- @COMPLETED@ - The calculation has completed without error.
--
-- @FAILED@ - The calculation failed and is no longer running.
stopCalculationExecutionResponse_state :: Lens.Lens' StopCalculationExecutionResponse (Prelude.Maybe CalculationExecutionState)
stopCalculationExecutionResponse_state :: Lens'
  StopCalculationExecutionResponse (Maybe CalculationExecutionState)
stopCalculationExecutionResponse_state = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopCalculationExecutionResponse' {Maybe CalculationExecutionState
state :: Maybe CalculationExecutionState
$sel:state:StopCalculationExecutionResponse' :: StopCalculationExecutionResponse -> Maybe CalculationExecutionState
state} -> Maybe CalculationExecutionState
state) (\s :: StopCalculationExecutionResponse
s@StopCalculationExecutionResponse' {} Maybe CalculationExecutionState
a -> StopCalculationExecutionResponse
s {$sel:state:StopCalculationExecutionResponse' :: Maybe CalculationExecutionState
state = Maybe CalculationExecutionState
a} :: StopCalculationExecutionResponse)

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

instance
  Prelude.NFData
    StopCalculationExecutionResponse
  where
  rnf :: StopCalculationExecutionResponse -> ()
rnf StopCalculationExecutionResponse' {Int
Maybe CalculationExecutionState
httpStatus :: Int
state :: Maybe CalculationExecutionState
$sel:httpStatus:StopCalculationExecutionResponse' :: StopCalculationExecutionResponse -> Int
$sel:state:StopCalculationExecutionResponse' :: StopCalculationExecutionResponse -> Maybe CalculationExecutionState
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe CalculationExecutionState
state
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus