{-# 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.VisibilityConfig
-- 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.VisibilityConfig 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

-- | Defines and enables Amazon CloudWatch metrics and web request sample
-- collection.
--
-- /See:/ 'newVisibilityConfig' smart constructor.
data VisibilityConfig = VisibilityConfig'
  { -- | A boolean indicating whether WAF should store a sampling of the web
    -- requests that match the rules. You can view the sampled requests through
    -- the WAF console.
    VisibilityConfig -> Bool
sampledRequestsEnabled :: Prelude.Bool,
    -- | A boolean indicating whether the associated resource sends metrics to
    -- Amazon CloudWatch. For the list of available metrics, see
    -- <https://docs.aws.amazon.com/waf/latest/developerguide/monitoring-cloudwatch.html#waf-metrics WAF Metrics>.
    VisibilityConfig -> Bool
cloudWatchMetricsEnabled :: Prelude.Bool,
    -- | A name of the Amazon CloudWatch metric. The name can contain only the
    -- characters: A-Z, a-z, 0-9, - (hyphen), and _ (underscore). The name can
    -- be from one to 128 characters long. It can\'t contain whitespace or
    -- metric names reserved for WAF, for example @All@ and @Default_Action@.
    VisibilityConfig -> Text
metricName :: Prelude.Text
  }
  deriving (VisibilityConfig -> VisibilityConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VisibilityConfig -> VisibilityConfig -> Bool
$c/= :: VisibilityConfig -> VisibilityConfig -> Bool
== :: VisibilityConfig -> VisibilityConfig -> Bool
$c== :: VisibilityConfig -> VisibilityConfig -> Bool
Prelude.Eq, ReadPrec [VisibilityConfig]
ReadPrec VisibilityConfig
Int -> ReadS VisibilityConfig
ReadS [VisibilityConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [VisibilityConfig]
$creadListPrec :: ReadPrec [VisibilityConfig]
readPrec :: ReadPrec VisibilityConfig
$creadPrec :: ReadPrec VisibilityConfig
readList :: ReadS [VisibilityConfig]
$creadList :: ReadS [VisibilityConfig]
readsPrec :: Int -> ReadS VisibilityConfig
$creadsPrec :: Int -> ReadS VisibilityConfig
Prelude.Read, Int -> VisibilityConfig -> ShowS
[VisibilityConfig] -> ShowS
VisibilityConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VisibilityConfig] -> ShowS
$cshowList :: [VisibilityConfig] -> ShowS
show :: VisibilityConfig -> String
$cshow :: VisibilityConfig -> String
showsPrec :: Int -> VisibilityConfig -> ShowS
$cshowsPrec :: Int -> VisibilityConfig -> ShowS
Prelude.Show, forall x. Rep VisibilityConfig x -> VisibilityConfig
forall x. VisibilityConfig -> Rep VisibilityConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VisibilityConfig x -> VisibilityConfig
$cfrom :: forall x. VisibilityConfig -> Rep VisibilityConfig x
Prelude.Generic)

-- |
-- Create a value of 'VisibilityConfig' 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:
--
-- 'sampledRequestsEnabled', 'visibilityConfig_sampledRequestsEnabled' - A boolean indicating whether WAF should store a sampling of the web
-- requests that match the rules. You can view the sampled requests through
-- the WAF console.
--
-- 'cloudWatchMetricsEnabled', 'visibilityConfig_cloudWatchMetricsEnabled' - A boolean indicating whether the associated resource sends metrics to
-- Amazon CloudWatch. For the list of available metrics, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/monitoring-cloudwatch.html#waf-metrics WAF Metrics>.
--
-- 'metricName', 'visibilityConfig_metricName' - A name of the Amazon CloudWatch metric. The name can contain only the
-- characters: A-Z, a-z, 0-9, - (hyphen), and _ (underscore). The name can
-- be from one to 128 characters long. It can\'t contain whitespace or
-- metric names reserved for WAF, for example @All@ and @Default_Action@.
newVisibilityConfig ::
  -- | 'sampledRequestsEnabled'
  Prelude.Bool ->
  -- | 'cloudWatchMetricsEnabled'
  Prelude.Bool ->
  -- | 'metricName'
  Prelude.Text ->
  VisibilityConfig
newVisibilityConfig :: Bool -> Bool -> Text -> VisibilityConfig
newVisibilityConfig
  Bool
pSampledRequestsEnabled_
  Bool
pCloudWatchMetricsEnabled_
  Text
pMetricName_ =
    VisibilityConfig'
      { $sel:sampledRequestsEnabled:VisibilityConfig' :: Bool
sampledRequestsEnabled =
          Bool
pSampledRequestsEnabled_,
        $sel:cloudWatchMetricsEnabled:VisibilityConfig' :: Bool
cloudWatchMetricsEnabled =
          Bool
pCloudWatchMetricsEnabled_,
        $sel:metricName:VisibilityConfig' :: Text
metricName = Text
pMetricName_
      }

-- | A boolean indicating whether WAF should store a sampling of the web
-- requests that match the rules. You can view the sampled requests through
-- the WAF console.
visibilityConfig_sampledRequestsEnabled :: Lens.Lens' VisibilityConfig Prelude.Bool
visibilityConfig_sampledRequestsEnabled :: Lens' VisibilityConfig Bool
visibilityConfig_sampledRequestsEnabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VisibilityConfig' {Bool
sampledRequestsEnabled :: Bool
$sel:sampledRequestsEnabled:VisibilityConfig' :: VisibilityConfig -> Bool
sampledRequestsEnabled} -> Bool
sampledRequestsEnabled) (\s :: VisibilityConfig
s@VisibilityConfig' {} Bool
a -> VisibilityConfig
s {$sel:sampledRequestsEnabled:VisibilityConfig' :: Bool
sampledRequestsEnabled = Bool
a} :: VisibilityConfig)

