{-# 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.BatchDetectDominantLanguage
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Determines the dominant language of the input text for a batch of
-- documents. For a list of languages that Amazon Comprehend can detect,
-- see
-- <https://docs.aws.amazon.com/comprehend/latest/dg/how-languages.html Amazon Comprehend Supported Languages>.
module Amazonka.Comprehend.BatchDetectDominantLanguage
  ( -- * Creating a Request
    BatchDetectDominantLanguage (..),
    newBatchDetectDominantLanguage,

    -- * Request Lenses
    batchDetectDominantLanguage_textList,

    -- * Destructuring the Response
    BatchDetectDominantLanguageResponse (..),
    newBatchDetectDominantLanguageResponse,

    -- * Response Lenses
    batchDetectDominantLanguageResponse_httpStatus,
    batchDetectDominantLanguageResponse_resultList,
    batchDetectDominantLanguageResponse_errorList,
  )
where

import Amazonka.Comprehend.Types
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
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newBatchDetectDominantLanguage' smart constructor.
data BatchDetectDominantLanguage = BatchDetectDominantLanguage'
  { -- | A list containing the UTF-8 encoded text of the input documents. The
    -- list can contain a maximum of 25 documents. Each document should contain
    -- at least 20 characters. The maximum size of each document is 5 KB.
    BatchDetectDominantLanguage
-> Sensitive (NonEmpty (Sensitive Text))
textList :: Data.Sensitive (Prelude.NonEmpty (Data.Sensitive Prelude.Text))
  }
  deriving (BatchDetectDominantLanguage -> BatchDetectDominantLanguage -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchDetectDominantLanguage -> BatchDetectDominantLanguage -> Bool
$c/= :: BatchDetectDominantLanguage -> BatchDetectDominantLanguage -> Bool
== :: BatchDetectDominantLanguage -> BatchDetectDominantLanguage -> Bool
$c== :: BatchDetectDominantLanguage -> BatchDetectDominantLanguage -> Bool
Prelude.Eq, Int -> BatchDetectDominantLanguage -> ShowS
[BatchDetectDominantLanguage] -> ShowS
BatchDetectDominantLanguage -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchDetectDominantLanguage] -> ShowS
$cshowList :: [BatchDetectDominantLanguage] -> ShowS
show :: BatchDetectDominantLanguage -> String
$cshow :: BatchDetectDominantLanguage -> String
showsPrec :: Int -> BatchDetectDominantLanguage -> ShowS
$cshowsPrec :: Int -> BatchDetectDominantLanguage -> ShowS
Prelude.Show, forall x.
Rep BatchDetectDominantLanguage x -> BatchDetectDominantLanguage
forall x.
BatchDetectDominantLanguage -> Rep BatchDetectDominantLanguage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BatchDetectDominantLanguage x -> BatchDetectDominantLanguage
$cfrom :: forall x.
BatchDetectDominantLanguage -> Rep BatchDetectDominantLanguage x
Prelude.Generic)

-- |
-- Create a value of 'BatchDetectDominantLanguage' 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:
--
-- 'textList', 'batchDetectDominantLanguage_textList' - A list containing the UTF-8 encoded text of the input documents. The
-- list can contain a maximum of 25 documents. Each document should contain
-- at least 20 characters. The maximum size of each document is 5 KB.
newBatchDetectDominantLanguage ::
  -- | 'textList'
  Prelude.NonEmpty Prelude.Text ->
  BatchDetectDominantLanguage
newBatchDetectDominantLanguage :: NonEmpty Text -> BatchDetectDominantLanguage
newBatchDetectDominantLanguage NonEmpty Text
pTextList_ =
  BatchDetectDominantLanguage'
    { $sel:textList:BatchDetectDominantLanguage' :: Sensitive (NonEmpty (Sensitive Text))
textList =
        forall a. Iso' (Sensitive a) a
Data._Sensitive
          forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced
          forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pTextList_
    }

-- | A list containing the UTF-8 encoded text of the input documents. The
-- list can contain a maximum of 25 documents. Each document should contain
-- at least 20 characters. The maximum size of each document is 5 KB.
batchDetectDominantLanguage_textList :: Lens.Lens' BatchDetectDominantLanguage (Prelude.NonEmpty Prelude.Text)
batchDetectDominantLanguage_textList :: Lens' BatchDetectDominantLanguage (NonEmpty Text)
batchDetectDominantLanguage_textList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchDetectDominantLanguage' {Sensitive (NonEmpty (Sensitive Text))
textList :: Sensitive (NonEmpty (Sensitive Text))
$sel:textList:BatchDetectDominantLanguage' :: BatchDetectDominantLanguage
-> Sensitive (NonEmpty (Sensitive Text))
textList} -> Sensitive (NonEmpty (Sensitive Text))
textList) (\s :: BatchDetectDominantLanguage
s@BatchDetectDominantLanguage' {} Sensitive (NonEmpty (Sensitive Text))
a -> BatchDetectDominantLanguage
s {$sel:textList:BatchDetectDominantLanguage' :: Sensitive (NonEmpty (Sensitive Text))
textList = Sensitive (NonEmpty (Sensitive Text))
a} :: BatchDetectDominantLanguage) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest BatchDetectDominantLanguage where
  type
    AWSResponse BatchDetectDominantLanguage =
      BatchDetectDominantLanguageResponse
  request :: (Service -> Service)
