{-# 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.IoTEvents.Types.EmailConfiguration
-- 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.IoTEvents.Types.EmailConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoTEvents.Types.EmailContent
import Amazonka.IoTEvents.Types.EmailRecipients
import qualified Amazonka.Prelude as Prelude

-- | Contains the configuration information of email notifications.
--
-- /See:/ 'newEmailConfiguration' smart constructor.
data EmailConfiguration = EmailConfiguration'
  { -- | Contains the subject and message of an email.
    EmailConfiguration -> Maybe EmailContent
content :: Prelude.Maybe EmailContent,
    -- | The email address that sends emails.
    --
    -- If you use the AWS IoT Events managed AWS Lambda function to manage your
    -- emails, you must
    -- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-email-addresses.html verify the email address that sends emails in Amazon SES>.
    EmailConfiguration -> Text
from :: Prelude.Text,
    -- | Contains the information of one or more recipients who receive the
    -- emails.
    --
    -- You must
    -- <https://docs.aws.amazon.com/singlesignon/latest/userguide/addusers.html add the users that receive emails to your AWS SSO store>.
    EmailConfiguration -> EmailRecipients
recipients :: EmailRecipients
  }
  deriving (EmailConfiguration -> EmailConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EmailConfiguration -> EmailConfiguration -> Bool
$c/= :: EmailConfiguration -> EmailConfiguration -> Bool
== :: EmailConfiguration -> EmailConfiguration -> Bool
$c== :: EmailConfiguration -> EmailConfiguration -> Bool
Prelude.Eq, ReadPrec [EmailConfiguration]
ReadPrec EmailConfiguration
Int -> ReadS EmailConfiguration
ReadS [EmailConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EmailConfiguration]
$creadListPrec :: ReadPrec [EmailConfiguration]
readPrec :: ReadPrec EmailConfiguration
$creadPrec :: ReadPrec EmailConfiguration
readList :: ReadS [EmailConfiguration]
$creadList :: ReadS [EmailConfiguration]
readsPrec :: Int -> ReadS EmailConfiguration
$creadsPrec :: Int -> ReadS EmailConfiguration
Prelude.Read, Int -> EmailConfiguration -> ShowS
[EmailConfiguration] -> ShowS
EmailConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EmailConfiguration] -> ShowS
$cshowList :: [EmailConfiguration] -> ShowS
show :: EmailConfiguration -> String
$cshow :: EmailConfiguration -> String
showsPrec :: Int -> EmailConfiguration -> ShowS
$cshowsPrec :: Int -> EmailConfiguration -> ShowS
Prelude.Show, forall x. Rep EmailConfiguration x -> EmailConfiguration
forall x. EmailConfiguration -> Rep EmailConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EmailConfiguration x -> EmailConfiguration
$cfrom :: forall x. EmailConfiguration -> Rep EmailConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'EmailConfiguration' 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:
--
-- 'content', 'emailConfiguration_content' - Contains the subject and message of an email.
--
-- 'from', 'emailConfiguration_from' - The email address that sends emails.
--
-- If you use the AWS IoT Events managed AWS Lambda function to manage your
-- emails, you must
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-email-addresses.html verify the email address that sends emails in Amazon SES>.
--
-- 'recipients', 'emailConfiguration_recipients' - Contains the information of one or more recipients who receive the
-- emails.
--
-- You must
-- <https://docs.aws.amazon.com/singlesignon/latest/userguide/addusers.html add the users that receive emails to your AWS SSO store>.
newEmailConfiguration ::
  -- | 'from'
  Prelude.Text ->
  -- | 'recipients'
  EmailRecipients ->
  EmailConfiguration
newEmailConfiguration :: Text -> EmailRecipients -> EmailConfiguration
newEmailConfiguration Text
pFrom_ EmailRecipients
pRecipients_ =
  EmailConfiguration'
    { $sel:content:EmailConfiguration' :: Maybe EmailContent
content = forall a. Maybe a
Prelude.Nothing,
      $sel:from:EmailConfiguration' :: Text
from = Text
pFrom_,
      $sel:recipients:EmailConfiguration' :: EmailRecipients
recipients = EmailRecipients
pRecipients_
    }

-- | Contains the subject and message of an email.
emailConfiguration_content :: Lens.Lens' EmailConfiguration (Prelude.Maybe EmailContent)
emailConfiguration_content :: Lens' EmailConfiguration (Maybe EmailContent)
emailConfiguration_content = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EmailConfiguration' {Maybe EmailContent
content :: Maybe EmailContent
$sel:content:EmailConfiguration' :: EmailConfiguration -> Maybe EmailContent
content} -> Maybe EmailContent
content) (\s :: EmailConfiguration
s@EmailConfiguration' {} Maybe EmailContent
a -> EmailConfiguration
s {$sel:content:EmailConfiguration' :: Maybe EmailContent
content = Maybe EmailContent
a} :: EmailConfiguration)

