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

-- |
-- Create a value of 'CaptchaResponse' 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', 'captchaResponse_failureReason' - The reason for failure, populated when the evaluation of the token
-- fails.
--
-- 'responseCode', 'captchaResponse_responseCode' - The HTTP response code indicating the status of the @CAPTCHA@ token in
-- the web request. If the token is missing, invalid, or expired, this code
-- is @405 Method Not Allowed@.
--
-- 'solveTimestamp', 'captchaResponse_solveTimestamp' - The time that the @CAPTCHA@ was last solved for the supplied token.
newCaptchaResponse ::
  CaptchaResponse
newCaptchaResponse :: CaptchaResponse
newCaptchaResponse =
  CaptchaResponse'
    { $sel:failureReason:CaptchaResponse' :: Maybe FailureReason
failureReason = forall a. Maybe a
Prelude.Nothing,
      $sel:responseCode:CaptchaResponse' :: Maybe Int
responseCode = forall a. Maybe a
Prelude.Nothing,
      $sel:solveTimestamp:CaptchaResponse' :: Maybe Integer
solveTimestamp = forall a. Maybe a
Prelude.Nothing
    }

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

-- | The HTTP response code indicating the status of the @CAPTCHA@ token in
-- the web request. If the token is missing, invalid, or expired, this code
-- is @405 Method Not Allowed@.
captchaResponse_responseCode :: Lens.Lens' CaptchaResponse (Prelude.Maybe Prelude.Int)
captchaResponse_responseCode :: Lens' CaptchaResponse (Maybe Int)
captchaResponse_responseCode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CaptchaResponse' {Maybe Int
responseCode :: Maybe Int
$sel:responseCode:CaptchaResponse' :: CaptchaResponse -> Maybe Int
responseCode} -> Maybe Int
responseCode) (\s :: CaptchaResponse
s@CaptchaResponse' {} Maybe Int
a -> CaptchaResponse
s {$sel:responseCode:CaptchaResponse' :: Maybe Int
responseCode = Maybe Int
a} :: CaptchaResponse)

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

instance Data.FromJSON CaptchaResponse where
  parseJSON :: Value -> Parser CaptchaResponse
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CaptchaResponse"
      ( \Object
x ->
          Maybe FailureReason
-> Maybe Int -> Maybe Integer -> CaptchaResponse
CaptchaResponse'
            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 CaptchaResponse where
  hashWithSalt :: Int -> CaptchaResponse -> Int
hashWithSalt Int
_salt CaptchaResponse' {Maybe Int
Maybe Integer
Maybe FailureReason
solveTimestamp :: Maybe Integer
responseCode :: Maybe Int
failureReason :: Maybe FailureReason
$sel:solveTimestamp:CaptchaResponse' :: CaptchaResponse -> Maybe Integer
$sel:responseCode:CaptchaResponse' :: CaptchaResponse -> Maybe Int
$sel:failureReason:CaptchaResponse' :: CaptchaResponse -> 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 CaptchaResponse where
  rnf :: CaptchaResponse -> ()
rnf CaptchaResponse' {Maybe Int
Maybe Integer
Maybe FailureReason
solveTimestamp :: Maybe Integer
responseCode :: Maybe Int
failureReason :: Maybe FailureReason
$sel:solveTimestamp:CaptchaResponse' :: CaptchaResponse -> Maybe Integer
$sel:responseCode:CaptchaResponse' :: CaptchaResponse -> Maybe Int
$sel:failureReason:CaptchaResponse' :: CaptchaResponse -> 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