{-# 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.DetectDominantLanguage
-- 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)
--
-- Determines the dominant language of the input text. 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.DetectDominantLanguage
  ( -- * Creating a Request
    DetectDominantLanguage (..),
    newDetectDominantLanguage,

    -- * Request Lenses
    detectDominantLanguage_text,

    -- * Destructuring the Response
    DetectDominantLanguageResponse (..),
    newDetectDominantLanguageResponse,

    -- * Response Lenses
    detectDominantLanguageResponse_languages,
    detectDominantLanguageResponse_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:/ 'newDetectDominantLanguage' smart constructor.
data DetectDominantLanguage = DetectDominantLanguage'
  { -- | A UTF-8 text string. Each string should contain at least 20 characters
    -- and must contain fewer that 5,000 bytes of UTF-8 encoded characters.
    DetectDominantLanguage -> Sensitive Text
text :: Core.Sensitive Prelude.Text
  }
  deriving (DetectDominantLanguage -> DetectDominantLanguage -> Bool
(DetectDominantLanguage -> DetectDominantLanguage -> Bool)
-> (DetectDominantLanguage -> DetectDominantLanguage -> Bool)
-> Eq DetectDominantLanguage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetectDominantLanguage -> DetectDominantLanguage -> Bool
$c/= :: DetectDominantLanguage -> DetectDominantLanguage -> Bool
== :: DetectDominantLanguage -> DetectDominantLanguage -> Bool
$c== :: DetectDominantLanguage -> DetectDominantLanguage -> Bool
Prelude.Eq, Int -> DetectDominantLanguage -> ShowS
[DetectDominantLanguage] -> ShowS
DetectDominantLanguage -> String
(Int -> DetectDominantLanguage -> ShowS)
-> (DetectDominantLanguage -> String)
-> ([DetectDominantLanguage] -> ShowS)
-> Show DetectDominantLanguage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetectDominantLanguage] -> ShowS
$cshowList :: [DetectDominantLanguage] -> ShowS
show :: DetectDominantLanguage -> String
$cshow :: DetectDominantLanguage -> String
showsPrec :: Int -> DetectDominantLanguage -> ShowS
$cshowsPrec :: Int -> DetectDominantLanguage -> ShowS
Prelude.Show, (forall x. DetectDominantLanguage -> Rep DetectDominantLanguage x)
-> (forall x.
    Rep DetectDominantLanguage x -> DetectDominantLanguage)
-> Generic DetectDominantLanguage
forall x. Rep DetectDominantLanguage x -> DetectDominantLanguage
forall x. DetectDominantLanguage -> Rep DetectDominantLanguage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetectDominantLanguage x -> DetectDominantLanguage
$cfrom :: forall x. DetectDominantLanguage -> Rep DetectDominantLanguage x
Prelude.Generic)

-- |
-- Create a value of 'DetectDominantLanguage' 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', 'detectDominantLanguage_text' - A UTF-8 text string. Each string should contain at least 20 characters
-- and must contain fewer that 5,000 bytes of UTF-8 encoded characters.
newDetectDominantLanguage ::
  -- | 'text'
  Prelude.Text ->
  DetectDominantLanguage
newDetectDominantLanguage :: Text -> DetectDominantLanguage
newDetectDominantLanguage Text
pText_ =
  DetectDominantLanguage' :: Sensitive Text -> DetectDominantLanguage
DetectDominantLanguage'
    { $sel:text:DetectDominantLanguage' :: Sensitive Text
text =
        Tagged Text (Identity Text)
-> Tagged (Sensitive Text) (Identity (Sensitive Text))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged Text (Identity Text)
 -> Tagged (Sensitive Text) (Identity (Sensitive Text)))
-> Text -> Sensitive Text
forall t b. AReview t b -> b -> t
Lens.# Text
pText_
    }

-- | A UTF-8 text string. Each string should contain at least 20 characters
-- and must contain fewer that 5,000 bytes of UTF-8 encoded characters.
detectDominantLanguage_text :: Lens.Lens' DetectDominantLanguage Prelude.Text
detectDominantLanguage_text :: (Text -> f Text)
-> DetectDominantLanguage -> f DetectDominantLanguage
detectDominantLanguage_text = (DetectDominantLanguage -> Sensitive Text)
-> (DetectDominantLanguage
    -> Sensitive Text -> DetectDominantLanguage)
