{-# 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.DeleteQueryDefinition
-- 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)
--
-- Deletes a saved CloudWatch Logs Insights query definition. A query
-- definition contains details about a saved CloudWatch Logs Insights
-- query.
--
-- Each @DeleteQueryDefinition@ operation can delete one query definition.
--
-- You must have the @logs:DeleteQueryDefinition@ permission to be able to
-- perform this operation.
module Amazonka.CloudWatchLogs.DeleteQueryDefinition
  ( -- * Creating a Request
    DeleteQueryDefinition (..),
    newDeleteQueryDefinition,

    -- * Request Lenses
    deleteQueryDefinition_queryDefinitionId,

    -- * Destructuring the Response
    DeleteQueryDefinitionResponse (..),
    newDeleteQueryDefinitionResponse,

    -- * Response Lenses
    deleteQueryDefinitionResponse_success,
    deleteQueryDefinitionResponse_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:/ 'newDeleteQueryDefinition' smart constructor.
data DeleteQueryDefinition = DeleteQueryDefinition'
  { -- | The ID of the query definition that you want to delete. You can use
    -- <https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeQueryDefinitions.html DescribeQueryDefinitions>
    -- to retrieve the IDs of your saved query definitions.
    DeleteQueryDefinition -> Text
queryDefinitionId :: Prelude.Text
  }
  deriving (DeleteQueryDefinition -> DeleteQueryDefinition -> Bool
(DeleteQueryDefinition -> DeleteQueryDefinition -> Bool)
-> (DeleteQueryDefinition -> DeleteQueryDefinition -> Bool)
-> Eq DeleteQueryDefinition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteQueryDefinition -> DeleteQueryDefinition -> Bool
$c/= :: DeleteQueryDefinition -> DeleteQueryDefinition -> Bool
== :: DeleteQueryDefinition -> DeleteQueryDefinition -> Bool
$c== :: DeleteQueryDefinition -> DeleteQueryDefinition -> Bool
Prelude.Eq, ReadPrec [DeleteQueryDefinition]
ReadPrec DeleteQueryDefinition
Int -> ReadS DeleteQueryDefinition
ReadS [DeleteQueryDefinition]
(Int -> ReadS DeleteQueryDefinition)
-> ReadS [DeleteQueryDefinition]
-> ReadPrec DeleteQueryDefinition
-> ReadPrec [DeleteQueryDefinition]
-> Read DeleteQueryDefinition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteQueryDefinition]
$creadListPrec :: ReadPrec [DeleteQueryDefinition]
readPrec :: ReadPrec DeleteQueryDefinition
$creadPrec :: ReadPrec DeleteQueryDefinition
readList :: ReadS [DeleteQueryDefinition]
$creadList :: ReadS [DeleteQueryDefinition]
readsPrec :: Int -> ReadS DeleteQueryDefinition
$creadsPrec :: Int -> ReadS DeleteQueryDefinition
Prelude.Read, Int -> DeleteQueryDefinition -> ShowS
[DeleteQueryDefinition] -> ShowS
DeleteQueryDefinition -> String
(Int -> DeleteQueryDefinition -> ShowS)
-> (DeleteQueryDefinition -> String)
-> ([DeleteQueryDefinition] -> ShowS)
-> Show DeleteQueryDefinition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteQueryDefinition] -> ShowS
$cshowList :: [DeleteQueryDefinition] -> ShowS
show :: DeleteQueryDefinition -> String
$cshow :: DeleteQueryDefinition -> String
showsPrec :: Int -> DeleteQueryDefinition -> ShowS
$cshowsPrec :: Int -> DeleteQueryDefinition -> ShowS
Prelude.Show, (forall x. DeleteQueryDefinition -> Rep DeleteQueryDefinition x)
-> (forall x. Rep DeleteQueryDefinition x -> DeleteQueryDefinition)
-> Generic DeleteQueryDefinition
forall x. Rep DeleteQueryDefinition x -> DeleteQueryDefinition
forall x. DeleteQueryDefinition -> Rep DeleteQueryDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteQueryDefinition x -> DeleteQueryDefinition
$cfrom :: forall x. DeleteQueryDefinition -> Rep DeleteQueryDefinition x
Prelude.Generic)

