{-# 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.PutLexicon
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Stores a pronunciation lexicon in an Amazon Web Services Region. If a
-- lexicon with the same name already exists in the region, it is
-- overwritten by the new lexicon. Lexicon operations have eventual
-- consistency, therefore, it might take some time before the lexicon is
-- available to the SynthesizeSpeech operation.
--
-- For more information, see
-- <https://docs.aws.amazon.com/polly/latest/dg/managing-lexicons.html Managing Lexicons>.
module Amazonka.Polly.PutLexicon
  ( -- * Creating a Request
    PutLexicon (..),
    newPutLexicon,

    -- * Request Lenses
    putLexicon_name,
    putLexicon_content,

    -- * Destructuring the Response
    PutLexiconResponse (..),
    newPutLexiconResponse,

    -- * Response Lenses
    putLexiconResponse_httpStatus,
  )
where

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

-- | /See:/ 'newPutLexicon' smart constructor.
data PutLexicon = PutLexicon'
  { -- | Name of the lexicon. The name must follow the regular express format
    -- [0-9A-Za-z]{1,20}. That is, the name is a case-sensitive alphanumeric
    -- string up to 20 characters long.
    PutLexicon -> Text
name :: Prelude.Text,
    -- | Content of the PLS lexicon as string data.
    PutLexicon -> Sensitive Text
content :: Data.Sensitive Prelude.Text
  }
  deriving (PutLexicon -> PutLexicon -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutLexicon -> PutLexicon -> Bool
$c/= :: PutLexicon -> PutLexicon -> Bool
== :: PutLexicon -> PutLexicon -> Bool
$c== :: PutLexicon -> PutLexicon -> Bool
Prelude.Eq, Int -> PutLexicon -> ShowS
[PutLexicon] -> ShowS
PutLexicon -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutLexicon] -> ShowS
$cshowList :: [PutLexicon] -> ShowS
show :: PutLexicon -> String
$cshow :: PutLexicon -> String
showsPrec :: Int -> PutLexicon -> ShowS
$cshowsPrec :: Int -> PutLexicon -> ShowS
Prelude.Show, forall x. Rep PutLexicon x -> PutLexicon
forall x. PutLexicon -> Rep PutLexicon x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutLexicon x -> PutLexicon
$cfrom :: forall x. PutLexicon -> Rep PutLexicon x
Prelude.Generic)

-- |
-- Create a value of 'PutLexicon' 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', 'putLexicon_name' - Name of the lexicon. The name must follow the regular express format
-- [0-9A-Za-z]{1,20}. That is, the name is a case-sensitive alphanumeric
-- string up to 20 characters long.
--
-- 'content', 'putLexicon_content' - Content of the PLS lexicon as string data.
newPutLexicon ::
  -- | 'name'
  Prelude.Text ->
  -- | 'content'
  Prelude.Text ->
  PutLexicon
newPutLexicon :: Text -> Text -> PutLexicon
newPutLexicon Text
pName_ Text
pContent_ =
  PutLexicon'
    { $sel:name:PutLexicon' :: Text
name = Text
pName_,
      $sel:content:PutLexicon' :: Sensitive Text
content = forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pContent_
    }

-- | Name of the lexicon. The name must follow the regular express format
-- [0-9A-Za-z]{1,20}. That is, the name is a case-sensitive alphanumeric
-- string up to 20 characters long.
putLexicon_name :: Lens.Lens' PutLexicon Prelude.Text
putLexicon_name :: Lens' PutLexicon Text
putLexicon_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutLexicon' {Text
name :: Text
$sel:name:PutLexicon' :: PutLexicon -> Text
name} -> Text
name) (\s :: PutLexicon
s@PutLexicon' {} Text
a -> PutLexicon
s {$sel:name:PutLexicon' :: Text
name = Text
a} :: PutLexicon)

