{-# 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.CreateEmailTemplate
-- 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)
--
-- Creates 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.CreateEmailTemplate
  ( -- * Creating a Request
    CreateEmailTemplate (..),
    newCreateEmailTemplate,

    -- * Request Lenses
    createEmailTemplate_templateName,
    createEmailTemplate_templateContent,

    -- * Destructuring the Response
    CreateEmailTemplateResponse (..),
    newCreateEmailTemplateResponse,

    -- * Response Lenses
    createEmailTemplateResponse_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 create 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:/ 'newCreateEmailTemplate' smart constructor.
data CreateEmailTemplate = CreateEmailTemplate'
  { -- | The name of the template.
    CreateEmailTemplate -> Text
templateName :: Prelude.Text,
    -- | The content of the email template, composed of a subject line, an HTML
    -- part, and a text-only part.
    CreateEmailTemplate -> EmailTemplateContent
templateContent :: EmailTemplateContent
  }
  deriving (CreateEmailTemplate -> CreateEmailTemplate -> Bool
(CreateEmailTemplate -> CreateEmailTemplate -> Bool)
-> (CreateEmailTemplate -> CreateEmailTemplate -> Bool)
-> Eq CreateEmailTemplate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateEmailTemplate -> CreateEmailTemplate -> Bool
$c/= :: CreateEmailTemplate -> CreateEmailTemplate -> Bool
== :: CreateEmailTemplate -> CreateEmailTemplate -> Bool
$c== :: CreateEmailTemplate -> CreateEmailTemplate -> Bool
Prelude.Eq, ReadPrec [CreateEmailTemplate]
ReadPrec CreateEmailTemplate
Int -> ReadS CreateEmailTemplate
ReadS [CreateEmailTemplate]
(Int -> ReadS CreateEmailTemplate)
-> ReadS [CreateEmailTemplate]
-> ReadPrec CreateEmailTemplate
-> ReadPrec [CreateEmailTemplate]
-> Read CreateEmailTemplate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateEmailTemplate]
$creadListPrec :: ReadPrec [CreateEmailTemplate]
readPrec :: ReadPrec CreateEmailTemplate
$creadPrec :: ReadPrec CreateEmailTemplate
readList :: ReadS [CreateEmailTemplate]
$creadList :: ReadS [CreateEmailTemplate]
readsPrec :: Int -> ReadS CreateEmailTemplate
$creadsPrec :: Int -> ReadS CreateEmailTemplate
Prelude.Read, Int -> CreateEmailTemplate -> ShowS
[CreateEmailTemplate] -> ShowS
CreateEmailTemplate -> String
(Int -> CreateEmailTemplate -> ShowS)
-> (CreateEmailTemplate -> String)
-> ([CreateEmailTemplate] -> ShowS)
-> Show CreateEmailTemplate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateEmailTemplate] -> ShowS
$cshowList :: [CreateEmailTemplate] -> ShowS
show :: CreateEmailTemplate -> String
$cshow :: CreateEmailTemplate -> String
showsPrec :: Int -> CreateEmailTemplate -> ShowS
$cshowsPrec :: Int -> CreateEmailTemplate -> ShowS
Prelude.Show, (forall x. CreateEmailTemplate -> Rep CreateEmailTemplate x)
-> (forall x. Rep CreateEmailTemplate x -> CreateEmailTemplate)
-> Generic CreateEmailTemplate
forall x. Rep CreateEmailTemplate x -> CreateEmailTemplate
forall x. CreateEmailTemplate -> Rep CreateEmailTemplate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateEmailTemplate x -> CreateEmailTemplate
$cfrom :: forall x. CreateEmailTemplate -> Rep CreateEmailTemplate x
Prelude.Generic)

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

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

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

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

instance Prelude.NFData CreateEmailTemplate

instance Core.ToHeaders CreateEmailTemplate where
  toHeaders :: CreateEmailTemplate -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateEmailTemplate -> 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 CreateEmailTemplate where
  toJSON :: CreateEmailTemplate -> Value
