{-# 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.WAFRegional.DeleteRule
-- 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)
--
-- This is __AWS WAF Classic__ documentation. For more information, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html AWS WAF Classic>
-- in the developer guide.
--
-- __For the latest version of AWS WAF__, use the AWS WAFV2 API and see the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html AWS WAF Developer Guide>.
-- With the latest version, AWS WAF has a single set of endpoints for
-- regional and global use.
--
-- Permanently deletes a Rule. You can\'t delete a @Rule@ if it\'s still
-- used in any @WebACL@ objects or if it still includes any predicates,
-- such as @ByteMatchSet@ objects.
--
-- If you just want to remove a @Rule@ from a @WebACL@, use UpdateWebACL.
--
-- To permanently delete a @Rule@ from AWS WAF, perform the following
-- steps:
--
-- 1.  Update the @Rule@ to remove predicates, if any. For more
--     information, see UpdateRule.
--
-- 2.  Use GetChangeToken to get the change token that you provide in the
--     @ChangeToken@ parameter of a @DeleteRule@ request.
--
-- 3.  Submit a @DeleteRule@ request.
module Amazonka.WAFRegional.DeleteRule
  ( -- * Creating a Request
    DeleteRule (..),
    newDeleteRule,

    -- * Request Lenses
    deleteRule_ruleId,
    deleteRule_changeToken,

    -- * Destructuring the Response
    DeleteRuleResponse (..),
    newDeleteRuleResponse,

    -- * Response Lenses
    deleteRuleResponse_changeToken,
    deleteRuleResponse_httpStatus,
  )
where

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
import Amazonka.WAFRegional.Types

-- | /See:/ 'newDeleteRule' smart constructor.
data DeleteRule = DeleteRule'
  { -- | The @RuleId@ of the Rule that you want to delete. @RuleId@ is returned
    -- by CreateRule and by ListRules.
    DeleteRule -> Text
ruleId :: Prelude.Text,
    -- | The value returned by the most recent call to GetChangeToken.
    DeleteRule -> Text
changeToken :: Prelude.Text
  }
  deriving (DeleteRule -> DeleteRule -> Bool
(DeleteRule -> DeleteRule -> Bool)
-> (DeleteRule -> DeleteRule -> Bool) -> Eq DeleteRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteRule -> DeleteRule -> Bool
$c/= :: DeleteRule -> DeleteRule -> Bool
== :: DeleteRule -> DeleteRule -> Bool
$c== :: DeleteRule -> DeleteRule -> Bool
Prelude.Eq, ReadPrec [DeleteRule]
ReadPrec DeleteRule
Int -> ReadS DeleteRule
ReadS [DeleteRule]
(Int -> ReadS DeleteRule)
-> ReadS [DeleteRule]
-> ReadPrec DeleteRule
-> ReadPrec [DeleteRule]
-> Read DeleteRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteRule]
$creadListPrec :: ReadPrec [DeleteRule]
readPrec :: ReadPrec DeleteRule
$creadPrec :: ReadPrec DeleteRule
readList :: ReadS [DeleteRule]
$creadList :: ReadS [DeleteRule]
readsPrec :: Int -> ReadS DeleteRule
$creadsPrec :: Int -> ReadS DeleteRule
Prelude.Read, Int -> DeleteRule -> ShowS
[DeleteRule] -> ShowS
DeleteRule -> String
(Int -> DeleteRule -> ShowS)
-> (DeleteRule -> String)
-> ([DeleteRule] -> ShowS)
-> Show DeleteRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteRule] -> ShowS
$cshowList :: [DeleteRule] -> ShowS
show :: DeleteRule -> String
$cshow :: DeleteRule -> String
showsPrec :: Int -> DeleteRule -> ShowS
$cshowsPrec :: Int -> DeleteRule -> ShowS
Prelude.Show, (forall x. DeleteRule -> Rep DeleteRule x)
-> (forall x. Rep DeleteRule x -> DeleteRule) -> Generic DeleteRule
forall x. Rep DeleteRule x -> DeleteRule
forall x. DeleteRule -> Rep DeleteRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteRule x -> DeleteRule
$cfrom :: forall x. DeleteRule -> Rep DeleteRule x
Prelude.Generic)

