{-# 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.ChallengeResponse
-- 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.ChallengeResponse 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.FailureReason

-- | The result from the inspection of the web request for a valid challenge
-- token.
--
-- /See:/ 'newChallengeResponse' smart constructor.
data ChallengeResponse = ChallengeResponse'
  { -- | The reason for failure, populated when the evaluation of the token
    -- fails.
    ChallengeResponse -> Maybe FailureReason
failureReason :: Prelude.Maybe FailureReason,
    -- | The HTTP response code indicating the status of the challenge token in
    -- the web request. If the token is missing, invalid, or expired, this code
    -- is @202 Request Accepted@.
    ChallengeResponse -> Maybe Int
responseCode :: Prelude.Maybe Prelude.Int,
    -- | The time that the challenge was last solved for the supplied token.
    ChallengeResponse -> Maybe Integer
solveTimestamp :: Prelude.Maybe Prelude.Integer
  }
  deriving (ChallengeResponse -> ChallengeResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChallengeResponse -> ChallengeResponse -> Bool
$c/= :: ChallengeResponse -> ChallengeResponse -> Bool
== :: ChallengeResponse -> ChallengeResponse -> Bool
$c== :: ChallengeResponse -> ChallengeResponse -> Bool
Prelude.Eq, ReadPrec [ChallengeResponse]
ReadPrec ChallengeResponse
Int -> ReadS ChallengeResponse
ReadS [ChallengeResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ChallengeResponse]
$creadListPrec :: ReadPrec [ChallengeResponse]
readPrec :: ReadPrec ChallengeResponse
$creadPrec :: ReadPrec ChallengeResponse
readList :: ReadS [ChallengeResponse]
$creadList :: ReadS [ChallengeResponse]
readsPrec :: Int -> ReadS ChallengeResponse
$creadsPrec :: Int -> ReadS ChallengeResponse
Prelude.Read, Int -> ChallengeResponse -> ShowS
[ChallengeResponse] -> ShowS
ChallengeResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChallengeResponse] -> ShowS
$cshowList :: [ChallengeResponse] -> ShowS
show :: ChallengeResponse -> String
$cshow :: ChallengeResponse -> String
showsPrec :: Int -> ChallengeResponse -> ShowS
$cshowsPrec :: Int -> ChallengeResponse -> ShowS
Prelude.Show, forall x. Rep ChallengeResponse x -> ChallengeResponse
forall x. ChallengeResponse -> Rep ChallengeResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ChallengeResponse x -> ChallengeResponse
$cfrom :: forall x. ChallengeResponse -> Rep ChallengeResponse x
Prelude.Generic)

-- |
-- Create a value of 'ChallengeResponse' 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:
--
-- 'failureReason', 'challengeResponse_failureReason' - The reason for failure, populated when the evaluation of the token
-- fails.
--
-- 'responseCode', 'challengeResponse_responseCode' - The HTTP response code indicating the status of the challenge token in
-- the web request. If the token is missing, invalid, or expired, this code
-- is @202 Request Accepted@.
--
-- 'solveTimestamp', 'challengeResponse_solveTimestamp' - The time that the challenge was last solved for the supplied token.
newChallengeResponse ::
  ChallengeResponse
newChallengeResponse :: ChallengeResponse
newChallengeResponse =
  ChallengeResponse'
    { $sel:failureReason:ChallengeResponse' :: Maybe FailureReason
failureReason = forall a. Maybe a
Prelude.Nothing,
      $sel:responseCode:ChallengeResponse' :: Maybe Int
responseCode = forall a. Maybe a
Prelude.Nothing,
      $sel:solveTimestamp:ChallengeResponse' :: Maybe Integer
solveTimestamp = forall a. Maybe a
Prelude.Nothing
    }

