{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.DetectPiiEntities
-- 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)
--
-- Inspects the input text for entities that contain personally
-- identifiable information (PII) and returns information about them.
module Amazonka.Comprehend.DetectPiiEntities
  ( -- * Creating a Request
    DetectPiiEntities (..),
    newDetectPiiEntities,

    -- * Request Lenses
    detectPiiEntities_text,
    detectPiiEntities_languageCode,

    -- * Destructuring the Response
    DetectPiiEntitiesResponse (..),
    newDetectPiiEntitiesResponse,

    -- * Response Lenses
    detectPiiEntitiesResponse_entities,
    detectPiiEntitiesResponse_httpStatus,
  )
where

import Amazonka.Comprehend.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newDetectPiiEntities' smart constructor.
data DetectPiiEntities = DetectPiiEntities'
  { -- | A UTF-8 text string. Each string must contain fewer that 5,000 bytes of
    -- UTF-8 encoded characters.
    DetectPiiEntities -> Text
text :: Prelude.Text,
    -- | The language of the input documents.
    DetectPiiEntities -> LanguageCode
languageCode :: LanguageCode
  }
  deriving (DetectPiiEntities -> DetectPiiEntities -> Bool
(DetectPiiEntities -> DetectPiiEntities -> Bool)
-> (DetectPiiEntities -> DetectPiiEntities -> Bool)
-> Eq DetectPiiEntities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetectPiiEntities -> DetectPiiEntities -> Bool
$c/= :: DetectPiiEntities -> DetectPiiEntities -> Bool
== :: DetectPiiEntities -> DetectPiiEntities -> Bool
$c== :: DetectPiiEntities -> DetectPiiEntities -> Bool
Prelude.Eq, ReadPrec [DetectPiiEntities]
ReadPrec DetectPiiEntities
Int -> ReadS DetectPiiEntities
ReadS [DetectPiiEntities]
(Int -> ReadS DetectPiiEntities)
-> ReadS [DetectPiiEntities]
-> ReadPrec DetectPiiEntities
-> ReadPrec [DetectPiiEntities]
-> Read DetectPiiEntities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetectPiiEntities]
$creadListPrec :: ReadPrec [DetectPiiEntities]
readPrec :: ReadPrec DetectPiiEntities
$creadPrec :: ReadPrec DetectPiiEntities
readList :: ReadS [DetectPiiEntities]
$creadList :: ReadS [DetectPiiEntities]
readsPrec :: Int -> ReadS DetectPiiEntities
$creadsPrec :: Int -> ReadS DetectPiiEntities
Prelude.Read, Int -> DetectPiiEntities -> ShowS
[DetectPiiEntities] -> ShowS
DetectPiiEntities -> String
(Int -> DetectPiiEntities -> ShowS)
-> (DetectPiiEntities -> String)
-> ([DetectPiiEntities] -> ShowS)
-> Show DetectPiiEntities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetectPiiEntities] -> ShowS
$cshowList :: [DetectPiiEntities] -> ShowS
show :: DetectPiiEntities -> String
$cshow :: DetectPiiEntities -> String
showsPrec :: Int -> DetectPiiEntities -> ShowS
$cshowsPrec :: Int -> DetectPiiEntities -> ShowS
Prelude.Show, (forall x. DetectPiiEntities -> Rep DetectPiiEntities x)
-> (forall x. Rep DetectPiiEntities x -> DetectPiiEntities)
-> Generic DetectPiiEntities
forall x. Rep DetectPiiEntities x -> DetectPiiEntities
forall x. DetectPiiEntities -> Rep DetectPiiEntities x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetectPiiEntities x -> DetectPiiEntities
$cfrom :: forall x. DetectPiiEntities -> Rep DetectPiiEntities x
Prelude.Generic)

-- |
-- Create a value of 'DetectPiiEntities' 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:
--
-- 'text', 'detectPiiEntities_text' - A UTF-8 text string. Each string must contain fewer that 5,000 bytes of
-- UTF-8 encoded characters.
--
-- 'languageCode', 'detectPiiEntities_languageCode' - The language of the input documents.
newDetectPiiEntities ::
  -- | 'text'
  Prelude.Text ->
  -- | 'languageCode'
  LanguageCode ->
  DetectPiiEntities