-> Lens
     DetectDominantLanguage
     DetectDominantLanguage
     (Sensitive Text)
     (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectDominantLanguage' {Sensitive Text
text :: Sensitive Text
$sel:text:DetectDominantLanguage' :: DetectDominantLanguage -> Sensitive Text
text} -> Sensitive Text
text) (\s :: DetectDominantLanguage
s@DetectDominantLanguage' {} Sensitive Text
a -> DetectDominantLanguage
s {$sel:text:DetectDominantLanguage' :: Sensitive Text
text = Sensitive Text
a} :: DetectDominantLanguage) ((Sensitive Text -> f (Sensitive Text))
 -> DetectDominantLanguage -> f DetectDominantLanguage)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> DetectDominantLanguage
-> f DetectDominantLanguage
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> f Text) -> Sensitive Text -> f (Sensitive Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive

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

instance Prelude.NFData DetectDominantLanguage

instance Core.ToHeaders DetectDominantLanguage where
  toHeaders :: DetectDominantLanguage -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DetectDominantLanguage -> 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.DetectDominantLanguage" ::
                          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 DetectDominantLanguage where
  toJSON :: DetectDominantLanguage -> Value
toJSON DetectDominantLanguage' {Sensitive Text
text :: Sensitive Text
$sel:text:DetectDominantLanguage' :: DetectDominantLanguage -> Sensitive 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 -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
text)]
      )

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

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

-- | /See:/ 'newDetectDominantLanguageResponse' smart constructor.
data DetectDominantLanguageResponse = DetectDominantLanguageResponse'
  { -- | The languages that Amazon Comprehend detected in the input text. For
    -- each language, the response returns the RFC 5646 language code and the
    -- level of confidence that Amazon Comprehend has in the accuracy of its
    -- inference. For more information about RFC 5646, see
    -- <https://tools.ietf.org/html/rfc5646 Tags for Identifying Languages> on
    -- the /IETF Tools/ web site.
    DetectDominantLanguageResponse -> Maybe [DominantLanguage]
languages :: Prelude.Maybe [DominantLanguage],
    -- | The response's http status code.
    DetectDominantLanguageResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DetectDominantLanguageResponse
-> DetectDominantLanguageResponse -> Bool
(DetectDominantLanguageResponse
 -> DetectDominantLanguageResponse -> Bool)
-> (DetectDominantLanguageResponse
    -> DetectDominantLanguageResponse -> Bool)
-> Eq DetectDominantLanguageResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetectDominantLanguageResponse
-> DetectDominantLanguageResponse -> Bool
$c/= :: DetectDominantLanguageResponse
-> DetectDominantLanguageResponse -> Bool
== :: DetectDominantLanguageResponse
-> DetectDominantLanguageResponse -> Bool
$c== :: DetectDominantLanguageResponse
-> DetectDominantLanguageResponse -> Bool
Prelude.Eq, Int -> DetectDominantLanguageResponse -> ShowS
[DetectDominantLanguageResponse] -> ShowS
DetectDominantLanguageResponse -> String
(Int -> DetectDominantLanguageResponse -> ShowS)
-> (DetectDominantLanguageResponse -> String)
-> ([DetectDominantLanguageResponse] -> ShowS)
-> Show DetectDominantLanguageResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetectDominantLanguageResponse] -> ShowS
$cshowList :: [DetectDominantLanguageResponse] -> ShowS
show :: DetectDominantLanguageResponse -> String
$cshow :: DetectDominantLanguageResponse -> String
showsPrec :: Int -> DetectDominantLanguageResponse -> ShowS
$cshowsPrec :: Int -> DetectDominantLanguageResponse -> ShowS
Prelude.Show, (forall x.
 DetectDominantLanguageResponse
 -> Rep DetectDominantLanguageResponse x)
-> (forall x.
    Rep DetectDominantLanguageResponse x
    -> DetectDominantLanguageResponse)