-- | The reason for failure, populated when the evaluation of the token
-- fails.
challengeResponse_failureReason :: Lens.Lens' ChallengeResponse (Prelude.Maybe FailureReason)
challengeResponse_failureReason :: Lens' ChallengeResponse (Maybe FailureReason)
challengeResponse_failureReason = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChallengeResponse' {Maybe FailureReason
failureReason :: Maybe FailureReason
$sel:failureReason:ChallengeResponse' :: ChallengeResponse -> Maybe FailureReason
failureReason} -> Maybe FailureReason
failureReason) (\s :: ChallengeResponse
s@ChallengeResponse' {} Maybe FailureReason
a -> ChallengeResponse
s {$sel:failureReason:ChallengeResponse' :: Maybe FailureReason
failureReason = Maybe FailureReason
a} :: ChallengeResponse)

-- | The HTTP response code indicating the status of the challenge token in
-- the web request. If the token is missing, invalid, or expired, this code
-- is @202 Request Accepted@.
challengeResponse_responseCode :: Lens.Lens' ChallengeResponse (Prelude.Maybe Prelude.Int)
challengeResponse_responseCode :: Lens' ChallengeResponse (Maybe Int)
challengeResponse_responseCode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChallengeResponse' {Maybe Int
responseCode :: Maybe Int
$sel:responseCode:ChallengeResponse' :: ChallengeResponse -> Maybe Int
responseCode} -> Maybe Int
responseCode) (\s :: ChallengeResponse
s@ChallengeResponse' {} Maybe Int
a -> ChallengeResponse
s {$sel:responseCode:ChallengeResponse' :: Maybe Int
responseCode = Maybe Int
a} :: ChallengeResponse)

-- | The time that the challenge was last solved for the supplied token.
challengeResponse_solveTimestamp :: Lens.Lens' ChallengeResponse (Prelude.Maybe Prelude.Integer)
challengeResponse_solveTimestamp :: Lens' ChallengeResponse (Maybe Integer)
challengeResponse_solveTimestamp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChallengeResponse' {Maybe Integer
solveTimestamp :: Maybe Integer
$sel:solveTimestamp:ChallengeResponse' :: ChallengeResponse -> Maybe Integer
solveTimestamp} -> Maybe Integer
solveTimestamp) (\s :: ChallengeResponse
s@ChallengeResponse' {} Maybe Integer
a -> ChallengeResponse
s {$sel:solveTimestamp:ChallengeResponse' :: Maybe Integer
solveTimestamp = Maybe Integer
a} :: ChallengeResponse)

instance Data.FromJSON ChallengeResponse where
  parseJSON :: Value -> Parser ChallengeResponse
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ChallengeResponse"
      ( \Object
x ->
          Maybe FailureReason
-> Maybe Int -> Maybe Integer -> ChallengeResponse
ChallengeResponse'
            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
"FailureReason")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ResponseCode")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"SolveTimestamp")
      )

instance Prelude.Hashable ChallengeResponse where
  hashWithSalt :: Int -> ChallengeResponse -> Int
hashWithSalt Int
_salt ChallengeResponse' {Maybe Int
Maybe Integer
Maybe FailureReason
solveTimestamp :: Maybe Integer
responseCode :: Maybe Int
failureReason :: Maybe FailureReason
$sel:solveTimestamp:ChallengeResponse' :: ChallengeResponse -> Maybe Integer
$sel:responseCode:ChallengeResponse' :: ChallengeResponse -> Maybe Int
$sel:failureReason:ChallengeResponse' :: ChallengeResponse -> Maybe FailureReason
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe FailureReason
failureReason
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
responseCode
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Integer
solveTimestamp

instance Prelude.NFData ChallengeResponse where
  rnf :: ChallengeResponse -> ()
rnf ChallengeResponse' {Maybe Int
Maybe Integer
Maybe FailureReason
solveTimestamp :: Maybe Integer
responseCode :: Maybe Int
failureReason :: Maybe FailureReason
$sel:solveTimestamp:ChallengeResponse' :: ChallengeResponse -> Maybe Integer
$sel:responseCode:ChallengeResponse' :: ChallengeResponse -> Maybe Int
$sel:failureReason:ChallengeResponse' :: ChallengeResponse -> Maybe FailureReason
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe FailureReason
failureReason
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
responseCode
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Integer
solveTimestamp