-- | The email address that sends emails.
--
-- If you use the AWS IoT Events managed AWS Lambda function to manage your
-- emails, you must
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-email-addresses.html verify the email address that sends emails in Amazon SES>.
emailConfiguration_from :: Lens.Lens' EmailConfiguration Prelude.Text
emailConfiguration_from :: Lens' EmailConfiguration Text
emailConfiguration_from = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EmailConfiguration' {Text
from :: Text
$sel:from:EmailConfiguration' :: EmailConfiguration -> Text
from} -> Text
from) (\s :: EmailConfiguration
s@EmailConfiguration' {} Text
a -> EmailConfiguration
s {$sel:from:EmailConfiguration' :: Text
from = Text
a} :: EmailConfiguration)

-- | Contains the information of one or more recipients who receive the
-- emails.
--
-- You must
-- <https://docs.aws.amazon.com/singlesignon/latest/userguide/addusers.html add the users that receive emails to your AWS SSO store>.
emailConfiguration_recipients :: Lens.Lens' EmailConfiguration EmailRecipients
emailConfiguration_recipients :: Lens' EmailConfiguration EmailRecipients
emailConfiguration_recipients = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EmailConfiguration' {EmailRecipients
recipients :: EmailRecipients
$sel:recipients:EmailConfiguration' :: EmailConfiguration -> EmailRecipients
recipients} -> EmailRecipients
recipients) (\s :: EmailConfiguration
s@EmailConfiguration' {} EmailRecipients
a -> EmailConfiguration
s {$sel:recipients:EmailConfiguration' :: EmailRecipients
recipients = EmailRecipients
a} :: EmailConfiguration)

instance Data.FromJSON EmailConfiguration where
  parseJSON :: Value -> Parser EmailConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"EmailConfiguration"
      ( \Object
x ->
          Maybe EmailContent -> Text -> EmailRecipients -> EmailConfiguration
EmailConfiguration'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"content")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"from")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"recipients")
      )

instance Prelude.Hashable EmailConfiguration where
  hashWithSalt :: Int -> EmailConfiguration -> Int
hashWithSalt Int
_salt EmailConfiguration' {Maybe EmailContent
Text
EmailRecipients
recipients :: EmailRecipients
from :: Text
content :: Maybe EmailContent
$sel:recipients:EmailConfiguration' :: EmailConfiguration -> EmailRecipients
$sel:from:EmailConfiguration' :: EmailConfiguration -> Text
$sel:content:EmailConfiguration' :: EmailConfiguration -> Maybe EmailContent
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EmailContent
content
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
from
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` EmailRecipients
recipients

instance Prelude.NFData EmailConfiguration where
  rnf :: EmailConfiguration -> ()
rnf EmailConfiguration' {Maybe EmailContent
Text
EmailRecipients
recipients :: EmailRecipients
from :: Text
content :: Maybe EmailContent
$sel:recipients:EmailConfiguration' :: EmailConfiguration -> EmailRecipients
$sel:from:EmailConfiguration' :: EmailConfiguration -> Text
$sel:content:EmailConfiguration' :: EmailConfiguration -> Maybe EmailContent
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe EmailContent
content
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
from
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf EmailRecipients
recipients

instance Data.ToJSON EmailConfiguration where
  toJSON :: EmailConfiguration -> Value
toJSON EmailConfiguration' {Maybe EmailContent
Text
EmailRecipients
recipients :: EmailRecipients
from :: Text
content :: Maybe EmailContent
$sel:recipients:EmailConfiguration' :: EmailConfiguration -> EmailRecipients
$sel:from:EmailConfiguration' :: EmailConfiguration -> Text
$sel:content:EmailConfiguration' :: EmailConfiguration -> Maybe EmailContent
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"content" 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 EmailContent
content,
            forall a. a -> Maybe a
Prelude.Just (Key
"from" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
from),
            forall a. a -> Maybe a
Prelude.Just (Key
"recipients" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= EmailRecipients
recipients)
          ]
      )