newDetectPiiEntities :: Text -> LanguageCode -> DetectPiiEntities
newDetectPiiEntities Text
pText_ LanguageCode
pLanguageCode_ =
  DetectPiiEntities' :: Text -> LanguageCode -> DetectPiiEntities
DetectPiiEntities'
    { $sel:text:DetectPiiEntities' :: Text
text = Text
pText_,
      $sel:languageCode:DetectPiiEntities' :: LanguageCode
languageCode = LanguageCode
pLanguageCode_
    }

-- | A UTF-8 text string. Each string must contain fewer that 5,000 bytes of
-- UTF-8 encoded characters.
detectPiiEntities_text :: Lens.Lens' DetectPiiEntities Prelude.Text
detectPiiEntities_text :: (Text -> f Text) -> DetectPiiEntities -> f DetectPiiEntities
detectPiiEntities_text = (DetectPiiEntities -> Text)
-> (DetectPiiEntities -> Text -> DetectPiiEntities)
-> Lens DetectPiiEntities DetectPiiEntities Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectPiiEntities' {Text
text :: Text
$sel:text:DetectPiiEntities' :: DetectPiiEntities -> Text
text} -> Text
text) (\s :: DetectPiiEntities
s@DetectPiiEntities' {} Text
a -> DetectPiiEntities
s {$sel:text:DetectPiiEntities' :: Text
text = Text
a} :: DetectPiiEntities)

-- | The language of the input documents.
detectPiiEntities_languageCode :: Lens.Lens' DetectPiiEntities LanguageCode
detectPiiEntities_languageCode :: (LanguageCode -> f LanguageCode)
-> DetectPiiEntities -> f DetectPiiEntities
detectPiiEntities_languageCode = (DetectPiiEntities -> LanguageCode)
-> (DetectPiiEntities -> LanguageCode -> DetectPiiEntities)
-> Lens
     DetectPiiEntities DetectPiiEntities LanguageCode LanguageCode
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectPiiEntities' {LanguageCode
languageCode :: LanguageCode
$sel:languageCode:DetectPiiEntities' :: DetectPiiEntities -> LanguageCode
languageCode} -> LanguageCode
languageCode) (\s :: DetectPiiEntities
s@DetectPiiEntities' {} LanguageCode
a -> DetectPiiEntities
s {$sel:languageCode:DetectPiiEntities' :: LanguageCode
languageCode = LanguageCode
a} :: DetectPiiEntities)

instance Core.AWSRequest DetectPiiEntities where
  type
    AWSResponse DetectPiiEntities =
      DetectPiiEntitiesResponse
  request :: DetectPiiEntities -> Request DetectPiiEntities
request = Service -> DetectPiiEntities -> Request DetectPiiEntities
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DetectPiiEntities
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DetectPiiEntities)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DetectPiiEntities))
-> Logger
-> Service
-> Proxy DetectPiiEntities
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DetectPiiEntities)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [PiiEntity] -> Int -> DetectPiiEntitiesResponse
DetectPiiEntitiesResponse'
            (Maybe [PiiEntity] -> Int -> DetectPiiEntitiesResponse)
-> Either String (Maybe [PiiEntity])
-> Either String (Int -> DetectPiiEntitiesResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [PiiEntity]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Entities" Either String (Maybe (Maybe [PiiEntity]))
-> Maybe [PiiEntity] -> Either String (Maybe [PiiEntity])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [PiiEntity]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> DetectPiiEntitiesResponse)
-> Either String Int -> Either String DetectPiiEntitiesResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable DetectPiiEntities

instance Prelude.NFData DetectPiiEntities

instance Core.ToHeaders DetectPiiEntities where
  toHeaders :: DetectPiiEntities -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DetectPiiEntities -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"Comprehend_20171127.DetectPiiEntities" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON DetectPiiEntities where
  toJSON :: DetectPiiEntities -> Value
toJSON DetectPiiEntities' {Text
LanguageCode
languageCode :: LanguageCode
text :: Text
$sel:languageCode:DetectPiiEntities' :: DetectPiiEntities -> LanguageCode
$sel:text:DetectPiiEntities' :: DetectPiiEntities -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Text" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
text),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"LanguageCode" Text -> LanguageCode -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= LanguageCode
languageCode)
          ]
      )

instance Core.ToPath DetectPiiEntities where
  toPath :: DetectPiiEntities -> ByteString
