{-# 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.AllowAction
-- 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.AllowAction 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 allow the request and 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:/ 'newAllowAction' smart constructor.
data AllowAction = AllowAction'
  { -- | 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>.
    AllowAction -> Maybe CustomRequestHandling
customRequestHandling :: Prelude.Maybe CustomRequestHandling
  }
  deriving (AllowAction -> AllowAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AllowAction -> AllowAction -> Bool
$c/= :: AllowAction -> AllowAction -> Bool
== :: AllowAction -> AllowAction -> Bool
$c== :: AllowAction -> AllowAction -> Bool
Prelude.Eq, ReadPrec [AllowAction]
ReadPrec AllowAction
Int -> ReadS AllowAction
ReadS [AllowAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AllowAction]
$creadListPrec :: ReadPrec [AllowAction]
readPrec :: ReadPrec AllowAction
$creadPrec :: ReadPrec AllowAction
readList :: ReadS [AllowAction]
$creadList :: ReadS [AllowAction]
readsPrec :: Int -> ReadS AllowAction
$creadsPrec :: Int -> ReadS AllowAction
Prelude.Read, Int -> AllowAction -> ShowS
[AllowAction] -> ShowS
AllowAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AllowAction] -> ShowS
$cshowList :: [AllowAction] -> ShowS
show :: AllowAction -> String
$cshow :: AllowAction -> String
showsPrec :: Int -> AllowAction -> ShowS
$cshowsPrec :: Int -> AllowAction -> ShowS
Prelude.Show, forall x. Rep AllowAction x -> AllowAction
forall x. AllowAction -> Rep AllowAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AllowAction x -> AllowAction
$cfrom :: forall x. AllowAction -> Rep AllowAction x
Prelude.Generic)

-- |
-- Create a value of 'AllowAction' 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', 'allowAction_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>.
newAllowAction ::
  AllowAction
newAllowAction :: AllowAction
newAllowAction =
  AllowAction'
    { $sel:customRequestHandling:AllowAction' :: 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>.
allowAction_customRequestHandling :: Lens.Lens' AllowAction (Prelude.Maybe CustomRequestHandling)
allowAction_customRequestHandling :: Lens' AllowAction (Maybe CustomRequestHandling)
allowAction_customRequestHandling = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllowAction' {Maybe CustomRequestHandling
customRequestHandling :: Maybe CustomRequestHandling
$sel:customRequestHandling:AllowAction' :: AllowAction -> Maybe CustomRequestHandling
customRequestHandling} -> Maybe CustomRequestHandling
customRequestHandling) (\s :: AllowAction
s@AllowAction' {} Maybe CustomRequestHandling
a -> AllowAction
s {$sel:customRequestHandling:AllowAction' :: Maybe CustomRequestHandling
customRequestHandling = Maybe CustomRequestHandling
a} :: AllowAction)

instance Data.FromJSON AllowAction where
  parseJSON :: Value -> Parser AllowAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AllowAction"
      ( \Object
x ->
          Maybe CustomRequestHandling -> AllowAction
AllowAction'
            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 AllowAction where
  hashWithSalt :: Int -> AllowAction -> Int
hashWithSalt Int
_salt AllowAction' {Maybe CustomRequestHandling
customRequestHandling :: Maybe CustomRequestHandling
$sel:customRequestHandling:AllowAction' :: AllowAction -> Maybe CustomRequestHandling
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CustomRequestHandling
customRequestHandling

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

instance Data.ToJSON AllowAction where
  toJSON :: AllowAction -> Value
toJSON AllowAction' {Maybe CustomRequestHandling
customRequestHandling :: Maybe CustomRequestHandling
$sel:customRequestHandling:AllowAction' :: AllowAction -> 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
          ]
      )