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

import qualified Amazonka.Core as Core
import Amazonka.IoTEvents.Types.EmailContent
import Amazonka.IoTEvents.Types.EmailRecipients
import qualified Amazonka.Lens as Lens
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
(EmailConfiguration -> EmailConfiguration -> Bool)
-> (EmailConfiguration -> EmailConfiguration -> Bool)
-> Eq EmailConfiguration
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]
(Int -> ReadS EmailConfiguration)
-> ReadS [EmailConfiguration]
-> ReadPrec EmailConfiguration
-> ReadPrec [EmailConfiguration]
-> Read 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
(Int -> EmailConfiguration -> ShowS)
-> (EmailConfiguration -> String)
-> ([EmailConfiguration] -> ShowS)
-> Show EmailConfiguration
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. EmailConfiguration -> Rep EmailConfiguration x)
-> (forall x. Rep EmailConfiguration x -> EmailConfiguration)
-> Generic EmailConfiguration
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' :: Maybe EmailContent -> Text -> EmailRecipients -> EmailConfiguration
EmailConfiguration'
    { $sel:content:EmailConfiguration' :: Maybe EmailContent
content = Maybe EmailContent
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 :: (Maybe EmailContent -> f (Maybe EmailContent))
-> EmailConfiguration -> f EmailConfiguration
emailConfiguration_content = (EmailConfiguration -> Maybe EmailContent)
-> (EmailConfiguration -> Maybe EmailContent -> EmailConfiguration)
-> Lens
     EmailConfiguration
     EmailConfiguration
     (Maybe EmailContent)
     (Maybe EmailContent)
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 :: (Text -> f Text) -> EmailConfiguration -> f EmailConfiguration
emailConfiguration_from = (EmailConfiguration -> Text)
-> (EmailConfiguration -> Text -> EmailConfiguration)
-> Lens EmailConfiguration EmailConfiguration Text Text
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 :: (EmailRecipients -> f EmailRecipients)
-> EmailConfiguration -> f EmailConfiguration
emailConfiguration_recipients = (EmailConfiguration -> EmailRecipients)
-> (EmailConfiguration -> EmailRecipients -> EmailConfiguration)
-> Lens
     EmailConfiguration
     EmailConfiguration
     EmailRecipients
     EmailRecipients
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 Core.FromJSON EmailConfiguration where
  parseJSON :: Value -> Parser EmailConfiguration
parseJSON =
    String
-> (Object -> Parser EmailConfiguration)
-> Value
-> Parser EmailConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EmailConfiguration"
      ( \Object
x ->
          Maybe EmailContent -> Text -> EmailRecipients -> EmailConfiguration
EmailConfiguration'
            (Maybe EmailContent
 -> Text -> EmailRecipients -> EmailConfiguration)
-> Parser (Maybe EmailContent)
-> Parser (Text -> EmailRecipients -> EmailConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe EmailContent)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"content")
            Parser (Text -> EmailRecipients -> EmailConfiguration)
-> Parser Text -> Parser (EmailRecipients -> EmailConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"from")
            Parser (EmailRecipients -> EmailConfiguration)
-> Parser EmailRecipients -> Parser EmailConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser EmailRecipients
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"recipients")
      )

instance Prelude.Hashable EmailConfiguration

instance Prelude.NFData EmailConfiguration

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"content" Text -> EmailContent -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (EmailContent -> Pair) -> Maybe EmailContent -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EmailContent
content,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"from" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
from),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"recipients" Text -> EmailRecipients -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= EmailRecipients
recipients)
          ]
      )