toPath = ByteString -> DetectPiiEntities -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery DetectPiiEntities where
  toQuery :: DetectPiiEntities -> QueryString
toQuery = QueryString -> DetectPiiEntities -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newDetectPiiEntitiesResponse' smart constructor.
data DetectPiiEntitiesResponse = DetectPiiEntitiesResponse'
  { -- | A collection of PII entities identified in the input text. For each
    -- entity, the response provides the entity type, where the entity text
    -- begins and ends, and the level of confidence that Amazon Comprehend has
    -- in the detection.
    DetectPiiEntitiesResponse -> Maybe [PiiEntity]
entities :: Prelude.Maybe [PiiEntity],
    -- | The response's http status code.
    DetectPiiEntitiesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DetectPiiEntitiesResponse -> DetectPiiEntitiesResponse -> Bool
(DetectPiiEntitiesResponse -> DetectPiiEntitiesResponse -> Bool)
-> (DetectPiiEntitiesResponse -> DetectPiiEntitiesResponse -> Bool)
-> Eq DetectPiiEntitiesResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetectPiiEntitiesResponse -> DetectPiiEntitiesResponse -> Bool
$c/= :: DetectPiiEntitiesResponse -> DetectPiiEntitiesResponse -> Bool
== :: DetectPiiEntitiesResponse -> DetectPiiEntitiesResponse -> Bool
$c== :: DetectPiiEntitiesResponse -> DetectPiiEntitiesResponse -> Bool
Prelude.Eq, ReadPrec [DetectPiiEntitiesResponse]
ReadPrec DetectPiiEntitiesResponse
Int -> ReadS DetectPiiEntitiesResponse
ReadS [DetectPiiEntitiesResponse]
(Int -> ReadS DetectPiiEntitiesResponse)
-> ReadS [DetectPiiEntitiesResponse]
-> ReadPrec DetectPiiEntitiesResponse
-> ReadPrec [DetectPiiEntitiesResponse]
-> Read DetectPiiEntitiesResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetectPiiEntitiesResponse]
$creadListPrec :: ReadPrec [DetectPiiEntitiesResponse]
readPrec :: ReadPrec DetectPiiEntitiesResponse
$creadPrec :: ReadPrec DetectPiiEntitiesResponse
readList :: ReadS [DetectPiiEntitiesResponse]
$creadList :: ReadS [DetectPiiEntitiesResponse]
readsPrec :: Int -> ReadS DetectPiiEntitiesResponse
$creadsPrec :: Int -> ReadS DetectPiiEntitiesResponse
Prelude.Read, Int -> DetectPiiEntitiesResponse -> ShowS
[DetectPiiEntitiesResponse] -> ShowS
DetectPiiEntitiesResponse -> String
(Int -> DetectPiiEntitiesResponse -> ShowS)
-> (DetectPiiEntitiesResponse -> String)
-> ([DetectPiiEntitiesResponse] -> ShowS)
-> Show DetectPiiEntitiesResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetectPiiEntitiesResponse] -> ShowS
$cshowList :: [DetectPiiEntitiesResponse] -> ShowS
show :: DetectPiiEntitiesResponse -> String
$cshow :: DetectPiiEntitiesResponse -> String
showsPrec :: Int -> DetectPiiEntitiesResponse -> ShowS
$cshowsPrec :: Int -> DetectPiiEntitiesResponse -> ShowS
Prelude.Show, (forall x.
 DetectPiiEntitiesResponse -> Rep DetectPiiEntitiesResponse x)
-> (forall x.
    Rep DetectPiiEntitiesResponse x -> DetectPiiEntitiesResponse)
-> Generic DetectPiiEntitiesResponse
forall x.
Rep DetectPiiEntitiesResponse x -> DetectPiiEntitiesResponse
forall x.
DetectPiiEntitiesResponse -> Rep DetectPiiEntitiesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DetectPiiEntitiesResponse x -> DetectPiiEntitiesResponse
$cfrom :: forall x.
DetectPiiEntitiesResponse -> Rep DetectPiiEntitiesResponse x
Prelude.Generic)

