{-# 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.SESV2.UpdateEmailTemplate
-- 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)
--
-- Updates an email template. Email templates enable you to send
-- personalized email to one or more destinations in a single API
-- operation. For more information, see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-personalized-email-api.html Amazon SES Developer Guide>.
--
-- You can execute this operation no more than once per second.
module Amazonka.SESV2.UpdateEmailTemplate
  ( -- * Creating a Request
    UpdateEmailTemplate (..),
    newUpdateEmailTemplate,

    -- * Request Lenses
    updateEmailTemplate_templateName,
    updateEmailTemplate_templateContent,

    -- * Destructuring the Response
    UpdateEmailTemplateResponse (..),
    newUpdateEmailTemplateResponse,

    -- * Response Lenses
    updateEmailTemplateResponse_httpStatus,
  )
where

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
import Amazonka.SESV2.Types

-- | Represents a request to update an email template. For more information,
-- see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-personalized-email-api.html Amazon SES Developer Guide>.
--
-- /See:/ 'newUpdateEmailTemplate' smart constructor.
data UpdateEmailTemplate = UpdateEmailTemplate'
  { -- | The name of the template.
    UpdateEmailTemplate -> Text
templateName :: Prelude.Text,
    -- | The content of the email template, composed of a subject line, an HTML
    -- part, and a text-only part.
    UpdateEmailTemplate -> EmailTemplateContent
templateContent :: EmailTemplateContent
  }
  deriving (UpdateEmailTemplate -> UpdateEmailTemplate -> Bool
(UpdateEmailTemplate -> UpdateEmailTemplate -> Bool)
-> (UpdateEmailTemplate -> UpdateEmailTemplate -> Bool)
-> Eq UpdateEmailTemplate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateEmailTemplate -> UpdateEmailTemplate -> Bool
$c/= :: UpdateEmailTemplate -> UpdateEmailTemplate -> Bool
== :: UpdateEmailTemplate -> UpdateEmailTemplate -> Bool
$c== :: UpdateEmailTemplate -> UpdateEmailTemplate -> Bool
Prelude.Eq, ReadPrec [UpdateEmailTemplate]
ReadPrec UpdateEmailTemplate
Int -> ReadS UpdateEmailTemplate
ReadS [UpdateEmailTemplate]
(Int -> ReadS UpdateEmailTemplate)
-> ReadS [UpdateEmailTemplate]
-> ReadPrec UpdateEmailTemplate
-> ReadPrec [UpdateEmailTemplate]
-> Read UpdateEmailTemplate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateEmailTemplate]
$creadListPrec :: ReadPrec [UpdateEmailTemplate]
readPrec :: ReadPrec UpdateEmailTemplate
$creadPrec :: ReadPrec UpdateEmailTemplate
readList :: ReadS [UpdateEmailTemplate]
$creadList :: ReadS [UpdateEmailTemplate]
readsPrec :: Int -> ReadS UpdateEmailTemplate
$creadsPrec :: Int -> ReadS UpdateEmailTemplate
Prelude.Read, Int -> UpdateEmailTemplate -> ShowS
[UpdateEmailTemplate] -> ShowS
UpdateEmailTemplate -> String
(Int -> UpdateEmailTemplate -> ShowS)
-> (UpdateEmailTemplate -> String)
-> ([UpdateEmailTemplate] -> ShowS)
-> Show UpdateEmailTemplate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateEmailTemplate] -> ShowS
$cshowList :: [UpdateEmailTemplate] -> ShowS
show :: UpdateEmailTemplate -> String
$cshow :: UpdateEmailTemplate -> String
showsPrec :: Int -> UpdateEmailTemplate -> ShowS
$cshowsPrec :: Int -> UpdateEmailTemplate -> ShowS
Prelude.Show, (forall x. UpdateEmailTemplate -> Rep UpdateEmailTemplate x)
-> (forall x. Rep UpdateEmailTemplate x -> UpdateEmailTemplate)
-> Generic UpdateEmailTemplate
forall x. Rep UpdateEmailTemplate x -> UpdateEmailTemplate
forall x. UpdateEmailTemplate -> Rep UpdateEmailTemplate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateEmailTemplate x -> UpdateEmailTemplate
$cfrom :: forall x. UpdateEmailTemplate -> Rep UpdateEmailTemplate x
Prelude.Generic)

