{-# 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.Body
-- 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.Body where

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

-- | Represents the body of the email message.
--
-- /See:/ 'newBody' smart constructor.
data Body = Body'
  { -- | An object that represents the version of the message that is displayed
    -- in email clients that don\'t support HTML, or clients where the
    -- recipient has disabled HTML rendering.
    Body -> Maybe Content
text :: Prelude.Maybe Content,
    -- | An object that represents the version of the message that is displayed
    -- in email clients that support HTML. HTML messages can include formatted
    -- text, hyperlinks, images, and more.
    Body -> Maybe Content
html :: Prelude.Maybe Content
  }
  deriving (Body -> Body -> Bool
(Body -> Body -> Bool) -> (Body -> Body -> Bool) -> Eq Body
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Body -> Body -> Bool
$c/= :: Body -> Body -> Bool
== :: Body -> Body -> Bool
$c== :: Body -> Body -> Bool
Prelude.Eq, ReadPrec [Body]
ReadPrec Body
Int -> ReadS Body
ReadS [Body]
(Int -> ReadS Body)
-> ReadS [Body] -> ReadPrec Body -> ReadPrec [Body] -> Read Body
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Body]
$creadListPrec :: ReadPrec [Body]
readPrec :: ReadPrec Body
$creadPrec :: ReadPrec Body
readList :: ReadS [Body]
$creadList :: ReadS [Body]
readsPrec :: Int -> ReadS Body
$creadsPrec :: Int -> ReadS Body
Prelude.Read, Int -> Body -> ShowS
[Body] -> ShowS
Body -> String
(Int -> Body -> ShowS)
-> (Body -> String) -> ([Body] -> ShowS) -> Show Body
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Body] -> ShowS
$cshowList :: [Body] -> ShowS
show :: Body -> String
$cshow :: Body -> String
showsPrec :: Int -> Body -> ShowS
$cshowsPrec :: Int -> Body -> ShowS
Prelude.Show, (forall x. Body -> Rep Body x)
-> (forall x. Rep Body x -> Body) -> Generic Body
forall x. Rep Body x -> Body
forall x. Body -> Rep Body x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Body x -> Body
$cfrom :: forall x. Body -> Rep Body x
Prelude.Generic)

-- |
-- Create a value of 'Body' 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:
--
-- 'text', 'body_text' - An object that represents the version of the message that is displayed
-- in email clients that don\'t support HTML, or clients where the
-- recipient has disabled HTML rendering.
--
-- 'html', 'body_html' - An object that represents the version of the message that is displayed
-- in email clients that support HTML. HTML messages can include formatted
-- text, hyperlinks, images, and more.
newBody ::
  Body
newBody :: Body
newBody =
  Body' :: Maybe Content -> Maybe Content -> Body
Body'
    { $sel:text:Body' :: Maybe Content
text = Maybe Content
forall a. Maybe a
Prelude.Nothing,
      $sel:html:Body' :: Maybe Content
html = Maybe Content
forall a. Maybe a
Prelude.Nothing
    }

-- | An object that represents the version of the message that is displayed
-- in email clients that don\'t support HTML, or clients where the
-- recipient has disabled HTML rendering.
body_text :: Lens.Lens' Body (Prelude.Maybe Content)
body_text :: (Maybe Content -> f (Maybe Content)) -> Body -> f Body
body_text = (Body -> Maybe Content)
-> (Body -> Maybe Content -> Body)
-> Lens Body Body (Maybe Content) (Maybe Content)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Body' {Maybe Content
text :: Maybe Content
$sel:text:Body' :: Body -> Maybe Content
text} -> Maybe Content
text) (\s :: Body
s@Body' {} Maybe Content
a -> Body
s {$sel:text:Body' :: Maybe Content
text = Maybe Content
a} :: Body)

-- | An object that represents the version of the message that is displayed
-- in email clients that support HTML. HTML messages can include formatted
-- text, hyperlinks, images, and more.
body_html :: Lens.Lens' Body (Prelude.Maybe Content)
body_html :: (Maybe Content -> f (Maybe Content)) -> Body -> f Body
body_html = (Body -> Maybe Content)
-> (Body -> Maybe Content -> Body)
-> Lens Body Body (Maybe Content) (Maybe Content)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Body' {Maybe Content
html :: Maybe Content
$sel:html:Body' :: Body -> Maybe Content
html} -> Maybe Content
html) (\s :: Body
s@Body' {} Maybe Content
a -> Body
s {$sel:html:Body' :: Maybe Content
html = Maybe Content
a} :: Body)

instance Prelude.Hashable Body

instance Prelude.NFData Body

instance Core.ToJSON Body where
  toJSON :: Body -> Value
toJSON Body' {Maybe Content
html :: Maybe Content
text :: Maybe Content
$sel:html:Body' :: Body -> Maybe Content
$sel:text:Body' :: Body -> Maybe Content
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Text" Text -> Content -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Content -> Pair) -> Maybe Content -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Content
text,
            (Text
"Html" Text -> Content -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Content -> Pair) -> Maybe Content -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Content
html
          ]
      )