-- | Content of the PLS lexicon as string data.
putLexicon_content :: Lens.Lens' PutLexicon Prelude.Text
putLexicon_content :: Lens' PutLexicon Text
putLexicon_content = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutLexicon' {Sensitive Text
content :: Sensitive Text
$sel:content:PutLexicon' :: PutLexicon -> Sensitive Text
content} -> Sensitive Text
content) (\s :: PutLexicon
s@PutLexicon' {} Sensitive Text
a -> PutLexicon
s {$sel:content:PutLexicon' :: Sensitive Text
content = Sensitive Text
a} :: PutLexicon) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

instance Core.AWSRequest PutLexicon where
  type AWSResponse PutLexicon = PutLexiconResponse
  request :: (Service -> Service) -> PutLexicon -> Request PutLexicon
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PutLexicon
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutLexicon)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> PutLexiconResponse
PutLexiconResponse'
            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))
      )

instance Prelude.Hashable PutLexicon where
  hashWithSalt :: Int -> PutLexicon -> Int
hashWithSalt Int
_salt PutLexicon' {Text
Sensitive Text
content :: Sensitive Text
name :: Text
$sel:content:PutLexicon' :: PutLexicon -> Sensitive Text
$sel:name:PutLexicon' :: PutLexicon -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
content

instance Prelude.NFData PutLexicon where
  rnf :: PutLexicon -> ()
rnf PutLexicon' {Text
Sensitive Text
content :: Sensitive Text
name :: Text
$sel:content:PutLexicon' :: PutLexicon -> Sensitive Text
$sel:name:PutLexicon' :: PutLexicon -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
name seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
content

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

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

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

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

-- | /See:/ 'newPutLexiconResponse' smart constructor.
data PutLexiconResponse = PutLexiconResponse'
  { -- | The response's http status code.
    PutLexiconResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PutLexiconResponse -> PutLexiconResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutLexiconResponse -> PutLexiconResponse -> Bool
$c/= :: PutLexiconResponse -> PutLexiconResponse -> Bool
== :: PutLexiconResponse -> PutLexiconResponse -> Bool
$c== :: PutLexiconResponse -> PutLexiconResponse -> Bool
Prelude.Eq, ReadPrec [PutLexiconResponse]
ReadPrec PutLexiconResponse
Int -> ReadS PutLexiconResponse
ReadS [PutLexiconResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutLexiconResponse]
$creadListPrec :: ReadPrec [PutLexiconResponse]
readPrec :: ReadPrec PutLexiconResponse
$creadPrec :: ReadPrec PutLexiconResponse
readList :: ReadS [PutLexiconResponse]
$creadList :: ReadS [PutLexiconResponse]
readsPrec :: Int -> ReadS PutLexiconResponse
$creadsPrec :: Int -> ReadS PutLexiconResponse
Prelude.Read, Int -> PutLexiconResponse -> ShowS
[PutLexiconResponse] -> ShowS
PutLexiconResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutLexiconResponse] -> ShowS
$cshowList :: [PutLexiconResponse] -> ShowS
show :: PutLexiconResponse -> String
$cshow :: PutLexiconResponse -> String
showsPrec :: Int -> PutLexiconResponse -> ShowS
$cshowsPrec :: Int -> PutLexiconResponse -> ShowS
Prelude.Show, forall x. Rep PutLexiconResponse x -> PutLexiconResponse
forall x. PutLexiconResponse -> Rep PutLexiconResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutLexiconResponse x -> PutLexiconResponse
$cfrom :: forall x. PutLexiconResponse -> Rep PutLexiconResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutLexiconResponse' 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', 'putLexiconResponse_httpStatus' - The response's http status code.
newPutLexiconResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutLexiconResponse
newPutLexiconResponse :: Int -> PutLexiconResponse
newPutLexiconResponse Int
pHttpStatus_ =
  PutLexiconResponse' {$sel:httpStatus:PutLexiconResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData PutLexiconResponse where
  rnf :: PutLexiconResponse -> ()
rnf PutLexiconResponse' {Int
httpStatus :: Int
$sel:httpStatus:PutLexiconResponse' :: PutLexiconResponse -> Int
..} = forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus