{-# 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.SES.Types.EventDestination
-- 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.SES.Types.EventDestination where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SES.Types.CloudWatchDestination
import Amazonka.SES.Types.EventType
import Amazonka.SES.Types.KinesisFirehoseDestination
import Amazonka.SES.Types.SNSDestination

-- | Contains information about the event destination that the specified
-- email sending events will be published to.
--
-- When you create or update an event destination, you must provide one,
-- and only one, destination. The destination can be Amazon CloudWatch,
-- Amazon Kinesis Firehose or Amazon Simple Notification Service (Amazon
-- SNS).
--
-- Event destinations are associated with configuration sets, which enable
-- you to publish email sending events to Amazon CloudWatch, Amazon Kinesis
-- Firehose, or Amazon Simple Notification Service (Amazon SNS). For
-- information about using configuration sets, see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/monitor-sending-activity.html Amazon SES Developer Guide>.
--
-- /See:/ 'newEventDestination' smart constructor.
data EventDestination = EventDestination'
  { -- | Sets whether Amazon SES publishes events to this destination when you
    -- send an email with the associated configuration set. Set to @true@ to
    -- enable publishing to this destination; set to @false@ to prevent
    -- publishing to this destination. The default value is @false@.
    EventDestination -> Maybe Bool
enabled :: Prelude.Maybe Prelude.Bool,
    -- | An object that contains the delivery stream ARN and the IAM role ARN
    -- associated with an Amazon Kinesis Firehose event destination.
    EventDestination -> Maybe KinesisFirehoseDestination
kinesisFirehoseDestination :: Prelude.Maybe KinesisFirehoseDestination,
    -- | An object that contains the names, default values, and sources of the
    -- dimensions associated with an Amazon CloudWatch event destination.
    EventDestination -> Maybe CloudWatchDestination
cloudWatchDestination :: Prelude.Maybe CloudWatchDestination,
    -- | An object that contains the topic ARN associated with an Amazon Simple
    -- Notification Service (Amazon SNS) event destination.
    EventDestination -> Maybe SNSDestination
sNSDestination :: Prelude.Maybe SNSDestination,
    -- | The name of the event destination. The name must:
    --
    -- -   This value can only contain ASCII letters (a-z, A-Z), numbers (0-9),
    --     underscores (_), or dashes (-).
    --
    -- -   Contain less than 64 characters.
    EventDestination -> Text
name :: Prelude.Text,
    -- | The type of email sending events to publish to the event destination.
    EventDestination -> [EventType]
matchingEventTypes :: [EventType]
  }
  deriving (EventDestination -> EventDestination -> Bool
(EventDestination -> EventDestination -> Bool)
-> (EventDestination -> EventDestination -> Bool)
-> Eq EventDestination
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EventDestination -> EventDestination -> Bool
$c/= :: EventDestination -> EventDestination -> Bool
== :: EventDestination -> EventDestination -> Bool
$c== :: EventDestination -> EventDestination -> Bool
Prelude.Eq, ReadPrec [EventDestination]
ReadPrec EventDestination
Int -> ReadS EventDestination
ReadS [EventDestination]
(Int -> ReadS EventDestination)
-> ReadS [EventDestination]
-> ReadPrec EventDestination
-> ReadPrec [EventDestination]
-> Read EventDestination
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EventDestination]
$creadListPrec :: ReadPrec [EventDestination]
readPrec :: ReadPrec EventDestination
$creadPrec :: ReadPrec EventDestination
readList :: ReadS [EventDestination]
$creadList :: ReadS [EventDestination]
readsPrec :: Int -> ReadS EventDestination
$creadsPrec :: Int -> ReadS EventDestination
Prelude.Read, Int -> EventDestination -> ShowS
[EventDestination] -> ShowS
EventDestination -> String
(Int -> EventDestination -> ShowS)
-> (EventDestination -> String)
-> ([EventDestination] -> ShowS)
-> Show EventDestination
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EventDestination] -> ShowS
$cshowList :: [EventDestination] -> ShowS
show :: EventDestination -> String
$cshow :: EventDestination -> String
showsPrec :: Int -> EventDestination -> ShowS
$cshowsPrec :: Int -> EventDestination -> ShowS
Prelude.Show, (forall x. EventDestination -> Rep EventDestination x)
-> (forall x. Rep EventDestination x -> EventDestination)
-> Generic EventDestination
forall x. Rep EventDestination x -> EventDestination
forall x. EventDestination -> Rep EventDestination x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EventDestination x -> EventDestination
$cfrom :: forall x. EventDestination -> Rep EventDestination x
Prelude.Generic)

