{-# 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.ContainsPiiEntities
-- 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)
--
-- Analyzes input text for the presence of personally identifiable
-- information (PII) and returns the labels of identified PII entity types
-- such as name, address, bank account number, or phone number.
module Amazonka.Comprehend.ContainsPiiEntities
  ( -- * Creating a Request
    ContainsPiiEntities (..),
    newContainsPiiEntities,

    -- * Request Lenses
    containsPiiEntities_text,
    containsPiiEntities_languageCode,

    -- * Destructuring the Response
    ContainsPiiEntitiesResponse (..),
    newContainsPiiEntitiesResponse,

    -- * Response Lenses
    containsPiiEntitiesResponse_labels,
    containsPiiEntitiesResponse_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:/ 'newContainsPiiEntities' smart constructor.
data ContainsPiiEntities = ContainsPiiEntities'
  { -- | Creates a new document classification request to analyze a single
    -- document in real-time, returning personally identifiable information
    -- (PII) entity labels.
    ContainsPiiEntities -> Text
text :: Prelude.Text,
    -- | The language of the input documents.
    ContainsPiiEntities -> LanguageCode
languageCode :: LanguageCode
  }
  deriving (ContainsPiiEntities -> ContainsPiiEntities -> Bool
(ContainsPiiEntities -> ContainsPiiEntities -> Bool)
-> (ContainsPiiEntities -> ContainsPiiEntities -> Bool)
-> Eq ContainsPiiEntities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ContainsPiiEntities -> ContainsPiiEntities -> Bool
$c/= :: ContainsPiiEntities -> ContainsPiiEntities -> Bool
== :: ContainsPiiEntities -> ContainsPiiEntities -> Bool
$c== :: ContainsPiiEntities -> ContainsPiiEntities -> Bool
Prelude.Eq, ReadPrec [ContainsPiiEntities]
ReadPrec ContainsPiiEntities
Int -> ReadS ContainsPiiEntities
ReadS [ContainsPiiEntities]
(Int -> ReadS ContainsPiiEntities)
-> ReadS [ContainsPiiEntities]
-> ReadPrec ContainsPiiEntities
-> ReadPrec [ContainsPiiEntities]
-> Read ContainsPiiEntities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ContainsPiiEntities]
$creadListPrec :: ReadPrec [ContainsPiiEntities]
readPrec :: ReadPrec ContainsPiiEntities
$creadPrec :: ReadPrec ContainsPiiEntities
readList :: ReadS [ContainsPiiEntities]
$creadList :: ReadS [ContainsPiiEntities]
readsPrec :: Int -> ReadS ContainsPiiEntities
$creadsPrec :: Int -> ReadS ContainsPiiEntities
Prelude.Read, Int -> ContainsPiiEntities -> ShowS
[ContainsPiiEntities] -> ShowS
ContainsPiiEntities -> String
(Int -> ContainsPiiEntities -> ShowS)
-> (ContainsPiiEntities -> String)
-> ([ContainsPiiEntities] -> ShowS)
-> Show ContainsPiiEntities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ContainsPiiEntities] -> ShowS
$cshowList :: [ContainsPiiEntities] -> ShowS
show :: ContainsPiiEntities -> String
$cshow :: ContainsPiiEntities -> String
showsPrec :: Int -> ContainsPiiEntities -> ShowS
$cshowsPrec :: Int -> ContainsPiiEntities -> ShowS
Prelude.Show, (forall x. ContainsPiiEntities -> Rep ContainsPiiEntities x)
-> (forall x. Rep ContainsPiiEntities x -> ContainsPiiEntities)
-> Generic ContainsPiiEntities
forall x. Rep ContainsPiiEntities x -> ContainsPiiEntities
forall x. ContainsPiiEntities -> Rep ContainsPiiEntities x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ContainsPiiEntities x -> ContainsPiiEntities
$cfrom :: forall x. ContainsPiiEntities -> Rep ContainsPiiEntities x
Prelude.Generic)

-- |
-- Create a value of 'ContainsPiiEntities' 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', 'containsPiiEntities_text' - Creates a new document classification request to analyze a single
-- document in real-time, returning personally identifiable information
-- (PII) entity labels.
--
-- 'languageCode', 'containsPiiEntities_languageCode' - The language of the input documents.
newContainsPiiEntities ::
  -- | 'text'
  Prelude.Text ->
  -- | 'languageCode'
  LanguageCode ->
  ContainsPiiEntities
newContainsPiiEntities :: Text -> LanguageCode -> ContainsPiiEntities
newContainsPiiEntities Text
pText_ LanguageCode
pLanguageCode_ =
  ContainsPiiEntities' :: Text -> LanguageCode -> ContainsPiiEntities
ContainsPiiEntities'
    { $sel:text:ContainsPiiEntities' :: Text
text = Text
pText_,
      $sel:languageCode:ContainsPiiEntities' :: LanguageCode
languageCode = LanguageCode
pLanguageCode_
    }

