{-# 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.CloudTrail.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 if the query is not in a terminated state, such as
-- @CANCELLED@, @FAILED@, @TIMED_OUT@, or @FINISHED@. You must specify an
-- ARN value for @EventDataStore@. The ID of the query that you want to
-- cancel is also required. When you run @CancelQuery@, the query status
-- might show as @CANCELLED@ even if the operation is not yet finished.
module Amazonka.CloudTrail.CancelQuery
  ( -- * Creating a Request
    CancelQuery (..),
    newCancelQuery,

    -- * Request Lenses
    cancelQuery_eventDataStore,
    cancelQuery_queryId,

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

    -- * Response Lenses
    cancelQueryResponse_httpStatus,
    cancelQueryResponse_queryId,
    cancelQueryResponse_queryStatus,
  )
where

import Amazonka.CloudTrail.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:/ 'newCancelQuery' smart constructor.
data CancelQuery = CancelQuery'
  { -- | The ARN (or the ID suffix of the ARN) of an event data store on which
    -- the specified query is running.
    CancelQuery -> Maybe Text
eventDataStore :: Prelude.Maybe Prelude.Text,
    -- | The ID of the query that you want to cancel. The @QueryId@ comes from
    -- the response of a @StartQuery@ operation.
    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:
--
-- 'eventDataStore', 'cancelQuery_eventDataStore' - The ARN (or the ID suffix of the ARN) of an event data store on which
-- the specified query is running.
--
-- 'queryId', 'cancelQuery_queryId' - The ID of the query that you want to cancel. The @QueryId@ comes from
-- the response of a @StartQuery@ operation.
newCancelQuery ::
  -- | 'queryId'
  Prelude.Text ->
  CancelQuery
newCancelQuery :: Text -> CancelQuery
newCancelQuery Text
pQueryId_ =
  CancelQuery'
    { $sel:eventDataStore:CancelQuery' :: Maybe Text
eventDataStore = forall a. Maybe a
Prelude.Nothing,
      $sel:queryId:CancelQuery' :: Text
queryId = Text
pQueryId_
    }

-- | The ARN (or the ID suffix of the ARN) of an event data store on which
-- the specified query is running.
cancelQuery_eventDataStore :: Lens.Lens' CancelQuery (Prelude.Maybe Prelude.Text)
cancelQuery_eventDataStore :: Lens' CancelQuery (Maybe Text)
cancelQuery_eventDataStore = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelQuery' {Maybe Text
eventDataStore :: Maybe Text
$sel:eventDataStore:CancelQuery' :: CancelQuery -> Maybe Text
eventDataStore} -> Maybe Text
eventDataStore) (\s :: CancelQuery
s@CancelQuery' {} Maybe Text
a -> CancelQuery
s {$sel:eventDataStore:CancelQuery' :: Maybe Text
eventDataStore = Maybe Text
a} :: CancelQuery)

-- | The ID of the query that you want to cancel. The @QueryId@ comes from
-- the response of a @StartQuery@ operation.
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 ->
          Int -> Text -> QueryStatus -> CancelQueryResponse
CancelQueryResponse'
            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
"QueryId")
            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
"QueryStatus")
      )

instance Prelude.Hashable CancelQuery where
  hashWithSalt :: Int -> CancelQuery -> Int
hashWithSalt Int
_salt CancelQuery' {Maybe Text
Text
queryId :: Text
eventDataStore :: Maybe Text
$sel:queryId:CancelQuery' :: CancelQuery -> Text
$sel:eventDataStore:CancelQuery' :: CancelQuery -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
eventDataStore
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
queryId

instance Prelude.NFData CancelQuery where
  rnf :: CancelQuery -> ()
rnf CancelQuery' {Maybe Text
Text
queryId :: Text
eventDataStore :: Maybe Text
$sel:queryId:CancelQuery' :: CancelQuery -> Text
$sel:eventDataStore:CancelQuery' :: CancelQuery -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
eventDataStore
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.CancelQuery" ::
                          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 CancelQuery where
  toJSON :: CancelQuery -> Value
