{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.WAFV2.Types.CountAction
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.WAFV2.Types.CountAction 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 Amazonka.WAFV2.Types.CustomRequestHandling

-- | Specifies that WAF should count the request. Optionally defines
-- additional custom handling for the request.
--
-- This is used in the context of other settings, for example to specify
-- values for RuleAction and web ACL DefaultAction.
--
-- /See:/ 'newCountAction' smart constructor.
data CountAction = CountAction'
  { -- | Defines custom handling for the web request.
    --
    -- For information about customizing web requests and responses, see
    -- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-custom-request-response.html Customizing web requests and responses in WAF>
    -- in the
    -- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html WAF Developer Guide>.
    CountAction -> Maybe CustomRequestHandling
customRequestHandling :: Prelude.Maybe CustomRequestHandling
  }
  deriving (CountAction -> CountAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CountAction -> CountAction -> Bool
$c/= :: CountAction -> CountAction -> Bool
== :: CountAction -> CountAction -> Bool
$c== :: CountAction -> CountAction -> Bool
Prelude.Eq, ReadPrec [CountAction]
ReadPrec CountAction
Int -> ReadS CountAction
ReadS [CountAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CountAction]
$creadListPrec :: ReadPrec [CountAction]
readPrec :: ReadPrec CountAction
$creadPrec :: ReadPrec CountAction
readList :: ReadS [CountAction]
$creadList :: ReadS [CountAction]
readsPrec :: Int -> ReadS CountAction
$creadsPrec :: Int -> ReadS CountAction
Prelude.Read, Int -> CountAction -> ShowS
[CountAction] -> ShowS
CountAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CountAction] -> ShowS
$cshowList :: [CountAction] -> ShowS
show :: CountAction -> String
$cshow :: CountAction -> String
showsPrec :: Int -> CountAction -> ShowS
$cshowsPrec :: Int -> CountAction -> ShowS
Prelude.Show, forall x. Rep CountAction x -> CountAction
forall x. CountAction -> Rep CountAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CountAction x -> CountAction
$cfrom :: forall x. CountAction -> Rep CountAction x
Prelude.Generic)

-- |
-- Create a value of 'CountAction' 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:
--
-- 'customRequestHandling', 'countAction_customRequestHandling' - Defines custom handling for the web request.
--
-- For information about customizing web requests and responses, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-custom-request-response.html Customizing web requests and responses in WAF>
-- in the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html WAF Developer Guide>.
newCountAction ::
  CountAction
newCountAction :: CountAction
newCountAction =
  CountAction'
    { $sel:customRequestHandling:CountAction' :: Maybe CustomRequestHandling
customRequestHandling =
        forall a. Maybe a
Prelude.Nothing
    }

-- | Defines custom handling for the web request.
--
-- For information about customizing web requests and responses, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-custom-request-response.html Customizing web requests and responses in WAF>
-- in the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html WAF Developer Guide>.
countAction_customRequestHandling :: Lens.Lens' CountAction (Prelude.Maybe CustomRequestHandling)
countAction_customRequestHandling :: Lens' CountAction (Maybe CustomRequestHandling)
countAction_customRequestHandling = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CountAction' {Maybe CustomRequestHandling
customRequestHandling :: Maybe CustomRequestHandling
$sel:customRequestHandling:CountAction' :: CountAction -> Maybe CustomRequestHandling
customRequestHandling} -> Maybe CustomRequestHandling
customRequestHandling) (\s :: CountAction
s@CountAction' {} Maybe CustomRequestHandling
a -> CountAction
s {$sel:customRequestHandling:CountAction' :: Maybe CustomRequestHandling
customRequestHandling = Maybe CustomRequestHandling
a} :: CountAction)

instance Data.FromJSON CountAction where
  parseJSON :: Value -> Parser CountAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CountAction"
      ( \Object
x ->
          Maybe CustomRequestHandling -> CountAction
CountAction'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"CustomRequestHandling")
      )

instance Prelude.Hashable CountAction where
  hashWithSalt :: Int -> CountAction -> Int
hashWithSalt Int
_salt CountAction' {Maybe CustomRequestHandling
customRequestHandling :: Maybe CustomRequestHandling
$sel:customRequestHandling:CountAction' :: CountAction -> Maybe CustomRequestHandling
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CustomRequestHandling
customRequestHandling

instance Prelude.NFData CountAction where
  rnf :: CountAction -> ()
rnf CountAction' {Maybe CustomRequestHandling
customRequestHandling :: Maybe CustomRequestHandling
$sel:customRequestHandling:CountAction' :: CountAction -> Maybe CustomRequestHandling
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe CustomRequestHandling
customRequestHandling

instance Data.ToJSON CountAction where
  toJSON :: CountAction -> Value
toJSON CountAction' {Maybe CustomRequestHandling
customRequestHandling :: Maybe CustomRequestHandling
$sel:customRequestHandling:CountAction' :: CountAction -> Maybe CustomRequestHandling
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CustomRequestHandling" 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 CustomRequestHandling
customRequestHandling
          ]
      )