{-# 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.CloudWatchLogs.StopQuery
-- 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)
--
-- Stops a CloudWatch Logs Insights query that is in progress. If the query
-- has already ended, the operation returns an error indicating that the
-- specified query is not running.
module Amazonka.CloudWatchLogs.StopQuery
  ( -- * Creating a Request
    StopQuery (..),
    newStopQuery,

    -- * Request Lenses
    stopQuery_queryId,

    -- * Destructuring the Response
    StopQueryResponse (..),
    newStopQueryResponse,

    -- * Response Lenses
    stopQueryResponse_success,
    stopQueryResponse_httpStatus,
  )
where

import Amazonka.CloudWatchLogs.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newStopQuery' smart constructor.
data StopQuery = StopQuery'
  { -- | The ID number of the query to stop. To find this ID number, use
    -- @DescribeQueries@.
    StopQuery -> Text
queryId :: Prelude.Text
  }
  deriving (StopQuery -> StopQuery -> Bool
(StopQuery -> StopQuery -> Bool)
-> (StopQuery -> StopQuery -> Bool) -> Eq StopQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopQuery -> StopQuery -> Bool
$c/= :: StopQuery -> StopQuery -> Bool
== :: StopQuery -> StopQuery -> Bool
$c== :: StopQuery -> StopQuery -> Bool
Prelude.Eq, ReadPrec [StopQuery]
ReadPrec StopQuery
Int -> ReadS StopQuery
ReadS [StopQuery]
(Int -> ReadS StopQuery)
-> ReadS [StopQuery]
-> ReadPrec StopQuery
-> ReadPrec [StopQuery]
-> Read StopQuery
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopQuery]
$creadListPrec :: ReadPrec [StopQuery]
readPrec :: ReadPrec StopQuery
$creadPrec :: ReadPrec StopQuery
readList :: ReadS [StopQuery]
$creadList :: ReadS [StopQuery]
readsPrec :: Int -> ReadS StopQuery
$creadsPrec :: Int -> ReadS StopQuery
Prelude.Read, Int -> StopQuery -> ShowS
[StopQuery] -> ShowS
StopQuery -> String
(Int -> StopQuery -> ShowS)
-> (StopQuery -> String)
-> ([StopQuery] -> ShowS)
-> Show StopQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopQuery] -> ShowS
$cshowList :: [StopQuery] -> ShowS
show :: StopQuery -> String
$cshow :: StopQuery -> String
showsPrec :: Int -> StopQuery -> ShowS
$cshowsPrec :: Int -> StopQuery -> ShowS
Prelude.Show, (forall x. StopQuery -> Rep StopQuery x)
-> (forall x. Rep StopQuery x -> StopQuery) -> Generic StopQuery
forall x. Rep StopQuery x -> StopQuery
forall x. StopQuery -> Rep StopQuery x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopQuery x -> StopQuery
$cfrom :: forall x. StopQuery -> Rep StopQuery x
Prelude.Generic)

-- |
-- Create a value of 'StopQuery' 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', 'stopQuery_queryId' - The ID number of the query to stop. To find this ID number, use
-- @DescribeQueries@.
newStopQuery ::
  -- | 'queryId'
  Prelude.Text ->
  StopQuery
newStopQuery :: Text -> StopQuery
newStopQuery Text
pQueryId_ =
  StopQuery' :: Text -> StopQuery
StopQuery' {$sel:queryId:StopQuery' :: Text
queryId = Text
pQueryId_}

-- | The ID number of the query to stop. To find this ID number, use
-- @DescribeQueries@.
stopQuery_queryId :: Lens.Lens' StopQuery Prelude.Text
stopQuery_queryId :: (Text -> f Text) -> StopQuery -> f StopQuery
stopQuery_queryId = (StopQuery -> Text)
-> (StopQuery -> Text -> StopQuery)
-> Lens StopQuery StopQuery Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopQuery' {Text
queryId :: Text
$sel:queryId:StopQuery' :: StopQuery -> Text
queryId} -> Text
queryId) (\s :: StopQuery
s@StopQuery' {} Text
a -> StopQuery
s {$sel:queryId:StopQuery' :: Text
queryId = Text
a} :: StopQuery)

instance Core.AWSRequest StopQuery where
  type AWSResponse StopQuery = StopQueryResponse
  request :: StopQuery -> Request StopQuery
request = Service -> StopQuery -> Request StopQuery
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StopQuery
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopQuery)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StopQuery))
-> Logger
-> Service
-> Proxy StopQuery
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopQuery)))
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 -> StopQueryResponse
StopQueryResponse'
            (Maybe Bool -> Int -> StopQueryResponse)
-> Either String (Maybe Bool)
-> Either String (Int -> StopQueryResponse)
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
"success")
            Either String (Int -> StopQueryResponse)
-> Either String Int -> Either String StopQueryResponse
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 StopQuery

instance Prelude.NFData StopQuery

