{-# 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.Pinpoint.Types.EmailMessage
-- 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.Pinpoint.Types.EmailMessage where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.RawEmail
import Amazonka.Pinpoint.Types.SimpleEmail
import qualified Amazonka.Prelude as Prelude

-- | Specifies the default settings and content for a one-time email message
-- that\'s sent directly to an endpoint.
--
-- /See:/ 'newEmailMessage' smart constructor.
data EmailMessage = EmailMessage'
  { -- | The default message variables to use in the email message. You can
    -- override the default variables with individual address variables.
    EmailMessage -> Maybe (HashMap Text [Text])
substitutions :: Prelude.Maybe (Prelude.HashMap Prelude.Text [Prelude.Text]),
    -- | The body of the email message.
    EmailMessage -> Maybe Text
body :: Prelude.Maybe Prelude.Text,
    -- | The verified email address to send the email message from. The default
    -- value is the FromAddress specified for the email channel.
    EmailMessage -> Maybe Text
fromAddress :: Prelude.Maybe Prelude.Text,
    -- | The email message, represented as a raw MIME message.
    EmailMessage -> Maybe RawEmail
rawEmail :: Prelude.Maybe RawEmail,
    -- | The email address to forward bounces and complaints to, if feedback
    -- forwarding is enabled.
    EmailMessage -> Maybe Text
feedbackForwardingAddress :: Prelude.Maybe Prelude.Text,
    -- | The email message, composed of a subject, a text part, and an HTML part.
    EmailMessage -> Maybe SimpleEmail
simpleEmail :: Prelude.Maybe SimpleEmail,
    -- | The reply-to email address(es) for the email message. If a recipient
    -- replies to the email, each reply-to address receives the reply.
    EmailMessage -> Maybe [Text]
replyToAddresses :: Prelude.Maybe [Prelude.Text]
  }
  deriving (EmailMessage -> EmailMessage -> Bool
(EmailMessage -> EmailMessage -> Bool)
-> (EmailMessage -> EmailMessage -> Bool) -> Eq EmailMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EmailMessage -> EmailMessage -> Bool
$c/= :: EmailMessage -> EmailMessage -> Bool
== :: EmailMessage -> EmailMessage -> Bool
$c== :: EmailMessage -> EmailMessage -> Bool
Prelude.Eq, ReadPrec [EmailMessage]
ReadPrec EmailMessage
Int -> ReadS EmailMessage
ReadS [EmailMessage]
(Int -> ReadS EmailMessage)
-> ReadS [EmailMessage]
-> ReadPrec EmailMessage
-> ReadPrec [EmailMessage]
-> Read EmailMessage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EmailMessage]
$creadListPrec :: ReadPrec [EmailMessage]
readPrec :: ReadPrec EmailMessage
$creadPrec :: ReadPrec EmailMessage
readList :: ReadS [EmailMessage]
$creadList :: ReadS [EmailMessage]
readsPrec :: Int -> ReadS EmailMessage
$creadsPrec :: Int -> ReadS EmailMessage
Prelude.Read, Int -> EmailMessage -> ShowS
[EmailMessage] -> ShowS
EmailMessage -> String
(Int -> EmailMessage -> ShowS)
-> (EmailMessage -> String)
-> ([EmailMessage] -> ShowS)
-> Show EmailMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EmailMessage] -> ShowS
$cshowList :: [EmailMessage] -> ShowS
show :: EmailMessage -> String
$cshow :: EmailMessage -> String
showsPrec :: Int -> EmailMessage -> ShowS
$cshowsPrec :: Int -> EmailMessage -> ShowS
Prelude.Show, (forall x. EmailMessage -> Rep EmailMessage x)
-> (forall x. Rep EmailMessage x -> EmailMessage)
-> Generic EmailMessage
forall x. Rep EmailMessage x -> EmailMessage
forall x. EmailMessage -> Rep EmailMessage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EmailMessage x -> EmailMessage
$cfrom :: forall x. EmailMessage -> Rep EmailMessage x
Prelude.Generic)