-- |
-- Create a value of 'DetectPiiEntitiesResponse' 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:
--
-- 'entities', 'detectPiiEntitiesResponse_entities' - A collection of PII entities identified in the input text. For each
-- entity, the response provides the entity type, where the entity text
-- begins and ends, and the level of confidence that Amazon Comprehend has
-- in the detection.
--
-- 'httpStatus', 'detectPiiEntitiesResponse_httpStatus' - The response's http status code.
newDetectPiiEntitiesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DetectPiiEntitiesResponse
newDetectPiiEntitiesResponse :: Int -> DetectPiiEntitiesResponse
newDetectPiiEntitiesResponse Int
pHttpStatus_ =
  DetectPiiEntitiesResponse' :: Maybe [PiiEntity] -> Int -> DetectPiiEntitiesResponse
DetectPiiEntitiesResponse'
    { $sel:entities:DetectPiiEntitiesResponse' :: Maybe [PiiEntity]
entities =
        Maybe [PiiEntity]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DetectPiiEntitiesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A collection of PII entities identified in the input text. For each
-- entity, the response provides the entity type, where the entity text
-- begins and ends, and the level of confidence that Amazon Comprehend has
-- in the detection.
detectPiiEntitiesResponse_entities :: Lens.Lens' DetectPiiEntitiesResponse (Prelude.Maybe [PiiEntity])
detectPiiEntitiesResponse_entities :: (Maybe [PiiEntity] -> f (Maybe [PiiEntity]))
-> DetectPiiEntitiesResponse -> f DetectPiiEntitiesResponse
detectPiiEntitiesResponse_entities = (DetectPiiEntitiesResponse -> Maybe [PiiEntity])
-> (DetectPiiEntitiesResponse
    -> Maybe [PiiEntity] -> DetectPiiEntitiesResponse)
-> Lens
     DetectPiiEntitiesResponse
     DetectPiiEntitiesResponse
     (Maybe [PiiEntity])
     (Maybe [PiiEntity])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectPiiEntitiesResponse' {Maybe [PiiEntity]
entities :: Maybe [PiiEntity]
$sel:entities:DetectPiiEntitiesResponse' :: DetectPiiEntitiesResponse -> Maybe [PiiEntity]
entities} -> Maybe [PiiEntity]
entities) (\s :: DetectPiiEntitiesResponse
s@DetectPiiEntitiesResponse' {} Maybe [PiiEntity]
a -> DetectPiiEntitiesResponse
s {$sel:entities:DetectPiiEntitiesResponse' :: Maybe [PiiEntity]
entities = Maybe [PiiEntity]
a} :: DetectPiiEntitiesResponse) ((Maybe [PiiEntity] -> f (Maybe [PiiEntity]))
 -> DetectPiiEntitiesResponse -> f DetectPiiEntitiesResponse)
-> ((Maybe [PiiEntity] -> f (Maybe [PiiEntity]))
    -> Maybe [PiiEntity] -> f (Maybe [PiiEntity]))
-> (Maybe [PiiEntity] -> f (Maybe [PiiEntity]))
-> DetectPiiEntitiesResponse
-> f DetectPiiEntitiesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [PiiEntity] [PiiEntity] [PiiEntity] [PiiEntity]
-> Iso
     (Maybe [PiiEntity])
     (Maybe [PiiEntity])
     (Maybe [PiiEntity])
     (Maybe [PiiEntity])
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 [PiiEntity] [PiiEntity] [PiiEntity] [PiiEntity]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The response's http status code.
detectPiiEntitiesResponse_httpStatus :: Lens.Lens' DetectPiiEntitiesResponse Prelude.Int
detectPiiEntitiesResponse_httpStatus :: (Int -> f Int)
-> DetectPiiEntitiesResponse -> f DetectPiiEntitiesResponse
detectPiiEntitiesResponse_httpStatus = (DetectPiiEntitiesResponse -> Int)
-> (DetectPiiEntitiesResponse -> Int -> DetectPiiEntitiesResponse)
-> Lens DetectPiiEntitiesResponse DetectPiiEntitiesResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectPiiEntitiesResponse' {Int
httpStatus :: Int
$sel:httpStatus:DetectPiiEntitiesResponse' :: DetectPiiEntitiesResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: DetectPiiEntitiesResponse
s@DetectPiiEntitiesResponse' {} Int
a -> DetectPiiEntitiesResponse
s {$sel:httpStatus:DetectPiiEntitiesResponse' :: Int
httpStatus = Int
a} :: DetectPiiEntitiesResponse)

instance Prelude.NFData DetectPiiEntitiesResponse