-- |
-- Create a value of 'DeleteQueryDefinition' 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:
--
-- 'queryDefinitionId', 'deleteQueryDefinition_queryDefinitionId' - The ID of the query definition that you want to delete. You can use
-- <https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeQueryDefinitions.html DescribeQueryDefinitions>
-- to retrieve the IDs of your saved query definitions.
newDeleteQueryDefinition ::
  -- | 'queryDefinitionId'
  Prelude.Text ->
  DeleteQueryDefinition
newDeleteQueryDefinition :: Text -> DeleteQueryDefinition
newDeleteQueryDefinition Text
pQueryDefinitionId_ =
  DeleteQueryDefinition' :: Text -> DeleteQueryDefinition
DeleteQueryDefinition'
    { $sel:queryDefinitionId:DeleteQueryDefinition' :: Text
queryDefinitionId =
        Text
pQueryDefinitionId_
    }

-- | The ID of the query definition that you want to delete. You can use
-- <https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeQueryDefinitions.html DescribeQueryDefinitions>
-- to retrieve the IDs of your saved query definitions.
deleteQueryDefinition_queryDefinitionId :: Lens.Lens' DeleteQueryDefinition Prelude.Text
deleteQueryDefinition_queryDefinitionId :: (Text -> f Text)
-> DeleteQueryDefinition -> f DeleteQueryDefinition
deleteQueryDefinition_queryDefinitionId = (DeleteQueryDefinition -> Text)
-> (DeleteQueryDefinition -> Text -> DeleteQueryDefinition)
-> Lens DeleteQueryDefinition DeleteQueryDefinition Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteQueryDefinition' {Text
queryDefinitionId :: Text
$sel:queryDefinitionId:DeleteQueryDefinition' :: DeleteQueryDefinition -> Text
queryDefinitionId} -> Text
queryDefinitionId) (\s :: DeleteQueryDefinition
s@DeleteQueryDefinition' {} Text
a -> DeleteQueryDefinition
s {$sel:queryDefinitionId:DeleteQueryDefinition' :: Text
queryDefinitionId = Text
a} :: DeleteQueryDefinition)

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

instance Prelude.NFData DeleteQueryDefinition

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

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

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

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

-- |
-- Create a value of 'DeleteQueryDefinitionResponse' 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', 'deleteQueryDefinitionResponse_success' - A value of TRUE indicates that the operation succeeded. FALSE indicates
-- that the operation failed.
--
-- 'httpStatus', 'deleteQueryDefinitionResponse_httpStatus' - The response's http status code.
newDeleteQueryDefinitionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteQueryDefinitionResponse
newDeleteQueryDefinitionResponse :: Int -> DeleteQueryDefinitionResponse
newDeleteQueryDefinitionResponse Int
pHttpStatus_ =
  DeleteQueryDefinitionResponse' :: Maybe Bool -> Int -> DeleteQueryDefinitionResponse
DeleteQueryDefinitionResponse'
    { $sel:success:DeleteQueryDefinitionResponse' :: Maybe Bool
success =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DeleteQueryDefinitionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A value of TRUE indicates that the operation succeeded. FALSE indicates
-- that the operation failed.
deleteQueryDefinitionResponse_success :: Lens.Lens' DeleteQueryDefinitionResponse (Prelude.Maybe Prelude.Bool)
deleteQueryDefinitionResponse_success :: (Maybe Bool -> f (Maybe Bool))
-> DeleteQueryDefinitionResponse -> f DeleteQueryDefinitionResponse
deleteQueryDefinitionResponse_success = (DeleteQueryDefinitionResponse -> Maybe Bool)
-> (DeleteQueryDefinitionResponse
    -> Maybe Bool -> DeleteQueryDefinitionResponse)
-> Lens
     DeleteQueryDefinitionResponse
     DeleteQueryDefinitionResponse
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteQueryDefinitionResponse' {Maybe Bool
success :: Maybe Bool
$sel:success:DeleteQueryDefinitionResponse' :: DeleteQueryDefinitionResponse -> Maybe Bool
success} -> Maybe Bool
success) (\s :: DeleteQueryDefinitionResponse
s@DeleteQueryDefinitionResponse' {} Maybe Bool
a -> DeleteQueryDefinitionResponse
s {$sel:success:DeleteQueryDefinitionResponse' :: Maybe Bool
success = Maybe Bool
a} :: DeleteQueryDefinitionResponse)

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

instance Prelude.NFData DeleteQueryDefinitionResponse