{-# 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-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)
--
-- 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.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:/ '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 :: Core.Sensitive Prelude.Text
  }
  deriving (PutLexicon -> PutLexicon -> Bool
(PutLexicon -> PutLexicon -> Bool)
-> (PutLexicon -> PutLexicon -> Bool) -> Eq PutLexicon
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
(Int -> PutLexicon -> ShowS)
-> (PutLexicon -> String)
-> ([PutLexicon] -> ShowS)
-> Show PutLexicon
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. PutLexicon -> Rep PutLexicon x)
-> (forall x. Rep PutLexicon x -> PutLexicon) -> Generic PutLexicon
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' :: Text -> Sensitive Text -> PutLexicon
PutLexicon'
    { $sel:name:PutLexicon' :: Text
name = Text
pName_,
      $sel:content:PutLexicon' :: Sensitive Text
content = 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
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 :: (Text -> f Text) -> PutLexicon -> f PutLexicon
putLexicon_name = (PutLexicon -> Text)
-> (PutLexicon -> Text -> PutLexicon)
-> Lens PutLexicon PutLexicon Text Text
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 :: (Text -> f Text) -> PutLexicon -> f PutLexicon
putLexicon_content = (PutLexicon -> Sensitive Text)
-> (PutLexicon -> Sensitive Text -> PutLexicon)
-> Lens PutLexicon PutLexicon (Sensitive Text) (Sensitive Text)
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) ((Sensitive Text -> f (Sensitive Text))
 -> PutLexicon -> f PutLexicon)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> PutLexicon
-> f PutLexicon
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 PutLexicon where
  type AWSResponse PutLexicon = PutLexiconResponse
  request :: PutLexicon -> Request PutLexicon
request = Service -> PutLexicon -> Request PutLexicon
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutLexicon
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutLexicon)))
response =
    (Int
 -> ResponseHeaders -> () -> Either String (AWSResponse PutLexicon))
-> Logger
-> Service
-> Proxy PutLexicon
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutLexicon)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> PutLexiconResponse
PutLexiconResponse'
            (Int -> PutLexiconResponse)
-> Either String Int -> Either String PutLexiconResponse
forall (f :: * -> *) a b. Functor 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 PutLexicon

instance Prelude.NFData PutLexicon

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

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Content" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
content)]
      )

instance Core.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
..} =
    [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 PutLexicon where
  toQuery :: PutLexicon -> QueryString
toQuery = QueryString -> PutLexicon -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(PutLexiconResponse -> PutLexiconResponse -> Bool)
-> (PutLexiconResponse -> PutLexiconResponse -> Bool)
-> Eq PutLexiconResponse
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]
(Int -> ReadS PutLexiconResponse)
-> ReadS [PutLexiconResponse]
-> ReadPrec PutLexiconResponse
-> ReadPrec [PutLexiconResponse]
-> Read 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
(Int -> PutLexiconResponse -> ShowS)
-> (PutLexiconResponse -> String)
-> ([PutLexiconResponse] -> ShowS)
-> Show PutLexiconResponse
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. PutLexiconResponse -> Rep PutLexiconResponse x)
-> (forall x. Rep PutLexiconResponse x -> PutLexiconResponse)
-> Generic PutLexiconResponse
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' :: Int -> PutLexiconResponse
PutLexiconResponse' {$sel:httpStatus:PutLexiconResponse' :: Int
httpStatus = Int
pHttpStatus_}

-- | The response's http status code.
putLexiconResponse_httpStatus :: Lens.Lens' PutLexiconResponse Prelude.Int
putLexiconResponse_httpStatus :: (Int -> f Int) -> PutLexiconResponse -> f PutLexiconResponse
putLexiconResponse_httpStatus = (PutLexiconResponse -> Int)
-> (PutLexiconResponse -> Int -> PutLexiconResponse)
-> Lens PutLexiconResponse PutLexiconResponse Int Int
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