{-# 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.ListRules
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.
--
-- Returns an array of RuleSummary objects.
module Amazonka.WAFRegional.ListRules
  ( -- * Creating a Request
    ListRules (..),
    newListRules,

    -- * Request Lenses
    listRules_limit,
    listRules_nextMarker,

    -- * Destructuring the Response
    ListRulesResponse (..),
    newListRulesResponse,

    -- * Response Lenses
    listRulesResponse_nextMarker,
    listRulesResponse_rules,
    listRulesResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListRules' smart constructor.
data ListRules = ListRules'
  { -- | Specifies the number of @Rules@ that you want AWS WAF to return for this
    -- request. If you have more @Rules@ than the number that you specify for
    -- @Limit@, the response includes a @NextMarker@ value that you can use to
    -- get another batch of @Rules@.
    ListRules -> Maybe Natural
limit :: Prelude.Maybe Prelude.Natural,
    -- | If you specify a value for @Limit@ and you have more @Rules@ than the
    -- value of @Limit@, AWS WAF returns a @NextMarker@ value in the response
    -- that allows you to list another group of @Rules@. For the second and
    -- subsequent @ListRules@ requests, specify the value of @NextMarker@ from
    -- the previous response to get information about another batch of @Rules@.
    ListRules -> Maybe Text
nextMarker :: Prelude.Maybe Prelude.Text
  }
  deriving (ListRules -> ListRules -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListRules -> ListRules -> Bool
$c/= :: ListRules -> ListRules -> Bool
== :: ListRules -> ListRules -> Bool
$c== :: ListRules -> ListRules -> Bool
Prelude.Eq, ReadPrec [ListRules]
ReadPrec ListRules
Int -> ReadS ListRules
ReadS [ListRules]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListRules]
$creadListPrec :: ReadPrec [ListRules]
readPrec :: ReadPrec ListRules
$creadPrec :: ReadPrec ListRules
readList :: ReadS [ListRules]
$creadList :: ReadS [ListRules]
readsPrec :: Int -> ReadS ListRules
$creadsPrec :: Int -> ReadS ListRules
Prelude.Read, Int -> ListRules -> ShowS
[ListRules] -> ShowS
ListRules -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListRules] -> ShowS
$cshowList :: [ListRules] -> ShowS
show :: ListRules -> String
$cshow :: ListRules -> String
showsPrec :: Int -> ListRules -> ShowS
$cshowsPrec :: Int -> ListRules -> ShowS
Prelude.Show, forall x. Rep ListRules x -> ListRules
forall x. ListRules -> Rep ListRules x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListRules x -> ListRules
$cfrom :: forall x. ListRules -> Rep ListRules x
Prelude.Generic)

-- |
-- Create a value of 'ListRules' 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:
--
-- 'limit', 'listRules_limit' - Specifies the number of @Rules@ that you want AWS WAF to return for this
-- request. If you have more @Rules@ than the number that you specify for
-- @Limit@, the response includes a @NextMarker@ value that you can use to
-- get another batch of @Rules@.
--
-- 'nextMarker', 'listRules_nextMarker' - If you specify a value for @Limit@ and you have more @Rules@ than the
-- value of @Limit@, AWS WAF returns a @NextMarker@ value in the response
-- that allows you to list another group of @Rules@. For the second and
-- subsequent @ListRules@ requests, specify the value of @NextMarker@ from
-- the previous response to get information about another batch of @Rules@.
newListRules ::
  ListRules
newListRules :: ListRules
newListRules =
  ListRules'
    { $sel:limit:ListRules' :: Maybe Natural
limit = forall a. Maybe a
Prelude.Nothing,
      $sel:nextMarker:ListRules' :: Maybe Text
nextMarker = forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the number of @Rules@ that you want AWS WAF to return for this
-- request. If you have more @Rules@ than the number that you specify for
-- @Limit@, the response includes a @NextMarker@ value that you can use to
-- get another batch of @Rules@.
listRules_limit :: Lens.Lens' ListRules (Prelude.Maybe Prelude.Natural)
listRules_limit :: Lens' ListRules (Maybe Natural)
listRules_limit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRules' {Maybe Natural
limit :: Maybe Natural
$sel:limit:ListRules' :: ListRules -> Maybe Natural
limit} -> Maybe Natural
limit) (\s :: ListRules
s@ListRules' {} Maybe Natural
a -> ListRules
s {$sel:limit:ListRules' :: Maybe Natural
limit = Maybe Natural
a} :: ListRules)

-- | If you specify a value for @Limit@ and you have more @Rules@ than the
-- value of @Limit@, AWS WAF returns a @NextMarker@ value in the response
-- that allows you to list another group of @Rules@. For the second and
-- subsequent @ListRules@ requests, specify the value of @NextMarker@ from
-- the previous response to get information about another batch of @Rules@.
listRules_nextMarker :: Lens.Lens' ListRules (Prelude.Maybe Prelude.Text)
listRules_nextMarker :: Lens' ListRules (Maybe Text)
listRules_nextMarker = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRules' {Maybe Text
nextMarker :: Maybe Text
$sel:nextMarker:ListRules' :: ListRules -> Maybe Text
nextMarker} -> Maybe Text
nextMarker) (\s :: ListRules
s@ListRules' {} Maybe Text
a -> ListRules
s {$sel:nextMarker:ListRules' :: Maybe Text
nextMarker = Maybe Text
a} :: ListRules)

instance Core.AWSRequest ListRules where
  type AWSResponse ListRules = ListRulesResponse
  request :: (Service -> Service) -> ListRules -> Request ListRules
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 ListRules
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListRules)))
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 ->
          Maybe Text -> Maybe [RuleSummary] -> Int -> ListRulesResponse
ListRulesResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"NextMarker")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Rules" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => 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))
      )

instance Prelude.Hashable ListRules where
  hashWithSalt :: Int -> ListRules -> Int
hashWithSalt Int
_salt ListRules' {Maybe Natural
Maybe Text
nextMarker :: Maybe Text
limit :: Maybe Natural
$sel:nextMarker:ListRules' :: ListRules -> Maybe Text
$sel:limit:ListRules' :: ListRules -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
limit
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextMarker

instance Prelude.NFData ListRules where
  rnf :: ListRules -> ()
rnf ListRules' {Maybe Natural
Maybe Text
nextMarker :: Maybe Text
limit :: Maybe Natural
$sel:nextMarker:ListRules' :: ListRules -> Maybe Text
$sel:limit:ListRules' :: ListRules -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
limit
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextMarker

instance Data.ToHeaders ListRules where
  toHeaders :: ListRules -> 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
"AWSWAF_Regional_20161128.ListRules" ::
                          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 ListRules where
  toJSON :: ListRules -> Value
toJSON ListRules' {Maybe Natural
Maybe Text
nextMarker :: Maybe Text
limit :: Maybe Natural
$sel:nextMarker:ListRules' :: ListRules -> Maybe Text
$sel:limit:ListRules' :: ListRules -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Limit" 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 Natural
limit,
            (Key
"NextMarker" 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
nextMarker
          ]
      )

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

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