-- |
-- Create a value of 'EmailMessage' 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:
--
-- 'substitutions', 'emailMessage_substitutions' - The default message variables to use in the email message. You can
-- override the default variables with individual address variables.
--
-- 'body', 'emailMessage_body' - The body of the email message.
--
-- 'fromAddress', 'emailMessage_fromAddress' - The verified email address to send the email message from. The default
-- value is the FromAddress specified for the email channel.
--
-- 'rawEmail', 'emailMessage_rawEmail' - The email message, represented as a raw MIME message.
--
-- 'feedbackForwardingAddress', 'emailMessage_feedbackForwardingAddress' - The email address to forward bounces and complaints to, if feedback
-- forwarding is enabled.
--
-- 'simpleEmail', 'emailMessage_simpleEmail' - The email message, composed of a subject, a text part, and an HTML part.
--
-- 'replyToAddresses', 'emailMessage_replyToAddresses' - The reply-to email address(es) for the email message. If a recipient
-- replies to the email, each reply-to address receives the reply.
newEmailMessage ::
  EmailMessage
newEmailMessage :: EmailMessage
newEmailMessage =
  EmailMessage' :: Maybe (HashMap Text [Text])
-> Maybe Text
-> Maybe Text
-> Maybe RawEmail
-> Maybe Text
-> Maybe SimpleEmail
-> Maybe [Text]
-> EmailMessage
EmailMessage'
    { $sel:substitutions:EmailMessage' :: Maybe (HashMap Text [Text])
substitutions = Maybe (HashMap Text [Text])
forall a. Maybe a
Prelude.Nothing,
      $sel:body:EmailMessage' :: Maybe Text
body = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:fromAddress:EmailMessage' :: Maybe Text
fromAddress = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:rawEmail:EmailMessage' :: Maybe RawEmail
rawEmail = Maybe RawEmail
forall a. Maybe a
Prelude.Nothing,
      $sel:feedbackForwardingAddress:EmailMessage' :: Maybe Text
feedbackForwardingAddress = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:simpleEmail:EmailMessage' :: Maybe SimpleEmail
simpleEmail = Maybe SimpleEmail
forall a. Maybe a
Prelude.Nothing,
      $sel:replyToAddresses:EmailMessage' :: Maybe [Text]
replyToAddresses = Maybe [Text]
forall a. Maybe a
Prelude.Nothing
    }

-- | The default message variables to use in the email message. You can
-- override the default variables with individual address variables.
emailMessage_substitutions :: Lens.Lens' EmailMessage (Prelude.Maybe (Prelude.HashMap Prelude.Text [Prelude.Text]))
emailMessage_substitutions :: (Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
-> EmailMessage -> f EmailMessage
emailMessage_substitutions = (EmailMessage -> Maybe (HashMap Text [Text]))
-> (EmailMessage -> Maybe (HashMap Text [Text]) -> EmailMessage)
-> Lens
     EmailMessage
     EmailMessage
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [Text]))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EmailMessage' {Maybe (HashMap Text [Text])
substitutions :: Maybe (HashMap Text [Text])
$sel:substitutions:EmailMessage' :: EmailMessage -> Maybe (HashMap Text [Text])
substitutions} -> Maybe (HashMap Text [Text])
substitutions) (\s :: EmailMessage
s@EmailMessage' {} Maybe (HashMap Text [Text])
a -> EmailMessage
s {$sel:substitutions:EmailMessage' :: Maybe (HashMap Text [Text])
substitutions = Maybe (HashMap Text [Text])
a} :: EmailMessage) ((Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
 -> EmailMessage -> f EmailMessage)
-> ((Maybe (HashMap Text [Text])
     -> f (Maybe (HashMap Text [Text])))
    -> Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
-> (Maybe (HashMap Text [Text]) -> f (Maybe (HashMap Text [Text])))
-> EmailMessage
-> f EmailMessage
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
-> Iso
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [Text]))
     (Maybe (HashMap Text [Text]))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
  (HashMap Text [Text])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

