{-# 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.ChallengeConfig
-- 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.ChallengeConfig 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.ImmunityTimeProperty

-- | Specifies how WAF should handle @Challenge@ evaluations. This is
-- available at the web ACL level and in each rule.
--
-- /See:/ 'newChallengeConfig' smart constructor.
data ChallengeConfig = ChallengeConfig'
  { -- | Determines how long a challenge timestamp in the token remains valid
    -- after the client successfully responds to a challenge.
    ChallengeConfig -> Maybe ImmunityTimeProperty
immunityTimeProperty :: Prelude.Maybe ImmunityTimeProperty
  }
  deriving (ChallengeConfig -> ChallengeConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChallengeConfig -> ChallengeConfig -> Bool
$c/= :: ChallengeConfig -> ChallengeConfig -> Bool
== :: ChallengeConfig -> ChallengeConfig -> Bool
$c== :: ChallengeConfig -> ChallengeConfig -> Bool
Prelude.Eq, ReadPrec [ChallengeConfig]
ReadPrec ChallengeConfig
Int -> ReadS ChallengeConfig
ReadS [ChallengeConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ChallengeConfig]
$creadListPrec :: ReadPrec [ChallengeConfig]
readPrec :: ReadPrec ChallengeConfig
$creadPrec :: ReadPrec ChallengeConfig
readList :: ReadS [ChallengeConfig]
$creadList :: ReadS [ChallengeConfig]
readsPrec :: Int -> ReadS ChallengeConfig
$creadsPrec :: Int -> ReadS ChallengeConfig
Prelude.Read, Int -> ChallengeConfig -> ShowS
[ChallengeConfig] -> ShowS
ChallengeConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChallengeConfig] -> ShowS
$cshowList :: [ChallengeConfig] -> ShowS
show :: ChallengeConfig -> String
$cshow :: ChallengeConfig -> String
showsPrec :: Int -> ChallengeConfig -> ShowS
$cshowsPrec :: Int -> ChallengeConfig -> ShowS
Prelude.Show, forall x. Rep ChallengeConfig x -> ChallengeConfig
forall x. ChallengeConfig -> Rep ChallengeConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ChallengeConfig x -> ChallengeConfig
$cfrom :: forall x. ChallengeConfig -> Rep ChallengeConfig x
Prelude.Generic)

-- |
-- Create a value of 'ChallengeConfig' 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:
--
-- 'immunityTimeProperty', 'challengeConfig_immunityTimeProperty' - Determines how long a challenge timestamp in the token remains valid
-- after the client successfully responds to a challenge.
newChallengeConfig ::
  ChallengeConfig
newChallengeConfig :: ChallengeConfig
newChallengeConfig =
  ChallengeConfig'
    { $sel:immunityTimeProperty:ChallengeConfig' :: Maybe ImmunityTimeProperty
immunityTimeProperty =
        forall a. Maybe a
Prelude.Nothing
    }

-- | Determines how long a challenge timestamp in the token remains valid
-- after the client successfully responds to a challenge.
challengeConfig_immunityTimeProperty :: Lens.Lens' ChallengeConfig (Prelude.Maybe ImmunityTimeProperty)
challengeConfig_immunityTimeProperty :: Lens' ChallengeConfig (Maybe ImmunityTimeProperty)
challengeConfig_immunityTimeProperty = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChallengeConfig' {Maybe ImmunityTimeProperty
immunityTimeProperty :: Maybe ImmunityTimeProperty
$sel:immunityTimeProperty:ChallengeConfig' :: ChallengeConfig -> Maybe ImmunityTimeProperty
immunityTimeProperty} -> Maybe ImmunityTimeProperty
immunityTimeProperty) (\s :: ChallengeConfig
s@ChallengeConfig' {} Maybe ImmunityTimeProperty
a -> ChallengeConfig
s {$sel:immunityTimeProperty:ChallengeConfig' :: Maybe ImmunityTimeProperty
immunityTimeProperty = Maybe ImmunityTimeProperty
a} :: ChallengeConfig)

instance Data.FromJSON ChallengeConfig where
  parseJSON :: Value -> Parser ChallengeConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ChallengeConfig"
      ( \Object
x ->
          Maybe ImmunityTimeProperty -> ChallengeConfig
ChallengeConfig'
            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
"ImmunityTimeProperty")
      )

instance Prelude.Hashable ChallengeConfig where
  hashWithSalt :: Int -> ChallengeConfig -> Int
hashWithSalt Int
_salt ChallengeConfig' {Maybe ImmunityTimeProperty
immunityTimeProperty :: Maybe ImmunityTimeProperty
$sel:immunityTimeProperty:ChallengeConfig' :: ChallengeConfig -> Maybe ImmunityTimeProperty
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ImmunityTimeProperty
immunityTimeProperty

instance Prelude.NFData ChallengeConfig where
  rnf :: ChallengeConfig -> ()
rnf ChallengeConfig' {Maybe ImmunityTimeProperty
immunityTimeProperty :: Maybe ImmunityTimeProperty
$sel:immunityTimeProperty:ChallengeConfig' :: ChallengeConfig -> Maybe ImmunityTimeProperty
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ImmunityTimeProperty
immunityTimeProperty

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