toJSON CreateEmailTemplate' {Text
EmailTemplateContent
templateContent :: EmailTemplateContent
templateName :: Text
$sel:templateContent:CreateEmailTemplate' :: CreateEmailTemplate -> EmailTemplateContent
$sel:templateName:CreateEmailTemplate' :: CreateEmailTemplate -> 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
"TemplateName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
templateName),
            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 CreateEmailTemplate where
  toPath :: CreateEmailTemplate -> ByteString
toPath = ByteString -> CreateEmailTemplate -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/v2/email/templates"

instance Core.ToQuery CreateEmailTemplate where
  toQuery :: CreateEmailTemplate -> QueryString
toQuery = QueryString -> CreateEmailTemplate -> 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:/ 'newCreateEmailTemplateResponse' smart constructor.
data CreateEmailTemplateResponse = CreateEmailTemplateResponse'
  { -- | The response's http status code.
    CreateEmailTemplateResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateEmailTemplateResponse -> CreateEmailTemplateResponse -> Bool
(CreateEmailTemplateResponse
 -> CreateEmailTemplateResponse -> Bool)
-> (CreateEmailTemplateResponse
    -> CreateEmailTemplateResponse -> Bool)
-> Eq CreateEmailTemplateResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateEmailTemplateResponse -> CreateEmailTemplateResponse -> Bool
$c/= :: CreateEmailTemplateResponse -> CreateEmailTemplateResponse -> Bool
== :: CreateEmailTemplateResponse -> CreateEmailTemplateResponse -> Bool
$c== :: CreateEmailTemplateResponse -> CreateEmailTemplateResponse -> Bool
Prelude.Eq, ReadPrec [CreateEmailTemplateResponse]
ReadPrec CreateEmailTemplateResponse
Int -> ReadS CreateEmailTemplateResponse
ReadS [CreateEmailTemplateResponse]
(Int -> ReadS CreateEmailTemplateResponse)
-> ReadS [CreateEmailTemplateResponse]
-> ReadPrec CreateEmailTemplateResponse
-> ReadPrec [CreateEmailTemplateResponse]
-> Read CreateEmailTemplateResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateEmailTemplateResponse]
$creadListPrec :: ReadPrec [CreateEmailTemplateResponse]
readPrec :: ReadPrec CreateEmailTemplateResponse
$creadPrec :: ReadPrec CreateEmailTemplateResponse
readList :: ReadS [CreateEmailTemplateResponse]
$creadList :: ReadS [CreateEmailTemplateResponse]
readsPrec :: Int -> ReadS CreateEmailTemplateResponse
$creadsPrec :: Int -> ReadS CreateEmailTemplateResponse
Prelude.Read, Int -> CreateEmailTemplateResponse -> ShowS
[CreateEmailTemplateResponse] -> ShowS
CreateEmailTemplateResponse -> String
(Int -> CreateEmailTemplateResponse -> ShowS)
-> (CreateEmailTemplateResponse -> String)
-> ([CreateEmailTemplateResponse] -> ShowS)
-> Show CreateEmailTemplateResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateEmailTemplateResponse] -> ShowS
$cshowList :: [CreateEmailTemplateResponse] -> ShowS
show :: CreateEmailTemplateResponse -> String
$cshow :: CreateEmailTemplateResponse -> String
showsPrec :: Int -> CreateEmailTemplateResponse -> ShowS
$cshowsPrec :: Int -> CreateEmailTemplateResponse -> ShowS
Prelude.Show, (forall x.
 CreateEmailTemplateResponse -> Rep CreateEmailTemplateResponse x)
-> (forall x.
    Rep CreateEmailTemplateResponse x -> CreateEmailTemplateResponse)
-> Generic CreateEmailTemplateResponse
forall x.
Rep CreateEmailTemplateResponse x -> CreateEmailTemplateResponse
forall x.
CreateEmailTemplateResponse -> Rep CreateEmailTemplateResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateEmailTemplateResponse x -> CreateEmailTemplateResponse
$cfrom :: forall x.
CreateEmailTemplateResponse -> Rep CreateEmailTemplateResponse x
Prelude.Generic)

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

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

instance Prelude.NFData CreateEmailTemplateResponse