-- | The verified email address to send the email message from. The default
-- value is the FromAddress specified for the email channel.
emailMessage_fromAddress :: Lens.Lens' EmailMessage (Prelude.Maybe Prelude.Text)
emailMessage_fromAddress :: (Maybe Text -> f (Maybe Text)) -> EmailMessage -> f EmailMessage
emailMessage_fromAddress = (EmailMessage -> Maybe Text)
-> (EmailMessage -> Maybe Text -> EmailMessage)
-> Lens EmailMessage EmailMessage (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EmailMessage' {Maybe Text
fromAddress :: Maybe Text
$sel:fromAddress:EmailMessage' :: EmailMessage -> Maybe Text
fromAddress} -> Maybe Text
fromAddress) (\s :: EmailMessage
s@EmailMessage' {} Maybe Text
a -> EmailMessage
s {$sel:fromAddress:EmailMessage' :: Maybe Text
fromAddress = Maybe Text
a} :: EmailMessage)

-- | The email message, represented as a raw MIME message.
emailMessage_rawEmail :: Lens.Lens' EmailMessage (Prelude.Maybe RawEmail)
emailMessage_rawEmail :: (Maybe RawEmail -> f (Maybe RawEmail))
-> EmailMessage -> f EmailMessage
emailMessage_rawEmail = (EmailMessage -> Maybe RawEmail)
-> (EmailMessage -> Maybe RawEmail -> EmailMessage)
-> Lens EmailMessage EmailMessage (Maybe RawEmail) (Maybe RawEmail)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EmailMessage' {Maybe RawEmail
rawEmail :: Maybe RawEmail
$sel:rawEmail:EmailMessage' :: EmailMessage -> Maybe RawEmail
rawEmail} -> Maybe RawEmail
rawEmail) (\s :: EmailMessage
s@EmailMessage' {} Maybe RawEmail
a -> EmailMessage
s {$sel:rawEmail:EmailMessage' :: Maybe RawEmail
rawEmail = Maybe RawEmail
a} :: EmailMessage)

-- | The email address to forward bounces and complaints to, if feedback
-- forwarding is enabled.
emailMessage_feedbackForwardingAddress :: Lens.Lens' EmailMessage (Prelude.Maybe Prelude.Text)
emailMessage_feedbackForwardingAddress :: (Maybe Text -> f (Maybe Text)) -> EmailMessage -> f EmailMessage
emailMessage_feedbackForwardingAddress = (EmailMessage -> Maybe Text)
-> (EmailMessage -> Maybe Text -> EmailMessage)
-> Lens EmailMessage EmailMessage (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EmailMessage' {Maybe Text
feedbackForwardingAddress :: Maybe Text
$sel:feedbackForwardingAddress:EmailMessage' :: EmailMessage -> Maybe Text
feedbackForwardingAddress} -> Maybe Text
feedbackForwardingAddress) (\s :: EmailMessage
s@EmailMessage' {} Maybe Text
a -> EmailMessage
s {$sel:feedbackForwardingAddress:EmailMessage' :: Maybe Text
feedbackForwardingAddress = Maybe Text
a} :: EmailMessage)

-- | The email message, composed of a subject, a text part, and an HTML part.
emailMessage_simpleEmail :: Lens.Lens' EmailMessage (Prelude.Maybe SimpleEmail)
emailMessage_simpleEmail :: (Maybe SimpleEmail -> f (Maybe SimpleEmail))
-> EmailMessage -> f EmailMessage
emailMessage_simpleEmail = (EmailMessage -> Maybe SimpleEmail)
-> (EmailMessage -> Maybe SimpleEmail -> EmailMessage)
-> Lens
     EmailMessage EmailMessage (Maybe SimpleEmail) (Maybe SimpleEmail)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EmailMessage' {Maybe SimpleEmail