-- |
-- Create a value of 'UpdateEmailTemplate' 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:
--
-- 'templateName', 'updateEmailTemplate_templateName' - The name of the template.
--
-- 'templateContent', 'updateEmailTemplate_templateContent' - The content of the email template, composed of a subject line, an HTML
-- part, and a text-only part.
newUpdateEmailTemplate ::
  -- | 'templateName'
  Prelude.Text ->
  -- | 'templateContent'
  EmailTemplateContent ->
  UpdateEmailTemplate
newUpdateEmailTemplate :: Text -> EmailTemplateContent -> UpdateEmailTemplate
newUpdateEmailTemplate
  Text
pTemplateName_
  EmailTemplateContent
pTemplateContent_ =
    UpdateEmailTemplate' :: Text -> EmailTemplateContent -> UpdateEmailTemplate
UpdateEmailTemplate'
      { $sel:templateName:UpdateEmailTemplate' :: Text
templateName = Text
pTemplateName_,
        $sel:templateContent:UpdateEmailTemplate' :: EmailTemplateContent
templateContent = EmailTemplateContent
pTemplateContent_
      }

-- | The name of the template.
updateEmailTemplate_templateName :: Lens.Lens' UpdateEmailTemplate Prelude.Text
updateEmailTemplate_templateName :: (Text -> f Text) -> UpdateEmailTemplate -> f UpdateEmailTemplate
updateEmailTemplate_templateName = (UpdateEmailTemplate -> Text)
-> (UpdateEmailTemplate -> Text -> UpdateEmailTemplate)
-> Lens UpdateEmailTemplate UpdateEmailTemplate Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateEmailTemplate' {Text
templateName :: Text
$sel:templateName:UpdateEmailTemplate' :: UpdateEmailTemplate -> Text
templateName} -> Text
templateName) (\s :: UpdateEmailTemplate
s@UpdateEmailTemplate' {} Text
a -> UpdateEmailTemplate
s {$sel:templateName:UpdateEmailTemplate' :: Text
templateName = Text
a} :: UpdateEmailTemplate)

-- | The content of the email template, composed of a subject line, an HTML
-- part, and a text-only part.
updateEmailTemplate_templateContent :: Lens.Lens' UpdateEmailTemplate EmailTemplateContent
updateEmailTemplate_templateContent :: (EmailTemplateContent -> f EmailTemplateContent)
-> UpdateEmailTemplate -> f UpdateEmailTemplate
updateEmailTemplate_templateContent = (UpdateEmailTemplate -> EmailTemplateContent)
-> (UpdateEmailTemplate
    -> EmailTemplateContent -> UpdateEmailTemplate)
-> Lens
     UpdateEmailTemplate
     UpdateEmailTemplate
     EmailTemplateContent
     EmailTemplateContent
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateEmailTemplate' {EmailTemplateContent
templateContent :: EmailTemplateContent
$sel:templateContent:UpdateEmailTemplate' :: UpdateEmailTemplate -> EmailTemplateContent
templateContent} -> EmailTemplateContent
templateContent) (\s :: UpdateEmailTemplate
s@UpdateEmailTemplate' {} EmailTemplateContent
a -> UpdateEmailTemplate
s {$sel:templateContent:UpdateEmailTemplate' :: EmailTemplateContent
templateContent = EmailTemplateContent
a} :: UpdateEmailTemplate)

instance Core.AWSRequest UpdateEmailTemplate where
  type
    AWSResponse UpdateEmailTemplate =
      UpdateEmailTemplateResponse
  request :: UpdateEmailTemplate -> Request UpdateEmailTemplate
request = Service -> UpdateEmailTemplate -> Request UpdateEmailTemplate
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateEmailTemplate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateEmailTemplate)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse UpdateEmailTemplate))
-> Logger
-> Service
-> Proxy UpdateEmailTemplate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateEmailTemplate)))
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 -> UpdateEmailTemplateResponse
UpdateEmailTemplateResponse'
            (Int -> UpdateEmailTemplateResponse)
-> Either String Int -> Either String UpdateEmailTemplateResponse
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 UpdateEmailTemplate

instance Prelude.NFData UpdateEmailTemplate

instance Core.ToHeaders UpdateEmailTemplate where
  toHeaders :: UpdateEmailTemplate -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateEmailTemplate -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 UpdateEmailTemplate where
  toJSON :: UpdateEmailTemplate -> Value
toJSON UpdateEmailTemplate' {Text
EmailTemplateContent
templateContent :: EmailTemplateContent
templateName :: Text
$sel:templateContent:UpdateEmailTemplate' :: UpdateEmailTemplate -> EmailTemplateContent
$sel:templateName:UpdateEmailTemplate' :: UpdateEmailTemplate -> 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
"TemplateContent" Text -> EmailTemplateContent -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= EmailTemplateContent
templateContent)
          ]
      )

