{-# 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.Comprehend.Types.RedactionConfig
-- 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.Comprehend.Types.RedactionConfig where

import Amazonka.Comprehend.Types.PiiEntitiesDetectionMaskMode
import Amazonka.Comprehend.Types.PiiEntityType
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

-- | Provides configuration parameters for PII entity redaction.
--
-- /See:/ 'newRedactionConfig' smart constructor.
data RedactionConfig = RedactionConfig'
  { -- | A character that replaces each character in the redacted PII entity.
    RedactionConfig -> Maybe Text
maskCharacter :: Prelude.Maybe Prelude.Text,
    -- | Specifies whether the PII entity is redacted with the mask character or
    -- the entity type.
    RedactionConfig -> Maybe PiiEntitiesDetectionMaskMode
maskMode :: Prelude.Maybe PiiEntitiesDetectionMaskMode,
    -- | An array of the types of PII entities that Amazon Comprehend detects in
    -- the input text for your request.
    RedactionConfig -> Maybe [PiiEntityType]
piiEntityTypes :: Prelude.Maybe [PiiEntityType]
  }
  deriving (RedactionConfig -> RedactionConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RedactionConfig -> RedactionConfig -> Bool
$c/= :: RedactionConfig -> RedactionConfig -> Bool
== :: RedactionConfig -> RedactionConfig -> Bool
$c== :: RedactionConfig -> RedactionConfig -> Bool
Prelude.Eq, ReadPrec [RedactionConfig]
ReadPrec RedactionConfig
Int -> ReadS RedactionConfig
ReadS [RedactionConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RedactionConfig]
$creadListPrec :: ReadPrec [RedactionConfig]
readPrec :: ReadPrec RedactionConfig
$creadPrec :: ReadPrec RedactionConfig
readList :: ReadS [RedactionConfig]
$creadList :: ReadS [RedactionConfig]
readsPrec :: Int -> ReadS RedactionConfig
$creadsPrec :: Int -> ReadS RedactionConfig
Prelude.Read, Int -> RedactionConfig -> ShowS
[RedactionConfig] -> ShowS
RedactionConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RedactionConfig] -> ShowS
$cshowList :: [RedactionConfig] -> ShowS
show :: RedactionConfig -> String
$cshow :: RedactionConfig -> String
showsPrec :: Int -> RedactionConfig -> ShowS
$cshowsPrec :: Int -> RedactionConfig -> ShowS
Prelude.Show, forall x. Rep RedactionConfig x -> RedactionConfig
forall x. RedactionConfig -> Rep RedactionConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RedactionConfig x -> RedactionConfig
$cfrom :: forall x. RedactionConfig -> Rep RedactionConfig x
Prelude.Generic)

-- |
-- Create a value of 'RedactionConfig' 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:
--
-- 'maskCharacter', 'redactionConfig_maskCharacter' - A character that replaces each character in the redacted PII entity.
--
-- 'maskMode', 'redactionConfig_maskMode' - Specifies whether the PII entity is redacted with the mask character or
-- the entity type.
--
-- 'piiEntityTypes', 'redactionConfig_piiEntityTypes' - An array of the types of PII entities that Amazon Comprehend detects in
-- the input text for your request.
newRedactionConfig ::
  RedactionConfig
newRedactionConfig :: RedactionConfig
newRedactionConfig =
  RedactionConfig'
    { $sel:maskCharacter:RedactionConfig' :: Maybe Text
maskCharacter = forall a. Maybe a
Prelude.Nothing,
      $sel:maskMode:RedactionConfig' :: Maybe PiiEntitiesDetectionMaskMode
maskMode = forall a. Maybe a
Prelude.Nothing,
      $sel:piiEntityTypes:RedactionConfig' :: Maybe [PiiEntityType]
piiEntityTypes = forall a. Maybe a
Prelude.Nothing
    }

-- | A character that replaces each character in the redacted PII entity.
redactionConfig_maskCharacter :: Lens.Lens' RedactionConfig (Prelude.Maybe Prelude.Text)
redactionConfig_maskCharacter :: Lens' RedactionConfig (Maybe Text)
redactionConfig_maskCharacter = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedactionConfig' {Maybe Text
maskCharacter :: Maybe Text
$sel:maskCharacter:RedactionConfig' :: RedactionConfig -> Maybe Text
maskCharacter} -> Maybe Text
maskCharacter) (\s :: RedactionConfig
s@RedactionConfig' {} Maybe Text
a -> RedactionConfig
s {$sel:maskCharacter:RedactionConfig' :: Maybe Text
maskCharacter = Maybe Text
a} :: RedactionConfig)