simpleEmail :: Maybe SimpleEmail
$sel:simpleEmail:EmailMessage' :: EmailMessage -> Maybe SimpleEmail
simpleEmail} -> Maybe SimpleEmail
simpleEmail) (\s :: EmailMessage
s@EmailMessage' {} Maybe SimpleEmail
a -> EmailMessage
s {$sel:simpleEmail:EmailMessage' :: Maybe SimpleEmail
simpleEmail = Maybe SimpleEmail
a} :: EmailMessage)

-- | The reply-to email address(es) for the email message. If a recipient
-- replies to the email, each reply-to address receives the reply.
emailMessage_replyToAddresses :: Lens.Lens' EmailMessage (Prelude.Maybe [Prelude.Text])
emailMessage_replyToAddresses :: (Maybe [Text] -> f (Maybe [Text]))
-> EmailMessage -> f EmailMessage
emailMessage_replyToAddresses = (EmailMessage -> Maybe [Text])
-> (EmailMessage -> Maybe [Text] -> EmailMessage)
-> Lens EmailMessage EmailMessage (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EmailMessage' {Maybe [Text]
replyToAddresses :: Maybe [Text]
$sel:replyToAddresses:EmailMessage' :: EmailMessage -> Maybe [Text]
replyToAddresses} -> Maybe [Text]
replyToAddresses) (\s :: EmailMessage
s@EmailMessage' {} Maybe [Text]
a -> EmailMessage
s {$sel:replyToAddresses:EmailMessage' :: Maybe [Text]
replyToAddresses = Maybe [Text]
a} :: EmailMessage) ((Maybe [Text] -> f (Maybe [Text]))
 -> EmailMessage -> f EmailMessage)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> EmailMessage
-> f EmailMessage
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.Hashable EmailMessage

instance Prelude.NFData EmailMessage

instance Core.ToJSON EmailMessage where
  toJSON :: EmailMessage -> Value
toJSON EmailMessage' {Maybe [Text]
Maybe Text
Maybe (HashMap Text [Text])
Maybe RawEmail
Maybe SimpleEmail
replyToAddresses :: Maybe [Text]
simpleEmail :: Maybe SimpleEmail
feedbackForwardingAddress :: Maybe Text
rawEmail :: Maybe RawEmail
fromAddress :: Maybe Text
body :: Maybe Text
substitutions :: Maybe (HashMap Text [Text])
$sel:replyToAddresses:EmailMessage' :: EmailMessage -> Maybe [Text]
$sel:simpleEmail:EmailMessage' :: EmailMessage -> Maybe SimpleEmail
$sel:feedbackForwardingAddress:EmailMessage' :: EmailMessage -> Maybe Text
$sel:rawEmail:EmailMessage' :: EmailMessage -> Maybe RawEmail
$sel:fromAddress:EmailMessage' :: EmailMessage -> Maybe Text
$sel:body:EmailMessage' :: EmailMessage -> Maybe Text
$sel:substitutions:EmailMessage' :: EmailMessage -> Maybe (HashMap Text [Text])
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Substitutions" Text -> HashMap Text [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text [Text] -> Pair)
-> Maybe (HashMap Text [Text]) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text [Text])
substitutions,
            (Text
"Body" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
body,
            (Text
"FromAddress" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
fromAddress,
            (Text
"RawEmail" Text -> RawEmail -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (RawEmail -> Pair) -> Maybe RawEmail -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe RawEmail
rawEmail,
            (Text
"FeedbackForwardingAddress" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
feedbackForwardingAddress,
            (Text
"SimpleEmail" Text -> SimpleEmail -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SimpleEmail -> Pair) -> Maybe SimpleEmail -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SimpleEmail
simpleEmail,
            (Text
"ReplyToAddresses" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([Text] -> Pair) -> Maybe [Text] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
replyToAddresses
          ]
      )