{-# 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.TimeStreamQuery.CancelQuery
-- 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 query that has been issued. Cancellation is provided only if
-- the query has not completed running before the cancellation request was
-- issued. Because cancellation is an idempotent operation, subsequent
-- cancellation requests will return a @CancellationMessage@, indicating
-- that the query has already been canceled. See
-- <https://docs.aws.amazon.com/timestream/latest/developerguide/code-samples.cancel-query.html code sample>
-- for details.
module Amazonka.TimeStreamQuery.CancelQuery
  ( -- * Creating a Request
    CancelQuery (..),
    newCancelQuery,

    -- * Request Lenses
    cancelQuery_queryId,

    -- * Destructuring the Response
    CancelQueryResponse (..),
    newCancelQueryResponse,

    -- * Response Lenses
    cancelQueryResponse_cancellationMessage,
    cancelQueryResponse_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.TimeStreamQuery.Types

-- | /See:/ 'newCancelQuery' smart constructor.
data CancelQuery = CancelQuery'
  { -- | The ID of the query that needs to be cancelled. @QueryID@ is returned as
    -- part of the query result.
    CancelQuery -> Text
queryId :: Prelude.Text
  }
  deriving (CancelQuery -> CancelQuery -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelQuery -> CancelQuery -> Bool
$c/= :: CancelQuery -> CancelQuery -> Bool
== :: CancelQuery -> CancelQuery -> Bool
$c== :: CancelQuery -> CancelQuery -> Bool
Prelude.Eq, ReadPrec [CancelQuery]
ReadPrec CancelQuery
Int -> ReadS CancelQuery
ReadS [CancelQuery]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelQuery]
$creadListPrec :: ReadPrec [CancelQuery]
readPrec :: ReadPrec CancelQuery
$creadPrec :: ReadPrec CancelQuery
readList :: ReadS [CancelQuery]
$creadList :: ReadS [CancelQuery]
readsPrec :: Int -> ReadS CancelQuery
$creadsPrec :: Int -> ReadS CancelQuery
Prelude.Read, Int -> CancelQuery -> ShowS
[CancelQuery] -> ShowS
CancelQuery -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelQuery] -> ShowS
$cshowList :: [CancelQuery] -> ShowS
show :: CancelQuery -> String
$cshow :: CancelQuery -> String
showsPrec :: Int -> CancelQuery -> ShowS
$cshowsPrec :: Int -> CancelQuery -> ShowS
Prelude.Show, forall x. Rep CancelQuery x -> CancelQuery
forall x. CancelQuery -> Rep CancelQuery x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CancelQuery x -> CancelQuery
$cfrom :: forall x. CancelQuery -> Rep CancelQuery x
Prelude.Generic)

-- |
-- Create a value of 'CancelQuery' 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:
--
-- 'queryId', 'cancelQuery_queryId' - The ID of the query that needs to be cancelled. @QueryID@ is returned as
-- part of the query result.
newCancelQuery ::
  -- | 'queryId'
  Prelude.Text ->
  CancelQuery
newCancelQuery :: Text -> CancelQuery
newCancelQuery Text
pQueryId_ =
  CancelQuery' {$sel:queryId:CancelQuery' :: Text
queryId = Text
pQueryId_}

-- | The ID of the query that needs to be cancelled. @QueryID@ is returned as
-- part of the query result.
cancelQuery_queryId :: Lens.Lens' CancelQuery Prelude.Text
cancelQuery_queryId :: Lens' CancelQuery Text
cancelQuery_queryId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelQuery' {Text
queryId :: Text
$sel:queryId:CancelQuery' :: CancelQuery -> Text
queryId} -> Text
queryId) (\s :: CancelQuery
s@CancelQuery' {} Text
a -> CancelQuery
s {$sel:queryId:CancelQuery' :: Text
queryId = Text
a} :: CancelQuery)

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

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

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

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

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

-- | /See:/ 'newCancelQueryResponse' smart constructor.
data CancelQueryResponse = CancelQueryResponse'
  { -- | A @CancellationMessage@ is returned when a @CancelQuery@ request for the
    -- query specified by @QueryId@ has already been issued.
    CancelQueryResponse -> Maybe Text
cancellationMessage :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CancelQueryResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CancelQueryResponse -> CancelQueryResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelQueryResponse -> CancelQueryResponse -> Bool
$c/= :: CancelQueryResponse -> CancelQueryResponse -> Bool
== :: CancelQueryResponse -> CancelQueryResponse -> Bool
$c== :: CancelQueryResponse -> CancelQueryResponse -> Bool
Prelude.Eq, ReadPrec [CancelQueryResponse]
ReadPrec CancelQueryResponse
Int -> ReadS CancelQueryResponse
ReadS [CancelQueryResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelQueryResponse]
$creadListPrec :: ReadPrec [CancelQueryResponse]
readPrec :: ReadPrec CancelQueryResponse
$creadPrec :: ReadPrec CancelQueryResponse
readList :: ReadS [CancelQueryResponse]
$creadList :: ReadS [CancelQueryResponse]
readsPrec :: Int -> ReadS CancelQueryResponse
$creadsPrec :: Int -> ReadS CancelQueryResponse
Prelude.Read, Int -> CancelQueryResponse -> ShowS
[CancelQueryResponse] -> ShowS
CancelQueryResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelQueryResponse] -> ShowS
$cshowList :: [CancelQueryResponse] -> ShowS
show :: CancelQueryResponse -> String
$cshow :: CancelQueryResponse -> String
showsPrec :: Int -> CancelQueryResponse -> ShowS
$cshowsPrec :: Int -> CancelQueryResponse -> ShowS
Prelude.Show, forall x. Rep CancelQueryResponse x -> CancelQueryResponse
forall x. CancelQueryResponse -> Rep CancelQueryResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CancelQueryResponse x -> CancelQueryResponse
$cfrom :: forall x. CancelQueryResponse -> Rep CancelQueryResponse x
Prelude.Generic)

-- |
-- Create a value of 'CancelQueryResponse' 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:
--
-- 'cancellationMessage', 'cancelQueryResponse_cancellationMessage' - A @CancellationMessage@ is returned when a @CancelQuery@ request for the
-- query specified by @QueryId@ has already been issued.
--
-- 'httpStatus', 'cancelQueryResponse_httpStatus' - The response's http status code.
newCancelQueryResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CancelQueryResponse
newCancelQueryResponse :: Int -> CancelQueryResponse
newCancelQueryResponse Int
pHttpStatus_ =
  CancelQueryResponse'
    { $sel:cancellationMessage:CancelQueryResponse' :: Maybe Text
cancellationMessage =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CancelQueryResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A @CancellationMessage@ is returned when a @CancelQuery@ request for the
-- query specified by @QueryId@ has already been issued.
cancelQueryResponse_cancellationMessage :: Lens.Lens' CancelQueryResponse (Prelude.Maybe Prelude.Text)
cancelQueryResponse_cancellationMessage :: Lens' CancelQueryResponse (Maybe Text)
cancelQueryResponse_cancellationMessage = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelQueryResponse' {Maybe Text
cancellationMessage :: Maybe Text
$sel:cancellationMessage:CancelQueryResponse' :: CancelQueryResponse -> Maybe Text
cancellationMessage} -> Maybe Text
cancellationMessage) (\s :: CancelQueryResponse
s@CancelQueryResponse' {} Maybe Text
a -> CancelQueryResponse
s {$sel:cancellationMessage:CancelQueryResponse' :: Maybe Text
cancellationMessage = Maybe Text
a} :: CancelQueryResponse)

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

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