-- | A boolean indicating whether the associated resource sends metrics to
-- Amazon CloudWatch. For the list of available metrics, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/monitoring-cloudwatch.html#waf-metrics WAF Metrics>.
visibilityConfig_cloudWatchMetricsEnabled :: Lens.Lens' VisibilityConfig Prelude.Bool
visibilityConfig_cloudWatchMetricsEnabled :: Lens' VisibilityConfig Bool
visibilityConfig_cloudWatchMetricsEnabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VisibilityConfig' {Bool
cloudWatchMetricsEnabled :: Bool
$sel:cloudWatchMetricsEnabled:VisibilityConfig' :: VisibilityConfig -> Bool
cloudWatchMetricsEnabled} -> Bool
cloudWatchMetricsEnabled) (\s :: VisibilityConfig
s@VisibilityConfig' {} Bool
a -> VisibilityConfig
s {$sel:cloudWatchMetricsEnabled:VisibilityConfig' :: Bool
cloudWatchMetricsEnabled = Bool
a} :: VisibilityConfig)

-- | A name of the Amazon CloudWatch metric. The name can contain only the
-- characters: A-Z, a-z, 0-9, - (hyphen), and _ (underscore). The name can
-- be from one to 128 characters long. It can\'t contain whitespace or
-- metric names reserved for WAF, for example @All@ and @Default_Action@.
visibilityConfig_metricName :: Lens.Lens' VisibilityConfig Prelude.Text
visibilityConfig_metricName :: Lens' VisibilityConfig Text
visibilityConfig_metricName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VisibilityConfig' {Text
metricName :: Text
$sel:metricName:VisibilityConfig' :: VisibilityConfig -> Text
metricName} -> Text
metricName) (\s :: VisibilityConfig
s@VisibilityConfig' {} Text
a -> VisibilityConfig
s {$sel:metricName:VisibilityConfig' :: Text
metricName = Text
a} :: VisibilityConfig)

instance Data.FromJSON VisibilityConfig where
  parseJSON :: Value -> Parser VisibilityConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"VisibilityConfig"
      ( \Object
x ->
          Bool -> Bool -> Text -> VisibilityConfig
VisibilityConfig'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"SampledRequestsEnabled")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"CloudWatchMetricsEnabled")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"MetricName")
      )

instance Prelude.Hashable VisibilityConfig where
  hashWithSalt :: Int -> VisibilityConfig -> Int
hashWithSalt Int
_salt VisibilityConfig' {Bool
Text
metricName :: Text
cloudWatchMetricsEnabled :: Bool
sampledRequestsEnabled :: Bool
$sel:metricName:VisibilityConfig' :: VisibilityConfig -> Text
$sel:cloudWatchMetricsEnabled:VisibilityConfig' :: VisibilityConfig -> Bool
$sel:sampledRequestsEnabled:VisibilityConfig' :: VisibilityConfig -> Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Bool
sampledRequestsEnabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Bool
cloudWatchMetricsEnabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
metricName

instance Prelude.NFData VisibilityConfig where
  rnf :: VisibilityConfig -> ()
rnf VisibilityConfig' {Bool
Text
metricName :: Text
cloudWatchMetricsEnabled :: Bool
sampledRequestsEnabled :: Bool
$sel:metricName:VisibilityConfig' :: VisibilityConfig -> Text
$sel:cloudWatchMetricsEnabled:VisibilityConfig' :: VisibilityConfig -> Bool
$sel:sampledRequestsEnabled:VisibilityConfig' :: VisibilityConfig -> Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Bool
sampledRequestsEnabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Bool
cloudWatchMetricsEnabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
metricName

instance Data.ToJSON VisibilityConfig where
  toJSON :: VisibilityConfig -> Value
toJSON VisibilityConfig' {Bool
Text
metricName :: Text
cloudWatchMetricsEnabled :: Bool
sampledRequestsEnabled :: Bool
$sel:metricName:VisibilityConfig' :: VisibilityConfig -> Text
$sel:cloudWatchMetricsEnabled:VisibilityConfig' :: VisibilityConfig -> Bool
$sel:sampledRequestsEnabled:VisibilityConfig' :: VisibilityConfig -> Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              ( Key
"SampledRequestsEnabled"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Bool
sampledRequestsEnabled
              ),
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"CloudWatchMetricsEnabled"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Bool
cloudWatchMetricsEnabled
              ),
            forall a. a -> Maybe a
Prelude.Just (Key
"MetricName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
metricName)
          ]
      )