-- | /See:/ 'newListRulesResponse' smart constructor.
data ListRulesResponse = ListRulesResponse'
  { -- | If you have more @Rules@ than the number that you specified for @Limit@
    -- in the request, the response includes a @NextMarker@ value. To list more
    -- @Rules@, submit another @ListRules@ request, and specify the
    -- @NextMarker@ value from the response in the @NextMarker@ value in the
    -- next request.
    ListRulesResponse -> Maybe Text
nextMarker :: Prelude.Maybe Prelude.Text,
    -- | An array of RuleSummary objects.
    ListRulesResponse -> Maybe [RuleSummary]
rules :: Prelude.Maybe [RuleSummary],
    -- | The response's http status code.
    ListRulesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListRulesResponse -> ListRulesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListRulesResponse -> ListRulesResponse -> Bool
$c/= :: ListRulesResponse -> ListRulesResponse -> Bool
== :: ListRulesResponse -> ListRulesResponse -> Bool
$c== :: ListRulesResponse -> ListRulesResponse -> Bool
Prelude.Eq, ReadPrec [ListRulesResponse]
ReadPrec ListRulesResponse
Int -> ReadS ListRulesResponse
ReadS [ListRulesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListRulesResponse]
$creadListPrec :: ReadPrec [ListRulesResponse]
readPrec :: ReadPrec ListRulesResponse
$creadPrec :: ReadPrec ListRulesResponse
readList :: ReadS [ListRulesResponse]
$creadList :: ReadS [ListRulesResponse]
readsPrec :: Int -> ReadS ListRulesResponse
$creadsPrec :: Int -> ReadS ListRulesResponse
Prelude.Read, Int -> ListRulesResponse -> ShowS
[ListRulesResponse] -> ShowS
ListRulesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListRulesResponse] -> ShowS
$cshowList :: [ListRulesResponse] -> ShowS
show :: ListRulesResponse -> String
$cshow :: ListRulesResponse -> String
showsPrec :: Int -> ListRulesResponse -> ShowS
$cshowsPrec :: Int -> ListRulesResponse -> ShowS
Prelude.Show, forall x. Rep ListRulesResponse x -> ListRulesResponse
forall x. ListRulesResponse -> Rep ListRulesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListRulesResponse x -> ListRulesResponse
$cfrom :: forall x. ListRulesResponse -> Rep ListRulesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListRulesResponse' 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:
--
-- 'nextMarker', 'listRulesResponse_nextMarker' - If you have more @Rules@ than the number that you specified for @Limit@
-- in the request, the response includes a @NextMarker@ value. To list more
-- @Rules@, submit another @ListRules@ request, and specify the
-- @NextMarker@ value from the response in the @NextMarker@ value in the
-- next request.
--
-- 'rules', 'listRulesResponse_rules' - An array of RuleSummary objects.
--
-- 'httpStatus', 'listRulesResponse_httpStatus' - The response's http status code.
newListRulesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListRulesResponse
newListRulesResponse :: Int -> ListRulesResponse
newListRulesResponse Int
pHttpStatus_ =
  ListRulesResponse'
    { $sel:nextMarker:ListRulesResponse' :: Maybe Text
nextMarker = forall a. Maybe a
Prelude.Nothing,
      $sel:rules:ListRulesResponse' :: Maybe [RuleSummary]
rules = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListRulesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | If you have more @Rules@ than the number that you specified for @Limit@
-- in the request, the response includes a @NextMarker@ value. To list more
-- @Rules@, submit another @ListRules@ request, and specify the
-- @NextMarker@ value from the response in the @NextMarker@ value in the
-- next request.
listRulesResponse_nextMarker :: Lens.Lens' ListRulesResponse (Prelude.Maybe Prelude.Text)
listRulesResponse_nextMarker :: Lens' ListRulesResponse (Maybe Text)
listRulesResponse_nextMarker = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRulesResponse' {Maybe Text
nextMarker :: Maybe Text
$sel:nextMarker:ListRulesResponse' :: ListRulesResponse -> Maybe Text
nextMarker} -> Maybe Text
nextMarker) (\s :: ListRulesResponse
s@ListRulesResponse' {} Maybe Text
a -> ListRulesResponse
s {$sel:nextMarker:ListRulesResponse' :: Maybe Text
nextMarker = Maybe Text
a} :: ListRulesResponse)

-- | An array of RuleSummary objects.
listRulesResponse_rules :: Lens.Lens' ListRulesResponse (Prelude.Maybe [RuleSummary])
listRulesResponse_rules :: Lens' ListRulesResponse (Maybe [RuleSummary])
listRulesResponse_rules = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRulesResponse' {Maybe [RuleSummary]
rules :: Maybe [RuleSummary]
$sel:rules:ListRulesResponse' :: ListRulesResponse -> Maybe [RuleSummary]
rules} -> Maybe [RuleSummary]
rules) (\s :: ListRulesResponse
s@ListRulesResponse' {} Maybe [RuleSummary]
a -> ListRulesResponse
s {$sel:rules:ListRulesResponse' :: Maybe [RuleSummary]
rules = Maybe [RuleSummary]
a} :: ListRulesResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData ListRulesResponse where
  rnf :: ListRulesResponse -> ()
rnf ListRulesResponse' {Int
Maybe [RuleSummary]
Maybe Text
httpStatus :: Int
rules :: Maybe [RuleSummary]
nextMarker :: Maybe Text
$sel:httpStatus:ListRulesResponse' :: ListRulesResponse -> Int
$sel:rules:ListRulesResponse' :: ListRulesResponse -> Maybe [RuleSummary]
$sel:nextMarker:ListRulesResponse' :: ListRulesResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextMarker
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [RuleSummary]
rules
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus