{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.SES.Types.Template 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

-- | 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 HTML body of the email.
    Template -> Maybe Text
htmlPart :: Prelude.Maybe Prelude.Text,
    -- | The subject line of the email.
    Template -> Maybe Text
subjectPart :: Prelude.Maybe Prelude.Text,
    -- | 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 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
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]
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
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. 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:
--
-- 'htmlPart', 'template_htmlPart' - The HTML body of the email.
--
-- 'subjectPart', 'template_subjectPart' - The subject line of the email.
--
-- 'textPart', 'template_textPart' - The email body that will be visible to recipients whose email clients do
-- not display HTML.
--
-- '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'
    { $sel:htmlPart:Template' :: Maybe Text
htmlPart = forall a. Maybe a
Prelude.Nothing,
      $sel:subjectPart:Template' :: Maybe Text
subjectPart = forall a. Maybe a
Prelude.Nothing,
      $sel:textPart:Template' :: Maybe Text
textPart = forall a. Maybe a
Prelude.Nothing,
      $sel:templateName:Template' :: Text
templateName = Text
pTemplateName_
    }

-- | The HTML body of the email.
template_htmlPart :: Lens.Lens' Template (Prelude.Maybe Prelude.Text)
template_htmlPart :: Lens' Template (Maybe Text)
template_htmlPart = 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 subject line of the email.
template_subjectPart :: Lens.Lens' Template (Prelude.Maybe Prelude.Text)
template_subjectPart :: Lens' Template (Maybe Text)
template_subjectPart = 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 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 :: Lens' Template (Maybe Text)
template_textPart = 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 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 :: Lens' Template Text
template_templateName = 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 Data.FromXML Template where
  parseXML :: [Node] -> Either String Template
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> Maybe Text -> Text -> Template
Template'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"HtmlPart")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"SubjectPart")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"TextPart")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"TemplateName")

instance Prelude.Hashable Template where
  hashWithSalt :: Int -> Template -> Int
hashWithSalt Int
_salt Template' {Maybe Text
Text
templateName :: Text
textPart :: Maybe Text
subjectPart :: Maybe Text
htmlPart :: Maybe Text
$sel:templateName:Template' :: Template -> Text
$sel:textPart:Template' :: Template -> Maybe Text
$sel:subjectPart:Template' :: Template -> Maybe Text
$sel:htmlPart:Template' :: Template -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
htmlPart
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
subjectPart
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
textPart
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
templateName

instance Prelude.NFData Template where
  rnf :: Template -> ()
rnf Template' {Maybe Text
Text
templateName :: Text
textPart :: Maybe Text
subjectPart :: Maybe Text
htmlPart :: Maybe Text
$sel:templateName:Template' :: Template -> Text
$sel:textPart:Template' :: Template -> Maybe Text
$sel:subjectPart:Template' :: Template -> Maybe Text
$sel:htmlPart:Template' :: Template -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
htmlPart
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
subjectPart
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
textPart
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
templateName

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