-> BatchDetectDominantLanguage
-> Request BatchDetectDominantLanguage
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy BatchDetectDominantLanguage
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse BatchDetectDominantLanguage)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int
-> [BatchDetectDominantLanguageItemResult]
-> [BatchItemError]
-> BatchDetectDominantLanguageResponse
BatchDetectDominantLanguageResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"ResultList" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"ErrorList" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable BatchDetectDominantLanguage where
  hashWithSalt :: Int -> BatchDetectDominantLanguage -> Int
hashWithSalt Int
_salt BatchDetectDominantLanguage' {Sensitive (NonEmpty (Sensitive Text))
textList :: Sensitive (NonEmpty (Sensitive Text))
$sel:textList:BatchDetectDominantLanguage' :: BatchDetectDominantLanguage
-> Sensitive (NonEmpty (Sensitive Text))
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive (NonEmpty (Sensitive Text))
textList

instance Prelude.NFData BatchDetectDominantLanguage where
  rnf :: BatchDetectDominantLanguage -> ()
rnf BatchDetectDominantLanguage' {Sensitive (NonEmpty (Sensitive Text))
textList :: Sensitive (NonEmpty (Sensitive Text))
$sel:textList:BatchDetectDominantLanguage' :: BatchDetectDominantLanguage
-> Sensitive (NonEmpty (Sensitive Text))
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Sensitive (NonEmpty (Sensitive Text))
textList

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

instance Data.ToJSON BatchDetectDominantLanguage where
  toJSON :: BatchDetectDominantLanguage -> Value
toJSON BatchDetectDominantLanguage' {Sensitive (NonEmpty (Sensitive Text))
textList :: Sensitive (NonEmpty (Sensitive Text))
$sel:textList:BatchDetectDominantLanguage' :: BatchDetectDominantLanguage
-> Sensitive (NonEmpty (Sensitive Text))
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"TextList" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive (NonEmpty (Sensitive Text))
textList)]
      )

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

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

-- | /See:/ 'newBatchDetectDominantLanguageResponse' smart constructor.
data BatchDetectDominantLanguageResponse = BatchDetectDominantLanguageResponse'
  { -- | The response's http status code.
    BatchDetectDominantLanguageResponse -> Int
httpStatus :: Prelude.Int,
    -- | A list of objects containing the results of the operation. The results
    -- are sorted in ascending order by the @Index@ field and match the order
    -- of the documents in the input list. If all of the documents contain an
    -- error, the @ResultList@ is empty.
    BatchDetectDominantLanguageResponse
-> [BatchDetectDominantLanguageItemResult]
resultList :: [BatchDetectDominantLanguageItemResult],
    -- | A list containing one object for each document that contained an error.
    -- The results are sorted in ascending order by the @Index@ field and match
    -- the order of the documents in the input list. If there are no errors in
    -- the batch, the @ErrorList@ is empty.
    BatchDetectDominantLanguageResponse -> [BatchItemError]
errorList :: [BatchItemError]
  }
  deriving (BatchDetectDominantLanguageResponse
-> BatchDetectDominantLanguageResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchDetectDominantLanguageResponse
-> BatchDetectDominantLanguageResponse -> Bool
$c/= :: BatchDetectDominantLanguageResponse
-> BatchDetectDominantLanguageResponse -> Bool
== :: BatchDetectDominantLanguageResponse
-> BatchDetectDominantLanguageResponse -> Bool
$c== :: BatchDetectDominantLanguageResponse
-> BatchDetectDominantLanguageResponse -> Bool
Prelude.Eq, Int -> BatchDetectDominantLanguageResponse -> ShowS
[BatchDetectDominantLanguageResponse] -> ShowS
BatchDetectDominantLanguageResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchDetectDominantLanguageResponse] -> ShowS
$cshowList :: [BatchDetectDominantLanguageResponse] -> ShowS
show :: BatchDetectDominantLanguageResponse -> String
$cshow :: BatchDetectDominantLanguageResponse -> String
showsPrec :: Int -> BatchDetectDominantLanguageResponse -> ShowS
$cshowsPrec :: Int -> BatchDetectDominantLanguageResponse -> ShowS
Prelude.Show, forall x.
Rep BatchDetectDominantLanguageResponse x
-> BatchDetectDominantLanguageResponse
forall x.
BatchDetectDominantLanguageResponse
-> Rep BatchDetectDominantLanguageResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BatchDetectDominantLanguageResponse x
-> BatchDetectDominantLanguageResponse
$cfrom :: forall x.
BatchDetectDominantLanguageResponse
-> Rep BatchDetectDominantLanguageResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchDetectDominantLanguageResponse' 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:
--
-- 'httpStatus', 'batchDetectDominantLanguageResponse_httpStatus' - The response's http status code.
--
-- 'resultList', 'batchDetectDominantLanguageResponse_resultList' - A list of objects containing the results of the operation. The results
-- are sorted in ascending order by the @Index@ field and match the order
-- of the documents in the input list. If all of the documents contain an
-- error, the @ResultList@ is empty.
--
-- 'errorList', 'batchDetectDominantLanguageResponse_errorList' - A list containing one object for each document that contained an error.
-- The results are sorted in ascending order by the @Index@ field and match
-- the order of the documents in the input list. If there are no errors in
-- the batch, the @ErrorList@ is empty.
newBatchDetectDominantLanguageResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchDetectDominantLanguageResponse
newBatchDetectDominantLanguageResponse :: Int -> BatchDetectDominantLanguageResponse
newBatchDetectDominantLanguageResponse Int
pHttpStatus_ =
  BatchDetectDominantLanguageResponse'
    { $sel:httpStatus:BatchDetectDominantLanguageResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:resultList:BatchDetectDominantLanguageResponse' :: [BatchDetectDominantLanguageItemResult]
resultList = forall a. Monoid a => a
Prelude.mempty,
      $sel:errorList:BatchDetectDominantLanguageResponse' :: [BatchItemError]
errorList = forall a. Monoid a => a
Prelude.mempty
    }

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