-- |
-- Create a value of 'DeleteRule' 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:
--
-- 'ruleId', 'deleteRule_ruleId' - The @RuleId@ of the Rule that you want to delete. @RuleId@ is returned
-- by CreateRule and by ListRules.
--
-- 'changeToken', 'deleteRule_changeToken' - The value returned by the most recent call to GetChangeToken.
newDeleteRule ::
  -- | 'ruleId'
  Prelude.Text ->
  -- | 'changeToken'
  Prelude.Text ->
  DeleteRule
newDeleteRule :: Text -> Text -> DeleteRule
newDeleteRule Text
pRuleId_ Text
pChangeToken_ =
  DeleteRule' :: Text -> Text -> DeleteRule
DeleteRule'
    { $sel:ruleId:DeleteRule' :: Text
ruleId = Text
pRuleId_,
      $sel:changeToken:DeleteRule' :: Text
changeToken = Text
pChangeToken_
    }

-- | The @RuleId@ of the Rule that you want to delete. @RuleId@ is returned
-- by CreateRule and by ListRules.
deleteRule_ruleId :: Lens.Lens' DeleteRule Prelude.Text
deleteRule_ruleId :: (Text -> f Text) -> DeleteRule -> f DeleteRule
deleteRule_ruleId = (DeleteRule -> Text)
-> (DeleteRule -> Text -> DeleteRule)
-> Lens DeleteRule DeleteRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteRule' {Text
ruleId :: Text
$sel:ruleId:DeleteRule' :: DeleteRule -> Text
ruleId} -> Text
ruleId) (\s :: DeleteRule
s@DeleteRule' {} Text
a -> DeleteRule
s {$sel:ruleId:DeleteRule' :: Text
ruleId = Text
a} :: DeleteRule)

-- | The value returned by the most recent call to GetChangeToken.
deleteRule_changeToken :: Lens.Lens' DeleteRule Prelude.Text
deleteRule_changeToken :: (Text -> f Text) -> DeleteRule -> f DeleteRule
deleteRule_changeToken = (DeleteRule -> Text)
-> (DeleteRule -> Text -> DeleteRule)
-> Lens DeleteRule DeleteRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteRule' {Text
changeToken :: Text
$sel:changeToken:DeleteRule' :: DeleteRule -> Text
changeToken} -> Text
changeToken) (\s :: DeleteRule
s@DeleteRule' {} Text
a -> DeleteRule
s {$sel:changeToken:DeleteRule' :: Text
changeToken = Text
a} :: DeleteRule)

instance Core.AWSRequest DeleteRule where
  type AWSResponse DeleteRule = DeleteRuleResponse
  request :: DeleteRule -> Request DeleteRule
request = Service -> DeleteRule -> Request DeleteRule
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteRule
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteRule)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DeleteRule))
-> Logger
-> Service
-> Proxy DeleteRule
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteRule)))
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 Text -> Int -> DeleteRuleResponse
DeleteRuleResponse'
            (Maybe Text -> Int -> DeleteRuleResponse)
-> Either String (Maybe Text)
-> Either String (Int -> DeleteRuleResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"ChangeToken")
            Either String (Int -> DeleteRuleResponse)
-> Either String Int -> Either String DeleteRuleResponse
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 DeleteRule

instance Prelude.NFData DeleteRule

instance Core.ToHeaders DeleteRule where
  toHeaders :: DeleteRule -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DeleteRule -> 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
"AWSWAF_Regional_20161128.DeleteRule" ::
                          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 DeleteRule where
  toJSON :: DeleteRule -> Value
toJSON DeleteRule' {Text
changeToken :: Text
ruleId :: Text
$sel:changeToken:DeleteRule' :: DeleteRule -> Text
$sel:ruleId:DeleteRule' :: DeleteRule -> 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
"RuleId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
ruleId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ChangeToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
changeToken)
          ]
      )

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

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