instance Core.ToPath UpdateEmailTemplate where
  toPath :: UpdateEmailTemplate -> ByteString
toPath UpdateEmailTemplate' {Text
EmailTemplateContent
templateContent :: EmailTemplateContent
templateName :: Text
$sel:templateContent:UpdateEmailTemplate' :: UpdateEmailTemplate -> EmailTemplateContent
$sel:templateName:UpdateEmailTemplate' :: UpdateEmailTemplate -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/v2/email/templates/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
templateName]

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

-- | If the action is successful, the service sends back an HTTP 200 response
-- with an empty HTTP body.
--
-- /See:/ 'newUpdateEmailTemplateResponse' smart constructor.
data UpdateEmailTemplateResponse = UpdateEmailTemplateResponse'
  { -- | The response's http status code.
    UpdateEmailTemplateResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (UpdateEmailTemplateResponse -> UpdateEmailTemplateResponse -> Bool
(UpdateEmailTemplateResponse
 -> UpdateEmailTemplateResponse -> Bool)
-> (UpdateEmailTemplateResponse
    -> UpdateEmailTemplateResponse -> Bool)
-> Eq UpdateEmailTemplateResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateEmailTemplateResponse -> UpdateEmailTemplateResponse -> Bool
$c/= :: UpdateEmailTemplateResponse -> UpdateEmailTemplateResponse -> Bool
== :: UpdateEmailTemplateResponse -> UpdateEmailTemplateResponse -> Bool
$c== :: UpdateEmailTemplateResponse -> UpdateEmailTemplateResponse -> Bool
Prelude.Eq, ReadPrec [UpdateEmailTemplateResponse]
ReadPrec UpdateEmailTemplateResponse
Int -> ReadS UpdateEmailTemplateResponse
ReadS [UpdateEmailTemplateResponse]
(Int -> ReadS UpdateEmailTemplateResponse)
-> ReadS [UpdateEmailTemplateResponse]
-> ReadPrec UpdateEmailTemplateResponse
-> ReadPrec [UpdateEmailTemplateResponse]
-> Read UpdateEmailTemplateResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateEmailTemplateResponse]
$creadListPrec :: ReadPrec [UpdateEmailTemplateResponse]
readPrec :: ReadPrec UpdateEmailTemplateResponse
$creadPrec :: ReadPrec UpdateEmailTemplateResponse
readList :: ReadS [UpdateEmailTemplateResponse]
$creadList :: ReadS [UpdateEmailTemplateResponse]
readsPrec :: Int -> ReadS UpdateEmailTemplateResponse
$creadsPrec :: Int -> ReadS UpdateEmailTemplateResponse
Prelude.Read, Int -> UpdateEmailTemplateResponse -> ShowS
[UpdateEmailTemplateResponse] -> ShowS
UpdateEmailTemplateResponse -> String
(Int -> UpdateEmailTemplateResponse -> ShowS)
-> (UpdateEmailTemplateResponse -> String)
-> ([UpdateEmailTemplateResponse] -> ShowS)
-> Show UpdateEmailTemplateResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateEmailTemplateResponse] -> ShowS
$cshowList :: [UpdateEmailTemplateResponse] -> ShowS
show :: UpdateEmailTemplateResponse -> String
$cshow :: UpdateEmailTemplateResponse -> String
showsPrec :: Int -> UpdateEmailTemplateResponse -> ShowS
$cshowsPrec :: Int -> UpdateEmailTemplateResponse -> ShowS
Prelude.Show, (forall x.
 UpdateEmailTemplateResponse -> Rep UpdateEmailTemplateResponse x)
-> (forall x.
    Rep UpdateEmailTemplateResponse x -> UpdateEmailTemplateResponse)
-> Generic UpdateEmailTemplateResponse
forall x.
Rep UpdateEmailTemplateResponse x -> UpdateEmailTemplateResponse
forall x.
UpdateEmailTemplateResponse -> Rep UpdateEmailTemplateResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdateEmailTemplateResponse x -> UpdateEmailTemplateResponse
$cfrom :: forall x.
UpdateEmailTemplateResponse -> Rep UpdateEmailTemplateResponse x
Prelude.Generic)

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

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

instance Prelude.NFData UpdateEmailTemplateResponse