-> Generic DetectDominantLanguageResponse
forall x.
Rep DetectDominantLanguageResponse x
-> DetectDominantLanguageResponse
forall x.
DetectDominantLanguageResponse
-> Rep DetectDominantLanguageResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DetectDominantLanguageResponse x
-> DetectDominantLanguageResponse
$cfrom :: forall x.
DetectDominantLanguageResponse
-> Rep DetectDominantLanguageResponse x
Prelude.Generic)

-- |
-- Create a value of 'DetectDominantLanguageResponse' 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:
--
-- 'languages', 'detectDominantLanguageResponse_languages' - The languages that Amazon Comprehend detected in the input text. For
-- each language, the response returns the RFC 5646 language code and the
-- level of confidence that Amazon Comprehend has in the accuracy of its
-- inference. For more information about RFC 5646, see
-- <https://tools.ietf.org/html/rfc5646 Tags for Identifying Languages> on
-- the /IETF Tools/ web site.
--
-- 'httpStatus', 'detectDominantLanguageResponse_httpStatus' - The response's http status code.
newDetectDominantLanguageResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DetectDominantLanguageResponse
newDetectDominantLanguageResponse :: Int -> DetectDominantLanguageResponse
newDetectDominantLanguageResponse Int
pHttpStatus_ =
  DetectDominantLanguageResponse' :: Maybe [DominantLanguage] -> Int -> DetectDominantLanguageResponse
DetectDominantLanguageResponse'
    { $sel:languages:DetectDominantLanguageResponse' :: Maybe [DominantLanguage]
languages =
        Maybe [DominantLanguage]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DetectDominantLanguageResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The languages that Amazon Comprehend detected in the input text. For
-- each language, the response returns the RFC 5646 language code and the
-- level of confidence that Amazon Comprehend has in the accuracy of its
-- inference. For more information about RFC 5646, see
-- <https://tools.ietf.org/html/rfc5646 Tags for Identifying Languages> on
-- the /IETF Tools/ web site.
detectDominantLanguageResponse_languages :: Lens.Lens' DetectDominantLanguageResponse (Prelude.Maybe [DominantLanguage])
detectDominantLanguageResponse_languages :: (Maybe [DominantLanguage] -> f (Maybe [DominantLanguage]))
-> DetectDominantLanguageResponse
-> f DetectDominantLanguageResponse
detectDominantLanguageResponse_languages = (DetectDominantLanguageResponse -> Maybe [DominantLanguage])
-> (DetectDominantLanguageResponse
    -> Maybe [DominantLanguage] -> DetectDominantLanguageResponse)
-> Lens
     DetectDominantLanguageResponse
     DetectDominantLanguageResponse
     (Maybe [DominantLanguage])
     (Maybe [DominantLanguage])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectDominantLanguageResponse' {Maybe [DominantLanguage]
languages :: Maybe [DominantLanguage]
$sel:languages:DetectDominantLanguageResponse' :: DetectDominantLanguageResponse -> Maybe [DominantLanguage]
languages} -> Maybe [DominantLanguage]
languages) (\s :: DetectDominantLanguageResponse
s@DetectDominantLanguageResponse' {} Maybe [DominantLanguage]
a -> DetectDominantLanguageResponse
s {$sel:languages:DetectDominantLanguageResponse' :: Maybe [DominantLanguage]
languages = Maybe [DominantLanguage]
a} :: DetectDominantLanguageResponse) ((Maybe [DominantLanguage] -> f (Maybe [DominantLanguage]))
 -> DetectDominantLanguageResponse
 -> f DetectDominantLanguageResponse)
-> ((Maybe [DominantLanguage] -> f (Maybe [DominantLanguage]))
    -> Maybe [DominantLanguage] -> f (Maybe [DominantLanguage]))
-> (Maybe [DominantLanguage] -> f (Maybe [DominantLanguage]))
-> DetectDominantLanguageResponse
-> f DetectDominantLanguageResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [DominantLanguage]
  [DominantLanguage]
  [DominantLanguage]
  [DominantLanguage]
-> Iso
     (Maybe [DominantLanguage])
     (Maybe [DominantLanguage])
     (Maybe [DominantLanguage])
     (Maybe [DominantLanguage])
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
  [DominantLanguage]
  [DominantLanguage]
  [DominantLanguage]
  [DominantLanguage]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance
  Prelude.NFData
    DetectDominantLanguageResponse