instance Core.ToHeaders StopQuery where
  toHeaders :: StopQuery -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StopQuery -> 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
"Logs_20140328.StopQuery" :: 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 StopQuery where
  toJSON :: StopQuery -> Value
toJSON StopQuery' {Text
queryId :: Text
$sel:queryId:StopQuery' :: StopQuery -> 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
"queryId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
queryId)]
      )

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

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

-- | /See:/ 'newStopQueryResponse' smart constructor.
data StopQueryResponse = StopQueryResponse'
  { -- | This is true if the query was stopped by the @StopQuery@ operation.
    StopQueryResponse -> Maybe Bool
success :: Prelude.Maybe Prelude.Bool,
    -- | The response's http status code.
    StopQueryResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StopQueryResponse -> StopQueryResponse -> Bool
(StopQueryResponse -> StopQueryResponse -> Bool)
-> (StopQueryResponse -> StopQueryResponse -> Bool)
-> Eq StopQueryResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopQueryResponse -> StopQueryResponse -> Bool
$c/= :: StopQueryResponse -> StopQueryResponse -> Bool
== :: StopQueryResponse -> StopQueryResponse -> Bool
$c== :: StopQueryResponse -> StopQueryResponse -> Bool
Prelude.Eq, ReadPrec [StopQueryResponse]
ReadPrec StopQueryResponse
Int -> ReadS StopQueryResponse
ReadS [StopQueryResponse]
(Int -> ReadS StopQueryResponse)
-> ReadS [StopQueryResponse]
-> ReadPrec StopQueryResponse
-> ReadPrec [StopQueryResponse]
-> Read StopQueryResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopQueryResponse]
$creadListPrec :: ReadPrec [StopQueryResponse]
readPrec :: ReadPrec StopQueryResponse
$creadPrec :: ReadPrec StopQueryResponse
readList :: ReadS [StopQueryResponse]
$creadList :: ReadS [StopQueryResponse]
readsPrec :: Int -> ReadS StopQueryResponse
$creadsPrec :: Int -> ReadS StopQueryResponse
Prelude.Read, Int -> StopQueryResponse -> ShowS
[StopQueryResponse] -> ShowS
StopQueryResponse -> String
(Int -> StopQueryResponse -> ShowS)
-> (StopQueryResponse -> String)
-> ([StopQueryResponse] -> ShowS)
-> Show StopQueryResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopQueryResponse] -> ShowS
$cshowList :: [StopQueryResponse] -> ShowS
show :: StopQueryResponse -> String
$cshow :: StopQueryResponse -> String
showsPrec :: Int -> StopQueryResponse -> ShowS
$cshowsPrec :: Int -> StopQueryResponse -> ShowS
Prelude.Show, (forall x. StopQueryResponse -> Rep StopQueryResponse x)
-> (forall x. Rep StopQueryResponse x -> StopQueryResponse)
-> Generic StopQueryResponse
forall x. Rep StopQueryResponse x -> StopQueryResponse
forall x. StopQueryResponse -> Rep StopQueryResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopQueryResponse x -> StopQueryResponse
$cfrom :: forall x. StopQueryResponse -> Rep StopQueryResponse x
Prelude.Generic)

-- |
-- Create a value of 'StopQueryResponse' 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:
--
-- 'success', 'stopQueryResponse_success' - This is true if the query was stopped by the @StopQuery@ operation.
--
-- 'httpStatus', 'stopQueryResponse_httpStatus' - The response's http status code.
newStopQueryResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StopQueryResponse
newStopQueryResponse :: Int -> StopQueryResponse
newStopQueryResponse Int
pHttpStatus_ =
  StopQueryResponse' :: Maybe Bool -> Int -> StopQueryResponse
StopQueryResponse'
    { $sel:success:StopQueryResponse' :: Maybe Bool
success = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StopQueryResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | This is true if the query was stopped by the @StopQuery@ operation.
stopQueryResponse_success :: Lens.Lens' StopQueryResponse (Prelude.Maybe Prelude.Bool)
stopQueryResponse_success :: (Maybe Bool -> f (Maybe Bool))
-> StopQueryResponse -> f StopQueryResponse
stopQueryResponse_success = (StopQueryResponse -> Maybe Bool)
-> (StopQueryResponse -> Maybe Bool -> StopQueryResponse)
-> Lens
     StopQueryResponse StopQueryResponse (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopQueryResponse' {Maybe Bool
success :: Maybe Bool
$sel:success:StopQueryResponse' :: StopQueryResponse -> Maybe Bool
success} -> Maybe Bool
success) (\s :: StopQueryResponse
s@StopQueryResponse' {} Maybe Bool
a -> StopQueryResponse
s {$sel:success:StopQueryResponse' :: Maybe Bool
success = Maybe Bool
a} :: StopQueryResponse)

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

instance Prelude.NFData StopQueryResponse