toJSON CancelQuery' {Maybe Text
Text
queryId :: Text
eventDataStore :: Maybe Text
$sel:queryId:CancelQuery' :: CancelQuery -> Text
$sel:eventDataStore:CancelQuery' :: CancelQuery -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"EventDataStore" 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 Text
eventDataStore,
            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'
  { -- | The response's http status code.
    CancelQueryResponse -> Int
httpStatus :: Prelude.Int,
    -- | The ID of the canceled query.
    CancelQueryResponse -> Text
queryId :: Prelude.Text,
    -- | Shows the status of a query after a @CancelQuery@ request. Typically,
    -- the values shown are either @RUNNING@ or @CANCELLED@.
    CancelQueryResponse -> QueryStatus
queryStatus :: QueryStatus
  }
  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:
--
-- 'httpStatus', 'cancelQueryResponse_httpStatus' - The response's http status code.
--
-- 'queryId', 'cancelQueryResponse_queryId' - The ID of the canceled query.
--
-- 'queryStatus', 'cancelQueryResponse_queryStatus' - Shows the status of a query after a @CancelQuery@ request. Typically,
-- the values shown are either @RUNNING@ or @CANCELLED@.
newCancelQueryResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'queryId'
  Prelude.Text ->
  -- | 'queryStatus'
  QueryStatus ->
  CancelQueryResponse
newCancelQueryResponse :: Int -> Text -> QueryStatus -> CancelQueryResponse
newCancelQueryResponse
  Int
pHttpStatus_
  Text
pQueryId_
  QueryStatus
pQueryStatus_ =
    CancelQueryResponse'
      { $sel:httpStatus:CancelQueryResponse' :: Int
httpStatus = Int
pHttpStatus_,
        $sel:queryId:CancelQueryResponse' :: Text
queryId = Text
pQueryId_,
        $sel:queryStatus:CancelQueryResponse' :: QueryStatus
queryStatus = QueryStatus
pQueryStatus_
      }

-- | 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)

-- | The ID of the canceled query.
cancelQueryResponse_queryId :: Lens.Lens' CancelQueryResponse Prelude.Text
cancelQueryResponse_queryId :: Lens' CancelQueryResponse Text
cancelQueryResponse_queryId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelQueryResponse' {Text
queryId :: Text
$sel:queryId:CancelQueryResponse' :: CancelQueryResponse -> Text
queryId} -> Text
queryId) (\s :: CancelQueryResponse
s@CancelQueryResponse' {} Text
a -> CancelQueryResponse
s {$sel:queryId:CancelQueryResponse' :: Text
queryId = Text
a} :: CancelQueryResponse)

-- | Shows the status of a query after a @CancelQuery@ request. Typically,
-- the values shown are either @RUNNING@ or @CANCELLED@.
cancelQueryResponse_queryStatus :: Lens.Lens' CancelQueryResponse QueryStatus
cancelQueryResponse_queryStatus :: Lens' CancelQueryResponse QueryStatus
cancelQueryResponse_queryStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelQueryResponse' {QueryStatus
queryStatus :: QueryStatus
$sel:queryStatus:CancelQueryResponse' :: CancelQueryResponse -> QueryStatus
queryStatus} -> QueryStatus
queryStatus) (\s :: CancelQueryResponse
s@CancelQueryResponse' {} QueryStatus
a -> CancelQueryResponse
s {$sel:queryStatus:CancelQueryResponse' :: QueryStatus
queryStatus = QueryStatus
a} :: CancelQueryResponse)

instance Prelude.NFData CancelQueryResponse where
  rnf :: CancelQueryResponse -> ()
rnf CancelQueryResponse' {Int
Text
QueryStatus
queryStatus :: QueryStatus
queryId :: Text
httpStatus :: Int
$sel:queryStatus:CancelQueryResponse' :: CancelQueryResponse -> QueryStatus
$sel:queryId:CancelQueryResponse' :: CancelQueryResponse -> Text
$sel:httpStatus:CancelQueryResponse' :: CancelQueryResponse -> 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 Text
queryId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf QueryStatus
queryStatus