-- | Specifies whether the PII entity is redacted with the mask character or
-- the entity type.
redactionConfig_maskMode :: Lens.Lens' RedactionConfig (Prelude.Maybe PiiEntitiesDetectionMaskMode)
redactionConfig_maskMode :: Lens' RedactionConfig (Maybe PiiEntitiesDetectionMaskMode)
redactionConfig_maskMode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedactionConfig' {Maybe PiiEntitiesDetectionMaskMode
maskMode :: Maybe PiiEntitiesDetectionMaskMode
$sel:maskMode:RedactionConfig' :: RedactionConfig -> Maybe PiiEntitiesDetectionMaskMode
maskMode} -> Maybe PiiEntitiesDetectionMaskMode
maskMode) (\s :: RedactionConfig
s@RedactionConfig' {} Maybe PiiEntitiesDetectionMaskMode
a -> RedactionConfig
s {$sel:maskMode:RedactionConfig' :: Maybe PiiEntitiesDetectionMaskMode
maskMode = Maybe PiiEntitiesDetectionMaskMode
a} :: RedactionConfig)

-- | An array of the types of PII entities that Amazon Comprehend detects in
-- the input text for your request.
redactionConfig_piiEntityTypes :: Lens.Lens' RedactionConfig (Prelude.Maybe [PiiEntityType])
redactionConfig_piiEntityTypes :: Lens' RedactionConfig (Maybe [PiiEntityType])
redactionConfig_piiEntityTypes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedactionConfig' {Maybe [PiiEntityType]
piiEntityTypes :: Maybe [PiiEntityType]
$sel:piiEntityTypes:RedactionConfig' :: RedactionConfig -> Maybe [PiiEntityType]
piiEntityTypes} -> Maybe [PiiEntityType]
piiEntityTypes) (\s :: RedactionConfig
s@RedactionConfig' {} Maybe [PiiEntityType]
a -> RedactionConfig
s {$sel:piiEntityTypes:RedactionConfig' :: Maybe [PiiEntityType]
piiEntityTypes = Maybe [PiiEntityType]
a} :: RedactionConfig) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON RedactionConfig where
  parseJSON :: Value -> Parser RedactionConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RedactionConfig"
      ( \Object
x ->
          Maybe Text
-> Maybe PiiEntitiesDetectionMaskMode
-> Maybe [PiiEntityType]
-> RedactionConfig
RedactionConfig'
            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
"MaskCharacter")
            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
"MaskMode")
            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
"PiiEntityTypes"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable RedactionConfig where
  hashWithSalt :: Int -> RedactionConfig -> Int
hashWithSalt Int
_salt RedactionConfig' {Maybe [PiiEntityType]
Maybe Text
Maybe PiiEntitiesDetectionMaskMode
piiEntityTypes :: Maybe [PiiEntityType]
maskMode :: Maybe PiiEntitiesDetectionMaskMode
maskCharacter :: Maybe Text
$sel:piiEntityTypes:RedactionConfig' :: RedactionConfig -> Maybe [PiiEntityType]
$sel:maskMode:RedactionConfig' :: RedactionConfig -> Maybe PiiEntitiesDetectionMaskMode
$sel:maskCharacter:RedactionConfig' :: RedactionConfig -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
maskCharacter
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe PiiEntitiesDetectionMaskMode
maskMode
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [PiiEntityType]
piiEntityTypes

instance Prelude.NFData RedactionConfig where
  rnf :: RedactionConfig -> ()
rnf RedactionConfig' {Maybe [PiiEntityType]
Maybe Text
Maybe PiiEntitiesDetectionMaskMode
piiEntityTypes :: Maybe [PiiEntityType]
maskMode :: Maybe PiiEntitiesDetectionMaskMode
maskCharacter :: Maybe Text
$sel:piiEntityTypes:RedactionConfig' :: RedactionConfig -> Maybe [PiiEntityType]
$sel:maskMode:RedactionConfig' :: RedactionConfig -> Maybe PiiEntitiesDetectionMaskMode
$sel:maskCharacter:RedactionConfig' :: RedactionConfig -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
maskCharacter
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe PiiEntitiesDetectionMaskMode
maskMode
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [PiiEntityType]
piiEntityTypes

instance Data.ToJSON RedactionConfig where
  toJSON :: RedactionConfig -> Value
toJSON RedactionConfig' {Maybe [PiiEntityType]
Maybe Text
Maybe PiiEntitiesDetectionMaskMode
piiEntityTypes :: Maybe [PiiEntityType]
maskMode :: Maybe PiiEntitiesDetectionMaskMode
maskCharacter :: Maybe Text
$sel:piiEntityTypes:RedactionConfig' :: RedactionConfig -> Maybe [PiiEntityType]
$sel:maskMode:RedactionConfig' :: RedactionConfig -> Maybe PiiEntitiesDetectionMaskMode
$sel:maskCharacter:RedactionConfig' :: RedactionConfig -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"MaskCharacter" 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
maskCharacter,
            (Key
"MaskMode" 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 PiiEntitiesDetectionMaskMode
maskMode,
            (Key
"PiiEntityTypes" 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 [PiiEntityType]
piiEntityTypes
          ]
      )