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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.PinpointEmail.Types.Content
import qualified Amazonka.Prelude as Prelude

-- | 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 support HTML. HTML messages can include formatted
    -- text, hyperlinks, images, and more.
    Body -> Maybe Content
html :: Prelude.Maybe Content,
    -- | 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
  }
  deriving (Body -> Body -> Bool
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]
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
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. 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:
--
-- '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.
--
-- '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.
newBody ::
  Body
newBody :: Body
newBody =
  Body'
    { $sel:html:Body' :: Maybe Content
html = forall a. Maybe a
Prelude.Nothing,
      $sel:text:Body' :: Maybe Content
text = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' Body (Maybe Content)
body_html = 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)

-- | 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 :: Lens' Body (Maybe Content)
body_text = 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)

instance Prelude.Hashable Body where
  hashWithSalt :: Int -> Body -> Int
hashWithSalt Int
_salt Body' {Maybe Content
text :: Maybe Content
html :: Maybe Content
$sel:text:Body' :: Body -> Maybe Content
$sel:html:Body' :: Body -> Maybe Content
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Content
html
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Content
text

instance Prelude.NFData Body where
  rnf :: Body -> ()
rnf Body' {Maybe Content
text :: Maybe Content
html :: Maybe Content
$sel:text:Body' :: Body -> Maybe Content
$sel:html:Body' :: Body -> Maybe Content
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Content
html seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Content
text

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