{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
      { $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 :: Lens' UpdateEmailTemplate Text
updateEmailTemplate_templateName = 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 :: Lens' UpdateEmailTemplate EmailTemplateContent
updateEmailTemplate_templateContent = 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 :: (Service -> Service)
-> UpdateEmailTemplate -> Request UpdateEmailTemplate
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 UpdateEmailTemplate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateEmailTemplate)))
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 -> UpdateEmailTemplateResponse
UpdateEmailTemplateResponse'
            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 UpdateEmailTemplate where
  hashWithSalt :: Int -> UpdateEmailTemplate -> Int
hashWithSalt Int
_salt UpdateEmailTemplate' {Text
EmailTemplateContent
templateContent :: EmailTemplateContent
templateName :: Text
$sel:templateContent:UpdateEmailTemplate' :: UpdateEmailTemplate -> EmailTemplateContent
$sel:templateName:UpdateEmailTemplate' :: UpdateEmailTemplate -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
templateName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` EmailTemplateContent
templateContent

instance Prelude.NFData UpdateEmailTemplate where
  rnf :: UpdateEmailTemplate -> ()
rnf UpdateEmailTemplate' {Text
EmailTemplateContent
templateContent :: EmailTemplateContent
templateName :: Text
$sel:templateContent:UpdateEmailTemplate' :: UpdateEmailTemplate -> EmailTemplateContent
$sel:templateName:UpdateEmailTemplate' :: UpdateEmailTemplate -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
templateName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf EmailTemplateContent
templateContent

instance Data.ToHeaders UpdateEmailTemplate where
  toHeaders :: UpdateEmailTemplate -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"TemplateContent" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= EmailTemplateContent
templateContent)
          ]
      )

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

instance Data.ToQuery UpdateEmailTemplate where
  toQuery :: UpdateEmailTemplate -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:httpStatus:UpdateEmailTemplateResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

-- | The response's http status code.
updateEmailTemplateResponse_httpStatus :: Lens.Lens' UpdateEmailTemplateResponse Prelude.Int
updateEmailTemplateResponse_httpStatus :: Lens' UpdateEmailTemplateResponse Int
updateEmailTemplateResponse_httpStatus = 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 where
  rnf :: UpdateEmailTemplateResponse -> ()
rnf UpdateEmailTemplateResponse' {Int
httpStatus :: Int
$sel:httpStatus:UpdateEmailTemplateResponse' :: UpdateEmailTemplateResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus