{-# 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.RedshiftData.CancelStatement
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Cancels a running query. To be canceled, a query must be running.
--
-- For more information about the Amazon Redshift Data API and CLI usage
-- examples, see
-- <https://docs.aws.amazon.com/redshift/latest/mgmt/data-api.html Using the Amazon Redshift Data API>
-- in the /Amazon Redshift Management Guide/.
module Amazonka.RedshiftData.CancelStatement
  ( -- * Creating a Request
    CancelStatement (..),
    newCancelStatement,

    -- * Request Lenses
    cancelStatement_id,

    -- * Destructuring the Response
    CancelStatementResponse (..),
    newCancelStatementResponse,

    -- * Response Lenses
    cancelStatementResponse_status,
    cancelStatementResponse_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 Amazonka.RedshiftData.Types
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCancelStatement' smart constructor.
data CancelStatement = CancelStatement'
  { -- | The identifier of the SQL statement to cancel. This value is a
    -- universally unique identifier (UUID) generated by Amazon Redshift Data
    -- API. This identifier is returned by @BatchExecuteStatment@,
    -- @ExecuteStatment@, and @ListStatements@.
    CancelStatement -> Text
id :: Prelude.Text
  }
  deriving (CancelStatement -> CancelStatement -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelStatement -> CancelStatement -> Bool
$c/= :: CancelStatement -> CancelStatement -> Bool
== :: CancelStatement -> CancelStatement -> Bool
$c== :: CancelStatement -> CancelStatement -> Bool
Prelude.Eq, ReadPrec [CancelStatement]
ReadPrec CancelStatement
Int -> ReadS CancelStatement
ReadS [CancelStatement]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelStatement]
$creadListPrec :: ReadPrec [CancelStatement]
readPrec :: ReadPrec CancelStatement
$creadPrec :: ReadPrec CancelStatement
readList :: ReadS [CancelStatement]
$creadList :: ReadS [CancelStatement]
readsPrec :: Int -> ReadS CancelStatement
$creadsPrec :: Int -> ReadS CancelStatement
Prelude.Read, Int -> CancelStatement -> ShowS
[CancelStatement] -> ShowS
CancelStatement -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelStatement] -> ShowS
$cshowList :: [CancelStatement] -> ShowS
show :: CancelStatement -> String
$cshow :: CancelStatement -> String
showsPrec :: Int -> CancelStatement -> ShowS
$cshowsPrec :: Int -> CancelStatement -> ShowS
Prelude.Show, forall x. Rep CancelStatement x -> CancelStatement
forall x. CancelStatement -> Rep CancelStatement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CancelStatement x -> CancelStatement
$cfrom :: forall x. CancelStatement -> Rep CancelStatement x
Prelude.Generic)

-- |
-- Create a value of 'CancelStatement' 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:
--
-- 'id', 'cancelStatement_id' - The identifier of the SQL statement to cancel. This value is a
-- universally unique identifier (UUID) generated by Amazon Redshift Data
-- API. This identifier is returned by @BatchExecuteStatment@,
-- @ExecuteStatment@, and @ListStatements@.
newCancelStatement ::
  -- | 'id'
  Prelude.Text ->
  CancelStatement
newCancelStatement :: Text -> CancelStatement
newCancelStatement Text
pId_ = CancelStatement' {$sel:id:CancelStatement' :: Text
id = Text
pId_}

-- | The identifier of the SQL statement to cancel. This value is a
-- universally unique identifier (UUID) generated by Amazon Redshift Data
-- API. This identifier is returned by @BatchExecuteStatment@,
-- @ExecuteStatment@, and @ListStatements@.
cancelStatement_id :: Lens.Lens' CancelStatement Prelude.Text
cancelStatement_id :: Lens' CancelStatement Text
cancelStatement_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelStatement' {Text
id :: Text
$sel:id:CancelStatement' :: CancelStatement -> Text
id} -> Text
id) (\s :: CancelStatement
s@CancelStatement' {} Text
a -> CancelStatement
s {$sel:id:CancelStatement' :: Text
id = Text
a} :: CancelStatement)

instance Core.AWSRequest CancelStatement where
  type
    AWSResponse CancelStatement =
      CancelStatementResponse
  request :: (Service -> Service) -> CancelStatement -> Request CancelStatement
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 CancelStatement
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CancelStatement)))
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 Bool -> Int -> CancelStatementResponse
CancelStatementResponse'
            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
"Status")
            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 CancelStatement where
  hashWithSalt :: Int -> CancelStatement -> Int
hashWithSalt Int
_salt CancelStatement' {Text
id :: Text
$sel:id:CancelStatement' :: CancelStatement -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id

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

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

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

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

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

-- |
-- Create a value of 'CancelStatementResponse' 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:
--
-- 'status', 'cancelStatementResponse_status' - A value that indicates whether the cancel statement succeeded (true).
--
-- 'httpStatus', 'cancelStatementResponse_httpStatus' - The response's http status code.
newCancelStatementResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CancelStatementResponse
newCancelStatementResponse :: Int -> CancelStatementResponse
newCancelStatementResponse Int
pHttpStatus_ =
  CancelStatementResponse'
    { $sel:status:CancelStatementResponse' :: Maybe Bool
status = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CancelStatementResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A value that indicates whether the cancel statement succeeded (true).
cancelStatementResponse_status :: Lens.Lens' CancelStatementResponse (Prelude.Maybe Prelude.Bool)
cancelStatementResponse_status :: Lens' CancelStatementResponse (Maybe Bool)
cancelStatementResponse_status = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelStatementResponse' {Maybe Bool
status :: Maybe Bool
$sel:status:CancelStatementResponse' :: CancelStatementResponse -> Maybe Bool
status} -> Maybe Bool
status) (\s :: CancelStatementResponse
s@CancelStatementResponse' {} Maybe Bool
a -> CancelStatementResponse
s {$sel:status:CancelStatementResponse' :: Maybe Bool
status = Maybe Bool
a} :: CancelStatementResponse)

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

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