{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SES.Types.Template
-- 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)
module Amazonka.SES.Types.Template where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The content of the email, composed of a subject line, an HTML part, and
-- a text-only part.
--
-- /See:/ 'newTemplate' smart constructor.
data Template = Template'
  { -- | The email body that will be visible to recipients whose email clients do
    -- not display HTML.
    Template -> Maybe Text
textPart :: Prelude.Maybe Prelude.Text,
    -- | The subject line of the email.
    Template -> Maybe Text
subjectPart :: Prelude.Maybe Prelude.Text,
    -- | The HTML body of the email.
    Template -> Maybe Text
htmlPart :: Prelude.Maybe Prelude.Text,
    -- | The name of the template. You will refer to this name when you send
    -- email using the @SendTemplatedEmail@ or @SendBulkTemplatedEmail@
    -- operations.
    Template -> Text
templateName :: Prelude.Text
  }
  deriving (Template -> Template -> Bool
(Template -> Template -> Bool)
-> (Template -> Template -> Bool) -> Eq Template
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Template -> Template -> Bool
$c/= :: Template -> Template -> Bool
== :: Template -> Template -> Bool
$c== :: Template -> Template -> Bool
Prelude.Eq, ReadPrec [Template]
ReadPrec Template
Int -> ReadS Template
ReadS [Template]
(Int -> ReadS Template)
-> ReadS [Template]
-> ReadPrec Template
-> ReadPrec [Template]
-> Read Template
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Template]
$creadListPrec :: ReadPrec [Template]
readPrec :: ReadPrec Template
$creadPrec :: ReadPrec Template
readList :: ReadS [Template]
$creadList :: ReadS [Template]
readsPrec :: Int -> ReadS Template
$creadsPrec :: Int -> ReadS Template
Prelude.Read, Int -> Template -> ShowS
[Template] -> ShowS
Template -> String
(Int -> Template -> ShowS)
-> (Template -> String) -> ([Template] -> ShowS) -> Show Template
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Template] -> ShowS
$cshowList :: [Template] -> ShowS
show :: Template -> String
$cshow :: Template -> String
showsPrec :: Int -> Template -> ShowS
$cshowsPrec :: Int -> Template -> ShowS
Prelude.Show, (forall x. Template -> Rep Template x)
-> (forall x. Rep Template x -> Template) -> Generic Template
forall x. Rep Template x -> Template
forall x. Template -> Rep Template x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Template x -> Template
$cfrom :: forall x. Template -> Rep Template x
Prelude.Generic)

-- |
-- Create a value of 'Template' 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:
--
-- 'textPart', 'template_textPart' - The email body that will be visible to recipients whose email clients do
-- not display HTML.
--
-- 'subjectPart', 'template_subjectPart' - The subject line of the email.
--
-- 'htmlPart', 'template_htmlPart' - The HTML body of the email.
--
-- 'templateName', 'template_templateName' - The name of the template. You will refer to this name when you send
-- email using the @SendTemplatedEmail@ or @SendBulkTemplatedEmail@
-- operations.
newTemplate ::
  -- | 'templateName'
  Prelude.Text ->
  Template
newTemplate :: Text -> Template
newTemplate Text
pTemplateName_ =
  Template' :: Maybe Text -> Maybe Text -> Maybe Text -> Text -> Template
Template'
    { $sel:textPart:Template' :: Maybe Text
textPart = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:subjectPart:Template' :: Maybe Text
subjectPart = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:htmlPart:Template' :: Maybe Text
htmlPart = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:templateName:Template' :: Text
templateName = Text
pTemplateName_
    }