-- | A list of objects containing the results of the operation. The results
-- are sorted in ascending order by the @Index@ field and match the order
-- of the documents in the input list. If all of the documents contain an
-- error, the @ResultList@ is empty.
batchDetectDominantLanguageResponse_resultList :: Lens.Lens' BatchDetectDominantLanguageResponse [BatchDetectDominantLanguageItemResult]
batchDetectDominantLanguageResponse_resultList :: Lens'
  BatchDetectDominantLanguageResponse
  [BatchDetectDominantLanguageItemResult]
batchDetectDominantLanguageResponse_resultList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchDetectDominantLanguageResponse' {[BatchDetectDominantLanguageItemResult]
resultList :: [BatchDetectDominantLanguageItemResult]
$sel:resultList:BatchDetectDominantLanguageResponse' :: BatchDetectDominantLanguageResponse
-> [BatchDetectDominantLanguageItemResult]
resultList} -> [BatchDetectDominantLanguageItemResult]
resultList) (\s :: BatchDetectDominantLanguageResponse
s@BatchDetectDominantLanguageResponse' {} [BatchDetectDominantLanguageItemResult]
a -> BatchDetectDominantLanguageResponse
s {$sel:resultList:BatchDetectDominantLanguageResponse' :: [BatchDetectDominantLanguageItemResult]
resultList = [BatchDetectDominantLanguageItemResult]
a} :: BatchDetectDominantLanguageResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list containing one object for each document that contained an error.
-- The results are sorted in ascending order by the @Index@ field and match
-- the order of the documents in the input list. If there are no errors in
-- the batch, the @ErrorList@ is empty.
batchDetectDominantLanguageResponse_errorList :: Lens.Lens' BatchDetectDominantLanguageResponse [BatchItemError]
batchDetectDominantLanguageResponse_errorList :: Lens' BatchDetectDominantLanguageResponse [BatchItemError]
batchDetectDominantLanguageResponse_errorList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchDetectDominantLanguageResponse' {[BatchItemError]
errorList :: [BatchItemError]
$sel:errorList:BatchDetectDominantLanguageResponse' :: BatchDetectDominantLanguageResponse -> [BatchItemError]
errorList} -> [BatchItemError]
errorList) (\s :: BatchDetectDominantLanguageResponse
s@BatchDetectDominantLanguageResponse' {} [BatchItemError]
a -> BatchDetectDominantLanguageResponse
s {$sel:errorList:BatchDetectDominantLanguageResponse' :: [BatchItemError]
errorList = [BatchItemError]
a} :: BatchDetectDominantLanguageResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance
  Prelude.NFData
    BatchDetectDominantLanguageResponse
  where
  rnf :: BatchDetectDominantLanguageResponse -> ()
rnf BatchDetectDominantLanguageResponse' {Int
[BatchItemError]
[BatchDetectDominantLanguageItemResult]
errorList :: [BatchItemError]
resultList :: [BatchDetectDominantLanguageItemResult]
httpStatus :: Int
$sel:errorList:BatchDetectDominantLanguageResponse' :: BatchDetectDominantLanguageResponse -> [BatchItemError]
$sel:resultList:BatchDetectDominantLanguageResponse' :: BatchDetectDominantLanguageResponse
-> [BatchDetectDominantLanguageItemResult]
$sel:httpStatus:BatchDetectDominantLanguageResponse' :: BatchDetectDominantLanguageResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [BatchDetectDominantLanguageItemResult]
resultList
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [BatchItemError]
errorList