-- | /See:/ 'newDeleteRuleResponse' smart constructor.
data DeleteRuleResponse = DeleteRuleResponse'
  { -- | The @ChangeToken@ that you used to submit the @DeleteRule@ request. You
    -- can also use this value to query the status of the request. For more
    -- information, see GetChangeTokenStatus.
    DeleteRuleResponse -> Maybe Text
changeToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    DeleteRuleResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DeleteRuleResponse -> DeleteRuleResponse -> Bool
(DeleteRuleResponse -> DeleteRuleResponse -> Bool)
-> (DeleteRuleResponse -> DeleteRuleResponse -> Bool)
-> Eq DeleteRuleResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteRuleResponse -> DeleteRuleResponse -> Bool
$c/= :: DeleteRuleResponse -> DeleteRuleResponse -> Bool
== :: DeleteRuleResponse -> DeleteRuleResponse -> Bool
$c== :: DeleteRuleResponse -> DeleteRuleResponse -> Bool
Prelude.Eq, ReadPrec [DeleteRuleResponse]
ReadPrec DeleteRuleResponse
Int -> ReadS DeleteRuleResponse
ReadS [DeleteRuleResponse]
(Int -> ReadS DeleteRuleResponse)
-> ReadS [DeleteRuleResponse]
-> ReadPrec DeleteRuleResponse
-> ReadPrec [DeleteRuleResponse]
-> Read DeleteRuleResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteRuleResponse]
$creadListPrec :: ReadPrec [DeleteRuleResponse]
readPrec :: ReadPrec DeleteRuleResponse
$creadPrec :: ReadPrec DeleteRuleResponse
readList :: ReadS [DeleteRuleResponse]
$creadList :: ReadS [DeleteRuleResponse]
readsPrec :: Int -> ReadS DeleteRuleResponse
$creadsPrec :: Int -> ReadS DeleteRuleResponse
Prelude.Read, Int -> DeleteRuleResponse -> ShowS
[DeleteRuleResponse] -> ShowS
DeleteRuleResponse -> String
(Int -> DeleteRuleResponse -> ShowS)
-> (DeleteRuleResponse -> String)
-> ([DeleteRuleResponse] -> ShowS)
-> Show DeleteRuleResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteRuleResponse] -> ShowS
$cshowList :: [DeleteRuleResponse] -> ShowS
show :: DeleteRuleResponse -> String
$cshow :: DeleteRuleResponse -> String
showsPrec :: Int -> DeleteRuleResponse -> ShowS
$cshowsPrec :: Int -> DeleteRuleResponse -> ShowS
Prelude.Show, (forall x. DeleteRuleResponse -> Rep DeleteRuleResponse x)
-> (forall x. Rep DeleteRuleResponse x -> DeleteRuleResponse)
-> Generic DeleteRuleResponse
forall x. Rep DeleteRuleResponse x -> DeleteRuleResponse
forall x. DeleteRuleResponse -> Rep DeleteRuleResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteRuleResponse x -> DeleteRuleResponse
$cfrom :: forall x. DeleteRuleResponse -> Rep DeleteRuleResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeleteRuleResponse' 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:
--
-- 'changeToken', 'deleteRuleResponse_changeToken' - The @ChangeToken@ that you used to submit the @DeleteRule@ request. You
-- can also use this value to query the status of the request. For more
-- information, see GetChangeTokenStatus.
--
-- 'httpStatus', 'deleteRuleResponse_httpStatus' - The response's http status code.
newDeleteRuleResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteRuleResponse
newDeleteRuleResponse :: Int -> DeleteRuleResponse
newDeleteRuleResponse Int
pHttpStatus_ =
  DeleteRuleResponse' :: Maybe Text -> Int -> DeleteRuleResponse
DeleteRuleResponse'
    { $sel:changeToken:DeleteRuleResponse' :: Maybe Text
changeToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DeleteRuleResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The @ChangeToken@ that you used to submit the @DeleteRule@ request. You
-- can also use this value to query the status of the request. For more
-- information, see GetChangeTokenStatus.
deleteRuleResponse_changeToken :: Lens.Lens' DeleteRuleResponse (Prelude.Maybe Prelude.Text)
deleteRuleResponse_changeToken :: (Maybe Text -> f (Maybe Text))
-> DeleteRuleResponse -> f DeleteRuleResponse
deleteRuleResponse_changeToken = (DeleteRuleResponse -> Maybe Text)
-> (DeleteRuleResponse -> Maybe Text -> DeleteRuleResponse)
-> Lens
     DeleteRuleResponse DeleteRuleResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteRuleResponse' {Maybe Text
changeToken :: Maybe Text
$sel:changeToken:DeleteRuleResponse' :: DeleteRuleResponse -> Maybe Text
changeToken} -> Maybe Text
changeToken) (\s :: DeleteRuleResponse
s@DeleteRuleResponse' {} Maybe Text
a -> DeleteRuleResponse
s {$sel:changeToken:DeleteRuleResponse' :: Maybe Text
changeToken = Maybe Text
a} :: DeleteRuleResponse)

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

instance Prelude.NFData DeleteRuleResponse