{-# 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.Polly.GetLexicon
-- 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)
--
-- Returns the content of the specified pronunciation lexicon stored in an
-- Amazon Web Services Region. For more information, see
-- <https://docs.aws.amazon.com/polly/latest/dg/managing-lexicons.html Managing Lexicons>.
module Amazonka.Polly.GetLexicon
  ( -- * Creating a Request
    GetLexicon (..),
    newGetLexicon,

    -- * Request Lenses
    getLexicon_name,

    -- * Destructuring the Response
    GetLexiconResponse (..),
    newGetLexiconResponse,

    -- * Response Lenses
    getLexiconResponse_lexiconAttributes,
    getLexiconResponse_lexicon,
    getLexiconResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetLexicon' smart constructor.
data GetLexicon = GetLexicon'
  { -- | Name of the lexicon.
    GetLexicon -> Text
name :: Prelude.Text
  }
  deriving (GetLexicon -> GetLexicon -> Bool
(GetLexicon -> GetLexicon -> Bool)
-> (GetLexicon -> GetLexicon -> Bool) -> Eq GetLexicon
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetLexicon -> GetLexicon -> Bool
$c/= :: GetLexicon -> GetLexicon -> Bool
== :: GetLexicon -> GetLexicon -> Bool
$c== :: GetLexicon -> GetLexicon -> Bool
Prelude.Eq, ReadPrec [GetLexicon]
ReadPrec GetLexicon
Int -> ReadS GetLexicon
ReadS [GetLexicon]
(Int -> ReadS GetLexicon)
-> ReadS [GetLexicon]
-> ReadPrec GetLexicon
-> ReadPrec [GetLexicon]
-> Read GetLexicon
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetLexicon]
$creadListPrec :: ReadPrec [GetLexicon]
readPrec :: ReadPrec GetLexicon
$creadPrec :: ReadPrec GetLexicon
readList :: ReadS [GetLexicon]
$creadList :: ReadS [GetLexicon]
readsPrec :: Int -> ReadS GetLexicon
$creadsPrec :: Int -> ReadS GetLexicon
Prelude.Read, Int -> GetLexicon -> ShowS
[GetLexicon] -> ShowS
GetLexicon -> String
(Int -> GetLexicon -> ShowS)
-> (GetLexicon -> String)
-> ([GetLexicon] -> ShowS)
-> Show GetLexicon
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetLexicon] -> ShowS
$cshowList :: [GetLexicon] -> ShowS
show :: GetLexicon -> String
$cshow :: GetLexicon -> String
showsPrec :: Int -> GetLexicon -> ShowS
$cshowsPrec :: Int -> GetLexicon -> ShowS
Prelude.Show, (forall x. GetLexicon -> Rep GetLexicon x)
-> (forall x. Rep GetLexicon x -> GetLexicon) -> Generic GetLexicon
forall x. Rep GetLexicon x -> GetLexicon
forall x. GetLexicon -> Rep GetLexicon x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetLexicon x -> GetLexicon
$cfrom :: forall x. GetLexicon -> Rep GetLexicon x
Prelude.Generic)

-- |
-- Create a value of 'GetLexicon' 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:
--
-- 'name', 'getLexicon_name' - Name of the lexicon.
newGetLexicon ::
  -- | 'name'
  Prelude.Text ->
  GetLexicon
newGetLexicon :: Text -> GetLexicon
newGetLexicon Text
pName_ = GetLexicon' :: Text -> GetLexicon
GetLexicon' {$sel:name:GetLexicon' :: Text
name = Text
pName_}

-- | Name of the lexicon.
getLexicon_name :: Lens.Lens' GetLexicon Prelude.Text
getLexicon_name :: (Text -> f Text) -> GetLexicon -> f GetLexicon
getLexicon_name = (GetLexicon -> Text)
-> (GetLexicon -> Text -> GetLexicon)
-> Lens GetLexicon GetLexicon Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetLexicon' {Text
name :: Text
$sel:name:GetLexicon' :: GetLexicon -> Text
name} -> Text
name) (\s :: GetLexicon
s@GetLexicon' {} Text
a -> GetLexicon
s {$sel:name:GetLexicon' :: Text
name = Text
a} :: GetLexicon)

instance Core.AWSRequest GetLexicon where
  type AWSResponse GetLexicon = GetLexiconResponse
  request :: GetLexicon -> Request GetLexicon
request = Service -> GetLexicon -> Request GetLexicon
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetLexicon
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetLexicon)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetLexicon))
-> Logger
-> Service
-> Proxy GetLexicon
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetLexicon)))
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 LexiconAttributes
-> Maybe Lexicon -> Int -> GetLexiconResponse
GetLexiconResponse'
            (Maybe LexiconAttributes
 -> Maybe Lexicon -> Int -> GetLexiconResponse)
-> Either String (Maybe LexiconAttributes)
-> Either String (Maybe Lexicon -> Int -> GetLexiconResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe LexiconAttributes)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"LexiconAttributes")
            Either String (Maybe Lexicon -> Int -> GetLexiconResponse)
-> Either String (Maybe Lexicon)
-> Either String (Int -> GetLexiconResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Lexicon)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Lexicon")
            Either String (Int -> GetLexiconResponse)
-> Either String Int -> Either String GetLexiconResponse
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 GetLexicon

instance Prelude.NFData GetLexicon

instance Core.ToHeaders GetLexicon where
  toHeaders :: GetLexicon -> ResponseHeaders
toHeaders = ResponseHeaders -> GetLexicon -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToPath GetLexicon where
  toPath :: GetLexicon -> ByteString
toPath GetLexicon' {Text
name :: Text
$sel:name:GetLexicon' :: GetLexicon -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/v1/lexicons/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
name]

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

-- | /See:/ 'newGetLexiconResponse' smart constructor.
data GetLexiconResponse = GetLexiconResponse'
  { -- | Metadata of the lexicon, including phonetic alphabetic used, language
    -- code, lexicon ARN, number of lexemes defined in the lexicon, and size of
    -- lexicon in bytes.
    GetLexiconResponse -> Maybe LexiconAttributes
lexiconAttributes :: Prelude.Maybe LexiconAttributes,
    -- | Lexicon object that provides name and the string content of the lexicon.
    GetLexiconResponse -> Maybe Lexicon
lexicon :: Prelude.Maybe Lexicon,
    -- | The response's http status code.
    GetLexiconResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetLexiconResponse -> GetLexiconResponse -> Bool
(GetLexiconResponse -> GetLexiconResponse -> Bool)
-> (GetLexiconResponse -> GetLexiconResponse -> Bool)
-> Eq GetLexiconResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetLexiconResponse -> GetLexiconResponse -> Bool
$c/= :: GetLexiconResponse -> GetLexiconResponse -> Bool
== :: GetLexiconResponse -> GetLexiconResponse -> Bool
$c== :: GetLexiconResponse -> GetLexiconResponse -> Bool
Prelude.Eq, Int -> GetLexiconResponse -> ShowS
[GetLexiconResponse] -> ShowS
GetLexiconResponse -> String
(Int -> GetLexiconResponse -> ShowS)
-> (GetLexiconResponse -> String)
-> ([GetLexiconResponse] -> ShowS)
-> Show GetLexiconResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetLexiconResponse] -> ShowS
$cshowList :: [GetLexiconResponse] -> ShowS
show :: GetLexiconResponse -> String
$cshow :: GetLexiconResponse -> String
showsPrec :: Int -> GetLexiconResponse -> ShowS
$cshowsPrec :: Int -> GetLexiconResponse -> ShowS
Prelude.Show, (forall x. GetLexiconResponse -> Rep GetLexiconResponse x)
-> (forall x. Rep GetLexiconResponse x -> GetLexiconResponse)
-> Generic GetLexiconResponse
forall x. Rep GetLexiconResponse x -> GetLexiconResponse
forall x. GetLexiconResponse -> Rep GetLexiconResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetLexiconResponse x -> GetLexiconResponse
$cfrom :: forall x. GetLexiconResponse -> Rep GetLexiconResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetLexiconResponse' 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:
--
-- 'lexiconAttributes', 'getLexiconResponse_lexiconAttributes' - Metadata of the lexicon, including phonetic alphabetic used, language
-- code, lexicon ARN, number of lexemes defined in the lexicon, and size of
-- lexicon in bytes.
--
-- 'lexicon', 'getLexiconResponse_lexicon' - Lexicon object that provides name and the string content of the lexicon.
--
-- 'httpStatus', 'getLexiconResponse_httpStatus' - The response's http status code.
newGetLexiconResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetLexiconResponse
newGetLexiconResponse :: Int -> GetLexiconResponse
newGetLexiconResponse Int
pHttpStatus_ =
  GetLexiconResponse' :: Maybe LexiconAttributes
-> Maybe Lexicon -> Int -> GetLexiconResponse
GetLexiconResponse'
    { $sel:lexiconAttributes:GetLexiconResponse' :: Maybe LexiconAttributes
lexiconAttributes =
        Maybe LexiconAttributes
forall a. Maybe a
Prelude.Nothing,
      $sel:lexicon:GetLexiconResponse' :: Maybe Lexicon
lexicon = Maybe Lexicon
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetLexiconResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Metadata of the lexicon, including phonetic alphabetic used, language
-- code, lexicon ARN, number of lexemes defined in the lexicon, and size of
-- lexicon in bytes.
getLexiconResponse_lexiconAttributes :: Lens.Lens' GetLexiconResponse (Prelude.Maybe LexiconAttributes)
getLexiconResponse_lexiconAttributes :: (Maybe LexiconAttributes -> f (Maybe LexiconAttributes))
-> GetLexiconResponse -> f GetLexiconResponse
getLexiconResponse_lexiconAttributes = (GetLexiconResponse -> Maybe LexiconAttributes)
-> (GetLexiconResponse
    -> Maybe LexiconAttributes -> GetLexiconResponse)
-> Lens
     GetLexiconResponse
     GetLexiconResponse
     (Maybe LexiconAttributes)
     (Maybe LexiconAttributes)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetLexiconResponse' {Maybe LexiconAttributes
lexiconAttributes :: Maybe LexiconAttributes
$sel:lexiconAttributes:GetLexiconResponse' :: GetLexiconResponse -> Maybe LexiconAttributes
lexiconAttributes} -> Maybe LexiconAttributes
lexiconAttributes) (\s :: GetLexiconResponse
s@GetLexiconResponse' {} Maybe LexiconAttributes
a -> GetLexiconResponse
s {$sel:lexiconAttributes:GetLexiconResponse' :: Maybe LexiconAttributes
lexiconAttributes = Maybe LexiconAttributes
a} :: GetLexiconResponse)

-- | Lexicon object that provides name and the string content of the lexicon.
getLexiconResponse_lexicon :: Lens.Lens' GetLexiconResponse (Prelude.Maybe Lexicon)
getLexiconResponse_lexicon :: (Maybe Lexicon -> f (Maybe Lexicon))
-> GetLexiconResponse -> f GetLexiconResponse
getLexiconResponse_lexicon = (GetLexiconResponse -> Maybe Lexicon)
-> (GetLexiconResponse -> Maybe Lexicon -> GetLexiconResponse)
-> Lens
     GetLexiconResponse
     GetLexiconResponse
     (Maybe Lexicon)
     (Maybe Lexicon)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetLexiconResponse' {Maybe Lexicon
lexicon :: Maybe Lexicon
$sel:lexicon:GetLexiconResponse' :: GetLexiconResponse -> Maybe Lexicon
lexicon} -> Maybe Lexicon
lexicon) (\s :: GetLexiconResponse
s@GetLexiconResponse' {} Maybe Lexicon
a -> GetLexiconResponse
s {$sel:lexicon:GetLexiconResponse' :: Maybe Lexicon
lexicon = Maybe Lexicon
a} :: GetLexiconResponse)

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

instance Prelude.NFData GetLexiconResponse