{-# 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-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)
--
-- Cancels a running query. To be canceled, a query must be running.
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.Lens as Lens
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
(CancelStatement -> CancelStatement -> Bool)
-> (CancelStatement -> CancelStatement -> Bool)
-> Eq CancelStatement
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]
(Int -> ReadS CancelStatement)
-> ReadS [CancelStatement]
-> ReadPrec CancelStatement
-> ReadPrec [CancelStatement]
-> Read 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
(Int -> CancelStatement -> ShowS)
-> (CancelStatement -> String)
-> ([CancelStatement] -> ShowS)
-> Show CancelStatement
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. CancelStatement -> Rep CancelStatement x)
-> (forall x. Rep CancelStatement x -> CancelStatement)
-> Generic CancelStatement
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' :: Text -> CancelStatement
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 :: (Text -> f Text) -> CancelStatement -> f CancelStatement
cancelStatement_id = (CancelStatement -> Text)
-> (CancelStatement -> Text -> CancelStatement)
-> Lens CancelStatement CancelStatement Text Text
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 :: CancelStatement -> Request CancelStatement
request = Service -> CancelStatement -> Request CancelStatement
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CancelStatement
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CancelStatement)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CancelStatement))
-> Logger
-> Service
-> Proxy CancelStatement
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CancelStatement)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Bool -> Int -> CancelStatementResponse
CancelStatementResponse'
            (Maybe Bool -> Int -> CancelStatementResponse)
-> Either String (Maybe Bool)
-> Either String (Int -> CancelStatementResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Status")
            Either String (Int -> CancelStatementResponse)
-> Either String Int -> Either String CancelStatementResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CancelStatement

instance Prelude.NFData CancelStatement

instance Core.ToHeaders CancelStatement where
  toHeaders :: CancelStatement -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CancelStatement -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"RedshiftData.CancelStatement" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON CancelStatement where
  toJSON :: CancelStatement -> Value
toJSON CancelStatement' {Text
id :: Text
$sel:id:CancelStatement' :: CancelStatement -> Text
..} =
    [Pair] -> Value
Core.object
      ([Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
id)])

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

instance Core.ToQuery CancelStatement where
  toQuery :: CancelStatement -> QueryString
toQuery = QueryString -> CancelStatement -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(CancelStatementResponse -> CancelStatementResponse -> Bool)
-> (CancelStatementResponse -> CancelStatementResponse -> Bool)
-> Eq CancelStatementResponse
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]
(Int -> ReadS CancelStatementResponse)
-> ReadS [CancelStatementResponse]
-> ReadPrec CancelStatementResponse
-> ReadPrec [CancelStatementResponse]
-> Read 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
(Int -> CancelStatementResponse -> ShowS)
-> (CancelStatementResponse -> String)
-> ([CancelStatementResponse] -> ShowS)
-> Show CancelStatementResponse
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.
 CancelStatementResponse -> Rep CancelStatementResponse x)
-> (forall x.
    Rep CancelStatementResponse x -> CancelStatementResponse)
-> Generic CancelStatementResponse
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' :: Maybe Bool -> Int -> CancelStatementResponse
CancelStatementResponse'
    { $sel:status:CancelStatementResponse' :: Maybe Bool
status = Maybe Bool
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 :: (Maybe Bool -> f (Maybe Bool))
-> CancelStatementResponse -> f CancelStatementResponse
cancelStatementResponse_status = (CancelStatementResponse -> Maybe Bool)
-> (CancelStatementResponse
    -> Maybe Bool -> CancelStatementResponse)
-> Lens
     CancelStatementResponse
     CancelStatementResponse
     (Maybe Bool)
     (Maybe Bool)
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 :: (Int -> f Int)
-> CancelStatementResponse -> f CancelStatementResponse
cancelStatementResponse_httpStatus = (CancelStatementResponse -> Int)
-> (CancelStatementResponse -> Int -> CancelStatementResponse)
-> Lens CancelStatementResponse CancelStatementResponse Int Int
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