{-# 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-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- 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.Lens as Lens
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
(RedactionConfig -> RedactionConfig -> Bool)
-> (RedactionConfig -> RedactionConfig -> Bool)
-> Eq RedactionConfig
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]
(Int -> ReadS RedactionConfig)
-> ReadS [RedactionConfig]
-> ReadPrec RedactionConfig
-> ReadPrec [RedactionConfig]
-> Read 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
(Int -> RedactionConfig -> ShowS)
-> (RedactionConfig -> String)
-> ([RedactionConfig] -> ShowS)
-> Show RedactionConfig
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. RedactionConfig -> Rep RedactionConfig x)
-> (forall x. Rep RedactionConfig x -> RedactionConfig)
-> Generic RedactionConfig
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' :: Maybe Text
-> Maybe PiiEntitiesDetectionMaskMode
-> Maybe [PiiEntityType]
-> RedactionConfig
RedactionConfig'
    { $sel:maskCharacter:RedactionConfig' :: Maybe Text
maskCharacter = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:maskMode:RedactionConfig' :: Maybe PiiEntitiesDetectionMaskMode
maskMode = Maybe PiiEntitiesDetectionMaskMode
forall a. Maybe a
Prelude.Nothing,
      $sel:piiEntityTypes:RedactionConfig' :: Maybe [PiiEntityType]
piiEntityTypes = Maybe [PiiEntityType]
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 :: (Maybe Text -> f (Maybe Text))
-> RedactionConfig -> f RedactionConfig
redactionConfig_maskCharacter = (RedactionConfig -> Maybe Text)
-> (RedactionConfig -> Maybe Text -> RedactionConfig)
-> Lens RedactionConfig RedactionConfig (Maybe Text) (Maybe Text)
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 :: (Maybe PiiEntitiesDetectionMaskMode
 -> f (Maybe PiiEntitiesDetectionMaskMode))
-> RedactionConfig -> f RedactionConfig
redactionConfig_maskMode = (RedactionConfig -> Maybe PiiEntitiesDetectionMaskMode)
-> (RedactionConfig
    -> Maybe PiiEntitiesDetectionMaskMode -> RedactionConfig)
-> Lens
     RedactionConfig
     RedactionConfig
     (Maybe PiiEntitiesDetectionMaskMode)
     (Maybe PiiEntitiesDetectionMaskMode)
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 :: (Maybe [PiiEntityType] -> f (Maybe [PiiEntityType]))
-> RedactionConfig -> f RedactionConfig
redactionConfig_piiEntityTypes = (RedactionConfig -> Maybe [PiiEntityType])
-> (RedactionConfig -> Maybe [PiiEntityType] -> RedactionConfig)
-> Lens
     RedactionConfig
     RedactionConfig
     (Maybe [PiiEntityType])
     (Maybe [PiiEntityType])
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) ((Maybe [PiiEntityType] -> f (Maybe [PiiEntityType]))
 -> RedactionConfig -> f RedactionConfig)
-> ((Maybe [PiiEntityType] -> f (Maybe [PiiEntityType]))
    -> Maybe [PiiEntityType] -> f (Maybe [PiiEntityType]))
-> (Maybe [PiiEntityType] -> f (Maybe [PiiEntityType]))
-> RedactionConfig
-> f RedactionConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [PiiEntityType] [PiiEntityType] [PiiEntityType] [PiiEntityType]
-> Iso
     (Maybe [PiiEntityType])
     (Maybe [PiiEntityType])
     (Maybe [PiiEntityType])
     (Maybe [PiiEntityType])
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 AnIso
  [PiiEntityType] [PiiEntityType] [PiiEntityType] [PiiEntityType]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON RedactionConfig where
  parseJSON :: Value -> Parser RedactionConfig
parseJSON =
    String
-> (Object -> Parser RedactionConfig)
-> Value
-> Parser RedactionConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RedactionConfig"
      ( \Object
x ->
          Maybe Text
-> Maybe PiiEntitiesDetectionMaskMode
-> Maybe [PiiEntityType]
-> RedactionConfig
RedactionConfig'
            (Maybe Text
 -> Maybe PiiEntitiesDetectionMaskMode
 -> Maybe [PiiEntityType]
 -> RedactionConfig)
-> Parser (Maybe Text)
-> Parser
     (Maybe PiiEntitiesDetectionMaskMode
      -> Maybe [PiiEntityType] -> RedactionConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MaskCharacter")
            Parser
  (Maybe PiiEntitiesDetectionMaskMode
   -> Maybe [PiiEntityType] -> RedactionConfig)
-> Parser (Maybe PiiEntitiesDetectionMaskMode)
-> Parser (Maybe [PiiEntityType] -> RedactionConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe PiiEntitiesDetectionMaskMode)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MaskMode")
            Parser (Maybe [PiiEntityType] -> RedactionConfig)
-> Parser (Maybe [PiiEntityType]) -> Parser RedactionConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe [PiiEntityType]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PiiEntityTypes"
                            Parser (Maybe (Maybe [PiiEntityType]))
-> Maybe [PiiEntityType] -> Parser (Maybe [PiiEntityType])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [PiiEntityType]
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable RedactionConfig

instance Prelude.NFData RedactionConfig

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"MaskCharacter" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
maskCharacter,
            (Text
"MaskMode" Text -> PiiEntitiesDetectionMaskMode -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (PiiEntitiesDetectionMaskMode -> Pair)
-> Maybe PiiEntitiesDetectionMaskMode -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe PiiEntitiesDetectionMaskMode
maskMode,
            (Text
"PiiEntityTypes" Text -> [PiiEntityType] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([PiiEntityType] -> Pair) -> Maybe [PiiEntityType] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [PiiEntityType]
piiEntityTypes
          ]
      )