{-# 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.SESV2.Types.Message
-- 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.SESV2.Types.Message where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SESV2.Types.Body
import Amazonka.SESV2.Types.Content

-- | Represents the email message that you\'re sending. The @Message@ object
-- consists of a subject line and a message body.
--
-- /See:/ 'newMessage' smart constructor.
data Message = Message'
  { -- | The subject line of the email. The subject line can only contain 7-bit
    -- ASCII characters. However, you can specify non-ASCII characters in the
    -- subject line by using encoded-word syntax, as described in
    -- <https://tools.ietf.org/html/rfc2047 RFC 2047>.
    Message -> Content
subject :: Content,
    -- | The body of the message. You can specify an HTML version of the message,
    -- a text-only version of the message, or both.
    Message -> Body
body :: Body
  }
  deriving (Message -> Message -> Bool
(Message -> Message -> Bool)
-> (Message -> Message -> Bool) -> Eq Message
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Message -> Message -> Bool
$c/= :: Message -> Message -> Bool
== :: Message -> Message -> Bool
$c== :: Message -> Message -> Bool
Prelude.Eq, ReadPrec [Message]
ReadPrec Message
Int -> ReadS Message
ReadS [Message]
(Int -> ReadS Message)
-> ReadS [Message]
-> ReadPrec Message
-> ReadPrec [Message]
-> Read Message
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Message]
$creadListPrec :: ReadPrec [Message]
readPrec :: ReadPrec Message
$creadPrec :: ReadPrec Message
readList :: ReadS [Message]
$creadList :: ReadS [Message]
readsPrec :: Int -> ReadS Message
$creadsPrec :: Int -> ReadS Message
Prelude.Read, Int -> Message -> ShowS
[Message] -> ShowS
Message -> String
(Int -> Message -> ShowS)
-> (Message -> String) -> ([Message] -> ShowS) -> Show Message
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Message] -> ShowS
$cshowList :: [Message] -> ShowS
show :: Message -> String
$cshow :: Message -> String
showsPrec :: Int -> Message -> ShowS
$cshowsPrec :: Int -> Message -> ShowS
Prelude.Show, (forall x. Message -> Rep Message x)
-> (forall x. Rep Message x -> Message) -> Generic Message
forall x. Rep Message x -> Message
forall x. Message -> Rep Message x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Message x -> Message
$cfrom :: forall x. Message -> Rep Message x
Prelude.Generic)

-- |
-- Create a value of 'Message' 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:
--
-- 'subject', 'message_subject' - The subject line of the email. The subject line can only contain 7-bit
-- ASCII characters. However, you can specify non-ASCII characters in the
-- subject line by using encoded-word syntax, as described in
-- <https://tools.ietf.org/html/rfc2047 RFC 2047>.
--
-- 'body', 'message_body' - The body of the message. You can specify an HTML version of the message,
-- a text-only version of the message, or both.
newMessage ::
  -- | 'subject'
  Content ->
  -- | 'body'
  Body ->
  Message
newMessage :: Content -> Body -> Message
newMessage Content
pSubject_ Body
pBody_ =
  Message' :: Content -> Body -> Message
Message' {$sel:subject:Message' :: Content
subject = Content
pSubject_, $sel:body:Message' :: Body
body = Body
pBody_}

-- | The subject line of the email. The subject line can only contain 7-bit
-- ASCII characters. However, you can specify non-ASCII characters in the
-- subject line by using encoded-word syntax, as described in
-- <https://tools.ietf.org/html/rfc2047 RFC 2047>.
message_subject :: Lens.Lens' Message Content
message_subject :: (Content -> f Content) -> Message -> f Message
message_subject = (Message -> Content)
-> (Message -> Content -> Message)
-> Lens Message Message Content Content
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {Content
subject :: Content
$sel:subject:Message' :: Message -> Content
subject} -> Content
subject) (\s :: Message
s@Message' {} Content
a -> Message
s {$sel:subject:Message' :: Content
subject = Content
a} :: Message)

-- | The body of the message. You can specify an HTML version of the message,
-- a text-only version of the message, or both.
message_body :: Lens.Lens' Message Body
message_body :: (Body -> f Body) -> Message -> f Message
message_body = (Message -> Body)
-> (Message -> Body -> Message) -> Lens Message Message Body Body
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {Body
body :: Body
$sel:body:Message' :: Message -> Body
body} -> Body
body) (\s :: Message
s@Message' {} Body
a -> Message
s {$sel:body:Message' :: Body
body = Body
a} :: Message)

instance Prelude.Hashable Message

instance Prelude.NFData Message

instance Core.ToJSON Message where
  toJSON :: Message -> Value
toJSON Message' {Content
Body
body :: Body
subject :: Content
$sel:body:Message' :: Message -> Body
$sel:subject:Message' :: Message -> Content
..} =
    [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
"Subject" Text -> Content -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Content
subject),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Body" Text -> Body -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Body
body)
          ]
      )