-- | Creates a new document classification request to analyze a single
-- document in real-time, returning personally identifiable information
-- (PII) entity labels.
containsPiiEntities_text :: Lens.Lens' ContainsPiiEntities Prelude.Text
containsPiiEntities_text :: (Text -> f Text) -> ContainsPiiEntities -> f ContainsPiiEntities
containsPiiEntities_text = (ContainsPiiEntities -> Text)
-> (ContainsPiiEntities -> Text -> ContainsPiiEntities)
-> Lens ContainsPiiEntities ContainsPiiEntities Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ContainsPiiEntities' {Text
text :: Text
$sel:text:ContainsPiiEntities' :: ContainsPiiEntities -> Text
text} -> Text
text) (\s :: ContainsPiiEntities
s@ContainsPiiEntities' {} Text
a -> ContainsPiiEntities
s {$sel:text:ContainsPiiEntities' :: Text
text = Text
a} :: ContainsPiiEntities)

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

instance Core.AWSRequest ContainsPiiEntities where
  type
    AWSResponse ContainsPiiEntities =
      ContainsPiiEntitiesResponse
  request :: ContainsPiiEntities -> Request ContainsPiiEntities
request = Service -> ContainsPiiEntities -> Request ContainsPiiEntities
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ContainsPiiEntities
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ContainsPiiEntities)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ContainsPiiEntities))
-> Logger
-> Service
-> Proxy ContainsPiiEntities
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ContainsPiiEntities)))
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 [EntityLabel] -> Int -> ContainsPiiEntitiesResponse
ContainsPiiEntitiesResponse'
            (Maybe [EntityLabel] -> Int -> ContainsPiiEntitiesResponse)
-> Either String (Maybe [EntityLabel])
-> Either String (Int -> ContainsPiiEntitiesResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [EntityLabel]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Labels" Either String (Maybe (Maybe [EntityLabel]))
-> Maybe [EntityLabel] -> Either String (Maybe [EntityLabel])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [EntityLabel]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> ContainsPiiEntitiesResponse)
-> Either String Int -> Either String ContainsPiiEntitiesResponse
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 ContainsPiiEntities

instance Prelude.NFData ContainsPiiEntities

instance Core.ToHeaders ContainsPiiEntities where
  toHeaders :: ContainsPiiEntities -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ContainsPiiEntities -> 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.ContainsPiiEntities" ::
                          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 ContainsPiiEntities where
  toJSON :: ContainsPiiEntities -> Value
toJSON ContainsPiiEntities' {Text
LanguageCode
languageCode :: LanguageCode
text :: Text
$sel:languageCode:ContainsPiiEntities' :: ContainsPiiEntities -> LanguageCode
$sel:text:ContainsPiiEntities' :: ContainsPiiEntities -> 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 ContainsPiiEntities where
  toPath :: ContainsPiiEntities -> ByteString
toPath = ByteString -> ContainsPiiEntities -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newContainsPiiEntitiesResponse' smart constructor.
data ContainsPiiEntitiesResponse = ContainsPiiEntitiesResponse'
  { -- | The labels used in the document being analyzed. Individual labels
    -- represent personally identifiable information (PII) entity types.
    ContainsPiiEntitiesResponse -> Maybe [EntityLabel]
labels :: Prelude.Maybe [EntityLabel],
    -- | The response's http status code.
    ContainsPiiEntitiesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ContainsPiiEntitiesResponse -> ContainsPiiEntitiesResponse -> Bool
(ContainsPiiEntitiesResponse
 -> ContainsPiiEntitiesResponse -> Bool)
-> (ContainsPiiEntitiesResponse
    -> ContainsPiiEntitiesResponse -> Bool)
-> Eq ContainsPiiEntitiesResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ContainsPiiEntitiesResponse -> ContainsPiiEntitiesResponse -> Bool
$c/= :: ContainsPiiEntitiesResponse -> ContainsPiiEntitiesResponse -> Bool
== :: ContainsPiiEntitiesResponse -> ContainsPiiEntitiesResponse -> Bool
$c== :: ContainsPiiEntitiesResponse -> ContainsPiiEntitiesResponse -> Bool
Prelude.Eq, ReadPrec [ContainsPiiEntitiesResponse]
ReadPrec ContainsPiiEntitiesResponse
Int -> ReadS ContainsPiiEntitiesResponse
ReadS [ContainsPiiEntitiesResponse]
(Int -> ReadS ContainsPiiEntitiesResponse)
-> ReadS [ContainsPiiEntitiesResponse]
-> ReadPrec ContainsPiiEntitiesResponse
-> ReadPrec [ContainsPiiEntitiesResponse]
-> Read ContainsPiiEntitiesResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ContainsPiiEntitiesResponse]
$creadListPrec :: ReadPrec [ContainsPiiEntitiesResponse]
readPrec :: ReadPrec ContainsPiiEntitiesResponse
$creadPrec :: ReadPrec ContainsPiiEntitiesResponse
readList :: ReadS [ContainsPiiEntitiesResponse]
$creadList :: ReadS [ContainsPiiEntitiesResponse]
readsPrec :: Int -> ReadS ContainsPiiEntitiesResponse
$creadsPrec :: Int -> ReadS ContainsPiiEntitiesResponse
Prelude.Read, Int -> ContainsPiiEntitiesResponse -> ShowS
[ContainsPiiEntitiesResponse] -> ShowS
ContainsPiiEntitiesResponse -> String
(Int -> ContainsPiiEntitiesResponse -> ShowS)
-> (ContainsPiiEntitiesResponse -> String)
-> ([ContainsPiiEntitiesResponse] -> ShowS)
-> Show ContainsPiiEntitiesResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ContainsPiiEntitiesResponse] -> ShowS
$cshowList :: [ContainsPiiEntitiesResponse] -> ShowS
show :: ContainsPiiEntitiesResponse -> String
$cshow :: ContainsPiiEntitiesResponse -> String
showsPrec :: Int -> ContainsPiiEntitiesResponse -> ShowS
$cshowsPrec :: Int -> ContainsPiiEntitiesResponse -> ShowS
Prelude.Show, (forall x.
 ContainsPiiEntitiesResponse -> Rep ContainsPiiEntitiesResponse x)
-> (forall x.
    Rep ContainsPiiEntitiesResponse x -> ContainsPiiEntitiesResponse)
-> Generic ContainsPiiEntitiesResponse
forall x.
Rep ContainsPiiEntitiesResponse x -> ContainsPiiEntitiesResponse
forall x.
ContainsPiiEntitiesResponse -> Rep ContainsPiiEntitiesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ContainsPiiEntitiesResponse x -> ContainsPiiEntitiesResponse
$cfrom :: forall x.
ContainsPiiEntitiesResponse -> Rep ContainsPiiEntitiesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ContainsPiiEntitiesResponse' 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:
--
-- 'labels', 'containsPiiEntitiesResponse_labels' - The labels used in the document being analyzed. Individual labels
-- represent personally identifiable information (PII) entity types.
--
-- 'httpStatus', 'containsPiiEntitiesResponse_httpStatus' - The response's http status code.
newContainsPiiEntitiesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ContainsPiiEntitiesResponse
newContainsPiiEntitiesResponse :: Int -> ContainsPiiEntitiesResponse
newContainsPiiEntitiesResponse Int
pHttpStatus_ =
  ContainsPiiEntitiesResponse' :: Maybe [EntityLabel] -> Int -> ContainsPiiEntitiesResponse
ContainsPiiEntitiesResponse'
    { $sel:labels:ContainsPiiEntitiesResponse' :: Maybe [EntityLabel]
labels =
        Maybe [EntityLabel]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ContainsPiiEntitiesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The labels used in the document being analyzed. Individual labels
-- represent personally identifiable information (PII) entity types.
containsPiiEntitiesResponse_labels :: Lens.Lens' ContainsPiiEntitiesResponse (Prelude.Maybe [EntityLabel])
containsPiiEntitiesResponse_labels :: (Maybe [EntityLabel] -> f (Maybe [EntityLabel]))
-> ContainsPiiEntitiesResponse -> f ContainsPiiEntitiesResponse
containsPiiEntitiesResponse_labels = (ContainsPiiEntitiesResponse -> Maybe [EntityLabel])
-> (ContainsPiiEntitiesResponse
    -> Maybe [EntityLabel] -> ContainsPiiEntitiesResponse)
-> Lens
     ContainsPiiEntitiesResponse
     ContainsPiiEntitiesResponse
     (Maybe [EntityLabel])
     (Maybe [EntityLabel])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ContainsPiiEntitiesResponse' {Maybe [EntityLabel]
labels :: Maybe [EntityLabel]
$sel:labels:ContainsPiiEntitiesResponse' :: ContainsPiiEntitiesResponse -> Maybe [EntityLabel]
labels} -> Maybe [EntityLabel]
labels) (\s :: ContainsPiiEntitiesResponse
s@ContainsPiiEntitiesResponse' {} Maybe [EntityLabel]
a -> ContainsPiiEntitiesResponse
s {$sel:labels:ContainsPiiEntitiesResponse' :: Maybe [EntityLabel]
labels = Maybe [EntityLabel]
a} :: ContainsPiiEntitiesResponse) ((Maybe [EntityLabel] -> f (Maybe [EntityLabel]))
 -> ContainsPiiEntitiesResponse -> f ContainsPiiEntitiesResponse)
-> ((Maybe [EntityLabel] -> f (Maybe [EntityLabel]))
    -> Maybe [EntityLabel] -> f (Maybe [EntityLabel]))
-> (Maybe [EntityLabel] -> f (Maybe [EntityLabel]))
-> ContainsPiiEntitiesResponse
-> f ContainsPiiEntitiesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [EntityLabel] [EntityLabel] [EntityLabel] [EntityLabel]
-> Iso
     (Maybe [EntityLabel])
     (Maybe [EntityLabel])
     (Maybe [EntityLabel])
     (Maybe [EntityLabel])
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 [EntityLabel] [EntityLabel] [EntityLabel] [EntityLabel]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData ContainsPiiEntitiesResponse