{-# 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.DeleteRateBasedRule
-- 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 RateBasedRule. 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 @RateBasedRule@ from AWS WAF, perform the
-- following steps:
--
-- 1.  Update the @RateBasedRule@ to remove predicates, if any. For more
--     information, see UpdateRateBasedRule.
--
-- 2.  Use GetChangeToken to get the change token that you provide in the
--     @ChangeToken@ parameter of a @DeleteRateBasedRule@ request.
--
-- 3.  Submit a @DeleteRateBasedRule@ request.
module Amazonka.WAFRegional.DeleteRateBasedRule
  ( -- * Creating a Request
    DeleteRateBasedRule (..),
    newDeleteRateBasedRule,

    -- * Request Lenses
    deleteRateBasedRule_ruleId,
    deleteRateBasedRule_changeToken,

    -- * Destructuring the Response
    DeleteRateBasedRuleResponse (..),
    newDeleteRateBasedRuleResponse,

    -- * Response Lenses
    deleteRateBasedRuleResponse_changeToken,
    deleteRateBasedRuleResponse_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:/ 'newDeleteRateBasedRule' smart constructor.
data DeleteRateBasedRule = DeleteRateBasedRule'
  { -- | The @RuleId@ of the RateBasedRule that you want to delete. @RuleId@ is
    -- returned by CreateRateBasedRule and by ListRateBasedRules.
    DeleteRateBasedRule -> Text
ruleId :: Prelude.Text,
    -- | The value returned by the most recent call to GetChangeToken.
    DeleteRateBasedRule -> Text
changeToken :: Prelude.Text
  }
  deriving (DeleteRateBasedRule -> DeleteRateBasedRule -> Bool
(DeleteRateBasedRule -> DeleteRateBasedRule -> Bool)
-> (DeleteRateBasedRule -> DeleteRateBasedRule -> Bool)
-> Eq DeleteRateBasedRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteRateBasedRule -> DeleteRateBasedRule -> Bool
$c/= :: DeleteRateBasedRule -> DeleteRateBasedRule -> Bool
== :: DeleteRateBasedRule -> DeleteRateBasedRule -> Bool
$c== :: DeleteRateBasedRule -> DeleteRateBasedRule -> Bool
Prelude.Eq, ReadPrec [DeleteRateBasedRule]
ReadPrec DeleteRateBasedRule
Int -> ReadS DeleteRateBasedRule
ReadS [DeleteRateBasedRule]
(Int -> ReadS DeleteRateBasedRule)
-> ReadS [DeleteRateBasedRule]
-> ReadPrec DeleteRateBasedRule
-> ReadPrec [DeleteRateBasedRule]
-> Read DeleteRateBasedRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteRateBasedRule]
$creadListPrec :: ReadPrec [DeleteRateBasedRule]
readPrec :: ReadPrec DeleteRateBasedRule
$creadPrec :: ReadPrec DeleteRateBasedRule
readList :: ReadS [DeleteRateBasedRule]
$creadList :: ReadS [DeleteRateBasedRule]
readsPrec :: Int -> ReadS DeleteRateBasedRule
$creadsPrec :: Int -> ReadS DeleteRateBasedRule
Prelude.Read, Int -> DeleteRateBasedRule -> ShowS
[DeleteRateBasedRule] -> ShowS
DeleteRateBasedRule -> String
(Int -> DeleteRateBasedRule -> ShowS)
-> (DeleteRateBasedRule -> String)
-> ([DeleteRateBasedRule] -> ShowS)
-> Show DeleteRateBasedRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteRateBasedRule] -> ShowS
$cshowList :: [DeleteRateBasedRule] -> ShowS
show :: DeleteRateBasedRule -> String
$cshow :: DeleteRateBasedRule -> String
showsPrec :: Int -> DeleteRateBasedRule -> ShowS
$cshowsPrec :: Int -> DeleteRateBasedRule -> ShowS
Prelude.Show, (forall x. DeleteRateBasedRule -> Rep DeleteRateBasedRule x)
-> (forall x. Rep DeleteRateBasedRule x -> DeleteRateBasedRule)
-> Generic DeleteRateBasedRule
forall x. Rep DeleteRateBasedRule x -> DeleteRateBasedRule
forall x. DeleteRateBasedRule -> Rep DeleteRateBasedRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteRateBasedRule x -> DeleteRateBasedRule
$cfrom :: forall x. DeleteRateBasedRule -> Rep DeleteRateBasedRule x
Prelude.Generic)

-- |
-- Create a value of 'DeleteRateBasedRule' 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', 'deleteRateBasedRule_ruleId' - The @RuleId@ of the RateBasedRule that you want to delete. @RuleId@ is
-- returned by CreateRateBasedRule and by ListRateBasedRules.
--
-- 'changeToken', 'deleteRateBasedRule_changeToken' - The value returned by the most recent call to GetChangeToken.
newDeleteRateBasedRule ::
  -- | 'ruleId'
  Prelude.Text ->
  -- | 'changeToken'
  Prelude.Text ->
  DeleteRateBasedRule
newDeleteRateBasedRule :: Text -> Text -> DeleteRateBasedRule
newDeleteRateBasedRule Text
pRuleId_ Text
pChangeToken_ =
  DeleteRateBasedRule' :: Text -> Text -> DeleteRateBasedRule
DeleteRateBasedRule'
    { $sel:ruleId:DeleteRateBasedRule' :: Text
ruleId = Text
pRuleId_,
      $sel:changeToken:DeleteRateBasedRule' :: Text
changeToken = Text
pChangeToken_
    }

-- | The @RuleId@ of the RateBasedRule that you want to delete. @RuleId@ is
-- returned by CreateRateBasedRule and by ListRateBasedRules.
deleteRateBasedRule_ruleId :: Lens.Lens' DeleteRateBasedRule Prelude.Text
deleteRateBasedRule_ruleId :: (Text -> f Text) -> DeleteRateBasedRule -> f DeleteRateBasedRule
deleteRateBasedRule_ruleId = (DeleteRateBasedRule -> Text)
-> (DeleteRateBasedRule -> Text -> DeleteRateBasedRule)
-> Lens DeleteRateBasedRule DeleteRateBasedRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteRateBasedRule' {Text
ruleId :: Text
$sel:ruleId:DeleteRateBasedRule' :: DeleteRateBasedRule -> Text
ruleId} -> Text
ruleId) (\s :: DeleteRateBasedRule
s@DeleteRateBasedRule' {} Text
a -> DeleteRateBasedRule
s {$sel:ruleId:DeleteRateBasedRule' :: Text
ruleId = Text
a} :: DeleteRateBasedRule)

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

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

instance Prelude.NFData DeleteRateBasedRule

instance Core.ToHeaders DeleteRateBasedRule where
  toHeaders :: DeleteRateBasedRule -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DeleteRateBasedRule -> 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.DeleteRateBasedRule" ::
                          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 DeleteRateBasedRule where
  toJSON :: DeleteRateBasedRule -> Value
toJSON DeleteRateBasedRule' {Text
changeToken :: Text
ruleId :: Text
$sel:changeToken:DeleteRateBasedRule' :: DeleteRateBasedRule -> Text
$sel:ruleId:DeleteRateBasedRule' :: DeleteRateBasedRule -> 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 DeleteRateBasedRule where
  toPath :: DeleteRateBasedRule -> ByteString
toPath = ByteString -> DeleteRateBasedRule -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

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

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

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

instance Prelude.NFData DeleteRateBasedRuleResponse