{-# 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.MacieV2.Types.AllowListCriteria
-- 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.MacieV2.Types.AllowListCriteria where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.MacieV2.Types.S3WordsList
import qualified Amazonka.Prelude as Prelude

-- | Specifies the criteria for an allow list. The criteria must specify a
-- regular expression (regex) or an S3 object (s3WordsList). It can\'t
-- specify both.
--
-- /See:/ 'newAllowListCriteria' smart constructor.
data AllowListCriteria = AllowListCriteria'
  { -- | The regular expression (/regex/) that defines the text pattern to
    -- ignore. The expression can contain as many as 512 characters.
    AllowListCriteria -> Maybe Text
regex :: Prelude.Maybe Prelude.Text,
    -- | The location and name of the S3 object that lists specific text to
    -- ignore.
    AllowListCriteria -> Maybe S3WordsList
s3WordsList :: Prelude.Maybe S3WordsList
  }
  deriving (AllowListCriteria -> AllowListCriteria -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AllowListCriteria -> AllowListCriteria -> Bool
$c/= :: AllowListCriteria -> AllowListCriteria -> Bool
== :: AllowListCriteria -> AllowListCriteria -> Bool
$c== :: AllowListCriteria -> AllowListCriteria -> Bool
Prelude.Eq, ReadPrec [AllowListCriteria]
ReadPrec AllowListCriteria
Int -> ReadS AllowListCriteria
ReadS [AllowListCriteria]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AllowListCriteria]
$creadListPrec :: ReadPrec [AllowListCriteria]
readPrec :: ReadPrec AllowListCriteria
$creadPrec :: ReadPrec AllowListCriteria
readList :: ReadS [AllowListCriteria]
$creadList :: ReadS [AllowListCriteria]
readsPrec :: Int -> ReadS AllowListCriteria
$creadsPrec :: Int -> ReadS AllowListCriteria
Prelude.Read, Int -> AllowListCriteria -> ShowS
[AllowListCriteria] -> ShowS
AllowListCriteria -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AllowListCriteria] -> ShowS
$cshowList :: [AllowListCriteria] -> ShowS
show :: AllowListCriteria -> String
$cshow :: AllowListCriteria -> String
showsPrec :: Int -> AllowListCriteria -> ShowS
$cshowsPrec :: Int -> AllowListCriteria -> ShowS
Prelude.Show, forall x. Rep AllowListCriteria x -> AllowListCriteria
forall x. AllowListCriteria -> Rep AllowListCriteria x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AllowListCriteria x -> AllowListCriteria
$cfrom :: forall x. AllowListCriteria -> Rep AllowListCriteria x
Prelude.Generic)

-- |
-- Create a value of 'AllowListCriteria' 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:
--
-- 'regex', 'allowListCriteria_regex' - The regular expression (/regex/) that defines the text pattern to
-- ignore. The expression can contain as many as 512 characters.
--
-- 's3WordsList', 'allowListCriteria_s3WordsList' - The location and name of the S3 object that lists specific text to
-- ignore.
newAllowListCriteria ::
  AllowListCriteria
newAllowListCriteria :: AllowListCriteria
newAllowListCriteria =
  AllowListCriteria'
    { $sel:regex:AllowListCriteria' :: Maybe Text
regex = forall a. Maybe a
Prelude.Nothing,
      $sel:s3WordsList:AllowListCriteria' :: Maybe S3WordsList
s3WordsList = forall a. Maybe a
Prelude.Nothing
    }

-- | The regular expression (/regex/) that defines the text pattern to
-- ignore. The expression can contain as many as 512 characters.
allowListCriteria_regex :: Lens.Lens' AllowListCriteria (Prelude.Maybe Prelude.Text)
allowListCriteria_regex :: Lens' AllowListCriteria (Maybe Text)
allowListCriteria_regex = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllowListCriteria' {Maybe Text
regex :: Maybe Text
$sel:regex:AllowListCriteria' :: AllowListCriteria -> Maybe Text
regex} -> Maybe Text
regex) (\s :: AllowListCriteria
s@AllowListCriteria' {} Maybe Text
a -> AllowListCriteria
s {$sel:regex:AllowListCriteria' :: Maybe Text
regex = Maybe Text
a} :: AllowListCriteria)

-- | The location and name of the S3 object that lists specific text to
-- ignore.
allowListCriteria_s3WordsList :: Lens.Lens' AllowListCriteria (Prelude.Maybe S3WordsList)
allowListCriteria_s3WordsList :: Lens' AllowListCriteria (Maybe S3WordsList)
allowListCriteria_s3WordsList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllowListCriteria' {Maybe S3WordsList
s3WordsList :: Maybe S3WordsList
$sel:s3WordsList:AllowListCriteria' :: AllowListCriteria -> Maybe S3WordsList
s3WordsList} -> Maybe S3WordsList
s3WordsList) (\s :: AllowListCriteria
s@AllowListCriteria' {} Maybe S3WordsList
a -> AllowListCriteria
s {$sel:s3WordsList:AllowListCriteria' :: Maybe S3WordsList
s3WordsList = Maybe S3WordsList
a} :: AllowListCriteria)

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

instance Prelude.Hashable AllowListCriteria where
  hashWithSalt :: Int -> AllowListCriteria -> Int
hashWithSalt Int
_salt AllowListCriteria' {Maybe Text
Maybe S3WordsList
s3WordsList :: Maybe S3WordsList
regex :: Maybe Text
$sel:s3WordsList:AllowListCriteria' :: AllowListCriteria -> Maybe S3WordsList
$sel:regex:AllowListCriteria' :: AllowListCriteria -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
regex
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe S3WordsList
s3WordsList

instance Prelude.NFData AllowListCriteria where
  rnf :: AllowListCriteria -> ()
rnf AllowListCriteria' {Maybe Text
Maybe S3WordsList
s3WordsList :: Maybe S3WordsList
regex :: Maybe Text
$sel:s3WordsList:AllowListCriteria' :: AllowListCriteria -> Maybe S3WordsList
$sel:regex:AllowListCriteria' :: AllowListCriteria -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
regex
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe S3WordsList
s3WordsList

instance Data.ToJSON AllowListCriteria where
  toJSON :: AllowListCriteria -> Value
toJSON AllowListCriteria' {Maybe Text
Maybe S3WordsList
s3WordsList :: Maybe S3WordsList
regex :: Maybe Text
$sel:s3WordsList:AllowListCriteria' :: AllowListCriteria -> Maybe S3WordsList
$sel:regex:AllowListCriteria' :: AllowListCriteria -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"regex" 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 Text
regex,
            (Key
"s3WordsList" 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 S3WordsList
s3WordsList
          ]
      )