-- | The email body that will be visible to recipients whose email clients do
-- not display HTML.
template_textPart :: Lens.Lens' Template (Prelude.Maybe Prelude.Text)
template_textPart :: (Maybe Text -> f (Maybe Text)) -> Template -> f Template
template_textPart = (Template -> Maybe Text)
-> (Template -> Maybe Text -> Template)
-> Lens Template Template (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Template' {Maybe Text
textPart :: Maybe Text
$sel:textPart:Template' :: Template -> Maybe Text
textPart} -> Maybe Text
textPart) (\s :: Template
s@Template' {} Maybe Text
a -> Template
s {$sel:textPart:Template' :: Maybe Text
textPart = Maybe Text
a} :: Template)

-- | The subject line of the email.
template_subjectPart :: Lens.Lens' Template (Prelude.Maybe Prelude.Text)
template_subjectPart :: (Maybe Text -> f (Maybe Text)) -> Template -> f Template
template_subjectPart = (Template -> Maybe Text)
-> (Template -> Maybe Text -> Template)
-> Lens Template Template (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Template' {Maybe Text
subjectPart :: Maybe Text
$sel:subjectPart:Template' :: Template -> Maybe Text
subjectPart} -> Maybe Text
subjectPart) (\s :: Template
s@Template' {} Maybe Text
a -> Template
s {$sel:subjectPart:Template' :: Maybe Text
subjectPart = Maybe Text
a} :: Template)

-- | The HTML body of the email.
template_htmlPart :: Lens.Lens' Template (Prelude.Maybe Prelude.Text)
template_htmlPart :: (Maybe Text -> f (Maybe Text)) -> Template -> f Template
template_htmlPart = (Template -> Maybe Text)
-> (Template -> Maybe Text -> Template)
-> Lens Template Template (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Template' {Maybe Text
htmlPart :: Maybe Text
$sel:htmlPart:Template' :: Template -> Maybe Text
htmlPart} -> Maybe Text
htmlPart) (\s :: Template
s@Template' {} Maybe Text
a -> Template
s {$sel:htmlPart:Template' :: Maybe Text
htmlPart = Maybe Text
a} :: Template)

-- | The name of the template. You will refer to this name when you send
-- email using the @SendTemplatedEmail@ or @SendBulkTemplatedEmail@
-- operations.
template_templateName :: Lens.Lens' Template Prelude.Text
template_templateName :: (Text -> f Text) -> Template -> f Template
template_templateName = (Template -> Text)
-> (Template -> Text -> Template)
-> Lens Template Template Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Template' {Text
templateName :: Text
$sel:templateName:Template' :: Template -> Text
templateName} -> Text
templateName) (\s :: Template
s@Template' {} Text
a -> Template
s {$sel:templateName:Template' :: Text
templateName = Text
a} :: Template)

instance Core.FromXML Template where
  parseXML :: [Node] -> Either String Template
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> Maybe Text -> Text -> Template
Template'
      (Maybe Text -> Maybe Text -> Maybe Text -> Text -> Template)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Maybe Text -> Text -> Template)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"TextPart")
      Either String (Maybe Text -> Maybe Text -> Text -> Template)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Text -> Template)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"SubjectPart")
      Either String (Maybe Text -> Text -> Template)
-> Either String (Maybe Text) -> Either String (Text -> Template)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"HtmlPart")
      Either String (Text -> Template)
-> Either String Text -> Either String Template
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"TemplateName")

instance Prelude.Hashable Template

instance Prelude.NFData Template

instance Core.ToQuery Template where
  toQuery :: Template -> QueryString
toQuery Template' {Maybe Text
Text
templateName :: Text
htmlPart :: Maybe Text
subjectPart :: Maybe Text
textPart :: Maybe Text
$sel:templateName:Template' :: Template -> Text
$sel:htmlPart:Template' :: Template -> Maybe Text
$sel:subjectPart:Template' :: Template -> Maybe Text
$sel:textPart:Template' :: Template -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"TextPart" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
textPart,
        ByteString
"SubjectPart" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
subjectPart,
        ByteString
"HtmlPart" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
htmlPart,
        ByteString
"TemplateName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
templateName
      ]