-- |
-- Create a value of 'EventDestination' 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:
--
-- 'enabled', 'eventDestination_enabled' - Sets whether Amazon SES publishes events to this destination when you
-- send an email with the associated configuration set. Set to @true@ to
-- enable publishing to this destination; set to @false@ to prevent
-- publishing to this destination. The default value is @false@.
--
-- 'kinesisFirehoseDestination', 'eventDestination_kinesisFirehoseDestination' - An object that contains the delivery stream ARN and the IAM role ARN
-- associated with an Amazon Kinesis Firehose event destination.
--
-- 'cloudWatchDestination', 'eventDestination_cloudWatchDestination' - An object that contains the names, default values, and sources of the
-- dimensions associated with an Amazon CloudWatch event destination.
--
-- 'sNSDestination', 'eventDestination_sNSDestination' - An object that contains the topic ARN associated with an Amazon Simple
-- Notification Service (Amazon SNS) event destination.
--
-- 'name', 'eventDestination_name' - The name of the event destination. The name must:
--
-- -   This value can only contain ASCII letters (a-z, A-Z), numbers (0-9),
--     underscores (_), or dashes (-).
--
-- -   Contain less than 64 characters.
--
-- 'matchingEventTypes', 'eventDestination_matchingEventTypes' - The type of email sending events to publish to the event destination.
newEventDestination ::
  -- | 'name'
  Prelude.Text ->
  EventDestination
newEventDestination :: Text -> EventDestination
newEventDestination Text
pName_ =
  EventDestination' :: Maybe Bool
-> Maybe KinesisFirehoseDestination
-> Maybe CloudWatchDestination
-> Maybe SNSDestination
-> Text
-> [EventType]
-> EventDestination
EventDestination'
    { $sel:enabled:EventDestination' :: Maybe Bool
enabled = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:kinesisFirehoseDestination:EventDestination' :: Maybe KinesisFirehoseDestination
kinesisFirehoseDestination = Maybe KinesisFirehoseDestination
forall a. Maybe a
Prelude.Nothing,
      $sel:cloudWatchDestination:EventDestination' :: Maybe CloudWatchDestination
cloudWatchDestination = Maybe CloudWatchDestination
forall a. Maybe a
Prelude.Nothing,
      $sel:sNSDestination:EventDestination' :: Maybe SNSDestination
sNSDestination = Maybe SNSDestination
forall a. Maybe a
Prelude.Nothing,
      $sel:name:EventDestination' :: Text
name = Text
pName_,
      $sel:matchingEventTypes:EventDestination' :: [EventType]
matchingEventTypes = [EventType]
forall a. Monoid a => a
Prelude.mempty
    }

-- | Sets whether Amazon SES publishes events to this destination when you
-- send an email with the associated configuration set. Set to @true@ to
-- enable publishing to this destination; set to @false@ to prevent
-- publishing to this destination. The default value is @false@.
eventDestination_enabled :: Lens.Lens' EventDestination (Prelude.Maybe Prelude.Bool)
eventDestination_enabled :: (Maybe Bool -> f (Maybe Bool))
-> EventDestination -> f EventDestination
eventDestination_enabled = (EventDestination -> Maybe Bool)
-> (EventDestination -> Maybe Bool -> EventDestination)
-> Lens EventDestination EventDestination (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventDestination' {Maybe Bool
enabled :: Maybe Bool
$sel:enabled:EventDestination' :: EventDestination -> Maybe Bool
enabled} -> Maybe Bool
enabled) (\s :: EventDestination
s@EventDestination' {} Maybe Bool
a -> EventDestination
s {$sel:enabled:EventDestination' :: Maybe Bool
enabled = Maybe Bool
a} :: EventDestination)

-- | An object that contains the delivery stream ARN and the IAM role ARN
-- associated with an Amazon Kinesis Firehose event destination.
eventDestination_kinesisFirehoseDestination :: Lens.Lens' EventDestination (Prelude.Maybe KinesisFirehoseDestination)
eventDestination_kinesisFirehoseDestination :: (Maybe KinesisFirehoseDestination
 -> f (Maybe KinesisFirehoseDestination))
-> EventDestination -> f EventDestination
eventDestination_kinesisFirehoseDestination = (EventDestination -> Maybe KinesisFirehoseDestination)
-> (EventDestination
    -> Maybe KinesisFirehoseDestination -> EventDestination)
-> Lens
     EventDestination
     EventDestination
     (Maybe KinesisFirehoseDestination)
     (Maybe KinesisFirehoseDestination)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventDestination' {Maybe KinesisFirehoseDestination
kinesisFirehoseDestination :: Maybe KinesisFirehoseDestination
$sel:kinesisFirehoseDestination:EventDestination' :: EventDestination -> Maybe KinesisFirehoseDestination
kinesisFirehoseDestination} -> Maybe KinesisFirehoseDestination
kinesisFirehoseDestination) (\s :: EventDestination
s@EventDestination' {} Maybe KinesisFirehoseDestination
a -> EventDestination
s {$sel:kinesisFirehoseDestination:EventDestination' :: Maybe KinesisFirehoseDestination
kinesisFirehoseDestination = Maybe KinesisFirehoseDestination
a} :: EventDestination)

-- | An object that contains the names, default values, and sources of the
-- dimensions associated with an Amazon CloudWatch event destination.
eventDestination_cloudWatchDestination :: Lens.Lens' EventDestination (Prelude.Maybe CloudWatchDestination)
eventDestination_cloudWatchDestination :: (Maybe CloudWatchDestination -> f (Maybe CloudWatchDestination))
-> EventDestination -> f EventDestination
eventDestination_cloudWatchDestination = (EventDestination -> Maybe CloudWatchDestination)
-> (EventDestination
    -> Maybe CloudWatchDestination -> EventDestination)
-> Lens
     EventDestination
     EventDestination
     (Maybe CloudWatchDestination)
     (Maybe CloudWatchDestination)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventDestination' {Maybe CloudWatchDestination
cloudWatchDestination :: Maybe CloudWatchDestination
$sel:cloudWatchDestination:EventDestination' :: EventDestination -> Maybe CloudWatchDestination
cloudWatchDestination} -> Maybe CloudWatchDestination
cloudWatchDestination) (\s :: EventDestination
s@EventDestination' {} Maybe CloudWatchDestination
a -> EventDestination
s {$sel:cloudWatchDestination:EventDestination' :: Maybe CloudWatchDestination
cloudWatchDestination = Maybe CloudWatchDestination
a} :: EventDestination)

-- | An object that contains the topic ARN associated with an Amazon Simple
-- Notification Service (Amazon SNS) event destination.
eventDestination_sNSDestination :: Lens.Lens' EventDestination (Prelude.Maybe SNSDestination)
eventDestination_sNSDestination :: (Maybe SNSDestination -> f (Maybe SNSDestination))
-> EventDestination -> f EventDestination
eventDestination_sNSDestination = (EventDestination -> Maybe SNSDestination)
-> (EventDestination -> Maybe SNSDestination -> EventDestination)
-> Lens
     EventDestination
     EventDestination
     (Maybe SNSDestination)
     (Maybe SNSDestination)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventDestination' {Maybe SNSDestination
sNSDestination :: Maybe SNSDestination
$sel:sNSDestination:EventDestination' :: EventDestination -> Maybe SNSDestination
sNSDestination} -> Maybe SNSDestination
sNSDestination) (\s :: EventDestination
s@EventDestination' {} Maybe SNSDestination
a -> EventDestination
s {$sel:sNSDestination:EventDestination' :: Maybe SNSDestination
sNSDestination = Maybe SNSDestination
a} :: EventDestination)

-- | The name of the event destination. The name must:
--
-- -   This value can only contain ASCII letters (a-z, A-Z), numbers (0-9),
--     underscores (_), or dashes (-).
--
-- -   Contain less than 64 characters.
eventDestination_name :: Lens.Lens' EventDestination Prelude.Text
eventDestination_name :: (Text -> f Text) -> EventDestination -> f EventDestination
eventDestination_name = (EventDestination -> Text)
-> (EventDestination -> Text -> EventDestination)
-> Lens EventDestination EventDestination Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventDestination' {Text
name :: Text
$sel:name:EventDestination' :: EventDestination -> Text
name} -> Text
name) (\s :: EventDestination
s@EventDestination' {} Text
a -> EventDestination
s {$sel:name:EventDestination' :: Text
name = Text
a} :: EventDestination)

-- | The type of email sending events to publish to the event destination.
eventDestination_matchingEventTypes :: Lens.Lens' EventDestination [EventType]
eventDestination_matchingEventTypes :: ([EventType] -> f [EventType])
-> EventDestination -> f EventDestination
eventDestination_matchingEventTypes = (EventDestination -> [EventType])
-> (EventDestination -> [EventType] -> EventDestination)
-> Lens EventDestination EventDestination [EventType] [EventType]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventDestination' {[EventType]
matchingEventTypes :: [EventType]
$sel:matchingEventTypes:EventDestination' :: EventDestination -> [EventType]
matchingEventTypes} -> [EventType]
matchingEventTypes) (\s :: EventDestination
s@EventDestination' {} [EventType]
a -> EventDestination
s {$sel:matchingEventTypes:EventDestination' :: [EventType]
matchingEventTypes = [EventType]
a} :: EventDestination) (([EventType] -> f [EventType])
 -> EventDestination -> f EventDestination)
-> (([EventType] -> f [EventType]) -> [EventType] -> f [EventType])
-> ([EventType] -> f [EventType])
-> EventDestination
-> f EventDestination
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([EventType] -> f [EventType]) -> [EventType] -> f [EventType]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromXML EventDestination where
  parseXML :: [Node] -> Either String EventDestination
parseXML [Node]
x =
    Maybe Bool
-> Maybe KinesisFirehoseDestination
-> Maybe CloudWatchDestination
-> Maybe SNSDestination
-> Text
-> [EventType]
-> EventDestination
EventDestination'
      (Maybe Bool
 -> Maybe KinesisFirehoseDestination
 -> Maybe CloudWatchDestination
 -> Maybe SNSDestination
 -> Text
 -> [EventType]
 -> EventDestination)
-> Either String (Maybe Bool)
-> Either
     String
     (Maybe KinesisFirehoseDestination
      -> Maybe CloudWatchDestination
      -> Maybe SNSDestination
      -> Text
      -> [EventType]
      -> EventDestination)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Bool)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Enabled")
      Either
  String
  (Maybe KinesisFirehoseDestination
   -> Maybe CloudWatchDestination
   -> Maybe SNSDestination
   -> Text
   -> [EventType]
   -> EventDestination)
-> Either String (Maybe KinesisFirehoseDestination)
-> Either
     String
     (Maybe CloudWatchDestination
      -> Maybe SNSDestination -> Text -> [EventType] -> EventDestination)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe KinesisFirehoseDestination)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"KinesisFirehoseDestination")
      Either
  String
  (Maybe CloudWatchDestination
   -> Maybe SNSDestination -> Text -> [EventType] -> EventDestination)
-> Either String (Maybe CloudWatchDestination)
-> Either
     String
     (Maybe SNSDestination -> Text -> [EventType] -> EventDestination)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe CloudWatchDestination)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"CloudWatchDestination")
      Either
  String
  (Maybe SNSDestination -> Text -> [EventType] -> EventDestination)
-> Either String (Maybe SNSDestination)
-> Either String (Text -> [EventType] -> EventDestination)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe SNSDestination)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"SNSDestination")
      Either String (Text -> [EventType] -> EventDestination)
-> Either String Text
-> Either String ([EventType] -> EventDestination)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Name")
      Either String ([EventType] -> EventDestination)
-> Either String [EventType] -> Either String EventDestination
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"MatchingEventTypes"
                      Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String [EventType])
-> Either String [EventType]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= Text -> [Node] -> Either String [EventType]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member"
                  )

instance Prelude.Hashable EventDestination

instance Prelude.NFData EventDestination

instance Core.ToQuery EventDestination where
  toQuery :: EventDestination -> QueryString
toQuery EventDestination' {[EventType]
Maybe Bool
Maybe CloudWatchDestination
Maybe KinesisFirehoseDestination
Maybe SNSDestination
Text
matchingEventTypes :: [EventType]
name :: Text
sNSDestination :: Maybe SNSDestination
cloudWatchDestination :: Maybe CloudWatchDestination
kinesisFirehoseDestination :: Maybe KinesisFirehoseDestination
enabled :: Maybe Bool
$sel:matchingEventTypes:EventDestination' :: EventDestination -> [EventType]
$sel:name:EventDestination' :: EventDestination -> Text
$sel:sNSDestination:EventDestination' :: EventDestination -> Maybe SNSDestination
$sel:cloudWatchDestination:EventDestination' :: EventDestination -> Maybe CloudWatchDestination
$sel:kinesisFirehoseDestination:EventDestination' :: EventDestination -> Maybe KinesisFirehoseDestination
$sel:enabled:EventDestination' :: EventDestination -> Maybe Bool
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Enabled" ByteString -> Maybe Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Bool
enabled,
        ByteString
"KinesisFirehoseDestination"
          ByteString -> Maybe KinesisFirehoseDestination -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe KinesisFirehoseDestination
kinesisFirehoseDestination,
        ByteString
"CloudWatchDestination"
          ByteString -> Maybe CloudWatchDestination -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe CloudWatchDestination
cloudWatchDestination,
        ByteString
"SNSDestination" ByteString -> Maybe SNSDestination -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe SNSDestination
sNSDestination,
        ByteString
"Name" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
name,
        ByteString
"MatchingEventTypes"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: ByteString -> [EventType] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" [EventType]
matchingEventTypes
      ]