{-# 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.S3.Types.NotificationConfiguration
-- 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.S3.Types.NotificationConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.S3.Internal
import Amazonka.S3.Types.EventBridgeConfiguration
import Amazonka.S3.Types.LambdaFunctionConfiguration
import Amazonka.S3.Types.QueueConfiguration
import Amazonka.S3.Types.TopicConfiguration

-- | A container for specifying the notification configuration of the bucket.
-- If this element is empty, notifications are turned off for the bucket.
--
-- /See:/ 'newNotificationConfiguration' smart constructor.
data NotificationConfiguration = NotificationConfiguration'
  { -- | Enables delivery of events to Amazon EventBridge.
    NotificationConfiguration -> Maybe EventBridgeConfiguration
eventBridgeConfiguration :: Prelude.Maybe EventBridgeConfiguration,
    -- | Describes the Lambda functions to invoke and the events for which to
    -- invoke them.
    NotificationConfiguration -> Maybe [LambdaFunctionConfiguration]
lambdaFunctionConfigurations :: Prelude.Maybe [LambdaFunctionConfiguration],
    -- | The Amazon Simple Queue Service queues to publish messages to and the
    -- events for which to publish messages.
    NotificationConfiguration -> Maybe [QueueConfiguration]
queueConfigurations :: Prelude.Maybe [QueueConfiguration],
    -- | The topic to which notifications are sent and the events for which
    -- notifications are generated.
    NotificationConfiguration -> Maybe [TopicConfiguration]
topicConfigurations :: Prelude.Maybe [TopicConfiguration]
  }
  deriving (NotificationConfiguration -> NotificationConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NotificationConfiguration -> NotificationConfiguration -> Bool
$c/= :: NotificationConfiguration -> NotificationConfiguration -> Bool
== :: NotificationConfiguration -> NotificationConfiguration -> Bool
$c== :: NotificationConfiguration -> NotificationConfiguration -> Bool
Prelude.Eq, ReadPrec [NotificationConfiguration]
ReadPrec NotificationConfiguration
Int -> ReadS NotificationConfiguration
ReadS [NotificationConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NotificationConfiguration]
$creadListPrec :: ReadPrec [NotificationConfiguration]
readPrec :: ReadPrec NotificationConfiguration
$creadPrec :: ReadPrec NotificationConfiguration
readList :: ReadS [NotificationConfiguration]
$creadList :: ReadS [NotificationConfiguration]
readsPrec :: Int -> ReadS NotificationConfiguration
$creadsPrec :: Int -> ReadS NotificationConfiguration
Prelude.Read, Int -> NotificationConfiguration -> ShowS
[NotificationConfiguration] -> ShowS
NotificationConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NotificationConfiguration] -> ShowS
$cshowList :: [NotificationConfiguration] -> ShowS
show :: NotificationConfiguration -> String
$cshow :: NotificationConfiguration -> String
showsPrec :: Int -> NotificationConfiguration -> ShowS
$cshowsPrec :: Int -> NotificationConfiguration -> ShowS
Prelude.Show, forall x.
Rep NotificationConfiguration x -> NotificationConfiguration
forall x.
NotificationConfiguration -> Rep NotificationConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep NotificationConfiguration x -> NotificationConfiguration
$cfrom :: forall x.
NotificationConfiguration -> Rep NotificationConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'NotificationConfiguration' 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:
--
-- 'eventBridgeConfiguration', 'notificationConfiguration_eventBridgeConfiguration' - Enables delivery of events to Amazon EventBridge.
--
-- 'lambdaFunctionConfigurations', 'notificationConfiguration_lambdaFunctionConfigurations' - Describes the Lambda functions to invoke and the events for which to
-- invoke them.
--
-- 'queueConfigurations', 'notificationConfiguration_queueConfigurations' - The Amazon Simple Queue Service queues to publish messages to and the
-- events for which to publish messages.
--
-- 'topicConfigurations', 'notificationConfiguration_topicConfigurations' - The topic to which notifications are sent and the events for which
-- notifications are generated.
newNotificationConfiguration ::
  NotificationConfiguration
newNotificationConfiguration :: NotificationConfiguration
newNotificationConfiguration =
  NotificationConfiguration'
    { $sel:eventBridgeConfiguration:NotificationConfiguration' :: Maybe EventBridgeConfiguration
eventBridgeConfiguration =
        forall a. Maybe a
Prelude.Nothing,
      $sel:lambdaFunctionConfigurations:NotificationConfiguration' :: Maybe [LambdaFunctionConfiguration]
lambdaFunctionConfigurations = forall a. Maybe a
Prelude.Nothing,
      $sel:queueConfigurations:NotificationConfiguration' :: Maybe [QueueConfiguration]
queueConfigurations = forall a. Maybe a
Prelude.Nothing,
      $sel:topicConfigurations:NotificationConfiguration' :: Maybe [TopicConfiguration]
topicConfigurations = forall a. Maybe a
Prelude.Nothing
    }

-- | Enables delivery of events to Amazon EventBridge.
notificationConfiguration_eventBridgeConfiguration :: Lens.Lens' NotificationConfiguration (Prelude.Maybe EventBridgeConfiguration)
notificationConfiguration_eventBridgeConfiguration :: Lens' NotificationConfiguration (Maybe EventBridgeConfiguration)
notificationConfiguration_eventBridgeConfiguration = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NotificationConfiguration' {Maybe EventBridgeConfiguration
eventBridgeConfiguration :: Maybe EventBridgeConfiguration
$sel:eventBridgeConfiguration:NotificationConfiguration' :: NotificationConfiguration -> Maybe EventBridgeConfiguration
eventBridgeConfiguration} -> Maybe EventBridgeConfiguration
eventBridgeConfiguration) (\s :: NotificationConfiguration
s@NotificationConfiguration' {} Maybe EventBridgeConfiguration
a -> NotificationConfiguration
s {$sel:eventBridgeConfiguration:NotificationConfiguration' :: Maybe EventBridgeConfiguration
eventBridgeConfiguration = Maybe EventBridgeConfiguration
a} :: NotificationConfiguration)

-- | Describes the Lambda functions to invoke and the events for which to
-- invoke them.
notificationConfiguration_lambdaFunctionConfigurations :: Lens.Lens' NotificationConfiguration (Prelude.Maybe [LambdaFunctionConfiguration])
notificationConfiguration_lambdaFunctionConfigurations :: Lens'
  NotificationConfiguration (Maybe [LambdaFunctionConfiguration])
notificationConfiguration_lambdaFunctionConfigurations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NotificationConfiguration' {Maybe [LambdaFunctionConfiguration]
lambdaFunctionConfigurations :: Maybe [LambdaFunctionConfiguration]
$sel:lambdaFunctionConfigurations:NotificationConfiguration' :: NotificationConfiguration -> Maybe [LambdaFunctionConfiguration]
lambdaFunctionConfigurations} -> Maybe [LambdaFunctionConfiguration]
lambdaFunctionConfigurations) (\s :: NotificationConfiguration
s@NotificationConfiguration' {} Maybe [LambdaFunctionConfiguration]
a -> NotificationConfiguration
s {$sel:lambdaFunctionConfigurations:NotificationConfiguration' :: Maybe [LambdaFunctionConfiguration]
lambdaFunctionConfigurations = Maybe [LambdaFunctionConfiguration]
a} :: NotificationConfiguration) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The Amazon Simple Queue Service queues to publish messages to and the
-- events for which to publish messages.
notificationConfiguration_queueConfigurations :: Lens.Lens' NotificationConfiguration (Prelude.Maybe [QueueConfiguration])
notificationConfiguration_queueConfigurations :: Lens' NotificationConfiguration (Maybe [QueueConfiguration])
notificationConfiguration_queueConfigurations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NotificationConfiguration' {Maybe [QueueConfiguration]
queueConfigurations :: Maybe [QueueConfiguration]
$sel:queueConfigurations:NotificationConfiguration' :: NotificationConfiguration -> Maybe [QueueConfiguration]
queueConfigurations} -> Maybe [QueueConfiguration]
queueConfigurations) (\s :: NotificationConfiguration
s@NotificationConfiguration' {} Maybe [QueueConfiguration]
a -> NotificationConfiguration
s {$sel:queueConfigurations:NotificationConfiguration' :: Maybe [QueueConfiguration]
queueConfigurations = Maybe [QueueConfiguration]
a} :: NotificationConfiguration) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The topic to which notifications are sent and the events for which
-- notifications are generated.
notificationConfiguration_topicConfigurations :: Lens.Lens' NotificationConfiguration (Prelude.Maybe [TopicConfiguration])
notificationConfiguration_topicConfigurations :: Lens' NotificationConfiguration (Maybe [TopicConfiguration])
notificationConfiguration_topicConfigurations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NotificationConfiguration' {Maybe [TopicConfiguration]
topicConfigurations :: Maybe [TopicConfiguration]
$sel:topicConfigurations:NotificationConfiguration' :: NotificationConfiguration -> Maybe [TopicConfiguration]
topicConfigurations} -> Maybe [TopicConfiguration]
topicConfigurations) (\s :: NotificationConfiguration
s@NotificationConfiguration' {} Maybe [TopicConfiguration]
a -> NotificationConfiguration
s {$sel:topicConfigurations:NotificationConfiguration' :: Maybe [TopicConfiguration]
topicConfigurations = Maybe [TopicConfiguration]
a} :: NotificationConfiguration) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromXML NotificationConfiguration where
  parseXML :: [Node] -> Either String NotificationConfiguration
parseXML [Node]
x =
    Maybe EventBridgeConfiguration
-> Maybe [LambdaFunctionConfiguration]
-> Maybe [QueueConfiguration]
-> Maybe [TopicConfiguration]
-> NotificationConfiguration
NotificationConfiguration'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"EventBridgeConfiguration")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may
                      (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"CloudFunctionConfiguration")
                      [Node]
x
                  )
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"QueueConfiguration") [Node]
x)
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"TopicConfiguration") [Node]
x)

instance Prelude.Hashable NotificationConfiguration where
  hashWithSalt :: Int -> NotificationConfiguration -> Int
hashWithSalt Int
_salt NotificationConfiguration' {Maybe [QueueConfiguration]
Maybe [LambdaFunctionConfiguration]
Maybe [TopicConfiguration]
Maybe EventBridgeConfiguration
topicConfigurations :: Maybe [TopicConfiguration]
queueConfigurations :: Maybe [QueueConfiguration]
lambdaFunctionConfigurations :: Maybe [LambdaFunctionConfiguration]
eventBridgeConfiguration :: Maybe EventBridgeConfiguration
$sel:topicConfigurations:NotificationConfiguration' :: NotificationConfiguration -> Maybe [TopicConfiguration]
$sel:queueConfigurations:NotificationConfiguration' :: NotificationConfiguration -> Maybe [QueueConfiguration]
$sel:lambdaFunctionConfigurations:NotificationConfiguration' :: NotificationConfiguration -> Maybe [LambdaFunctionConfiguration]
$sel:eventBridgeConfiguration:NotificationConfiguration' :: NotificationConfiguration -> Maybe EventBridgeConfiguration
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EventBridgeConfiguration
eventBridgeConfiguration
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [LambdaFunctionConfiguration]
lambdaFunctionConfigurations
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [QueueConfiguration]
queueConfigurations
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [TopicConfiguration]
topicConfigurations

instance Prelude.NFData NotificationConfiguration where
  rnf :: NotificationConfiguration -> ()
rnf NotificationConfiguration' {Maybe [QueueConfiguration]
Maybe [LambdaFunctionConfiguration]
Maybe [TopicConfiguration]
Maybe EventBridgeConfiguration
topicConfigurations :: Maybe [TopicConfiguration]
queueConfigurations :: Maybe [QueueConfiguration]
lambdaFunctionConfigurations :: Maybe [LambdaFunctionConfiguration]
eventBridgeConfiguration :: Maybe EventBridgeConfiguration
$sel:topicConfigurations:NotificationConfiguration' :: NotificationConfiguration -> Maybe [TopicConfiguration]
$sel:queueConfigurations:NotificationConfiguration' :: NotificationConfiguration -> Maybe [QueueConfiguration]
$sel:lambdaFunctionConfigurations:NotificationConfiguration' :: NotificationConfiguration -> Maybe [LambdaFunctionConfiguration]
$sel:eventBridgeConfiguration:NotificationConfiguration' :: NotificationConfiguration -> Maybe EventBridgeConfiguration
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe EventBridgeConfiguration
eventBridgeConfiguration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [LambdaFunctionConfiguration]
lambdaFunctionConfigurations
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [QueueConfiguration]
queueConfigurations
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [TopicConfiguration]
topicConfigurations

instance Data.ToXML NotificationConfiguration where
  toXML :: NotificationConfiguration -> XML
toXML NotificationConfiguration' {Maybe [QueueConfiguration]
Maybe [LambdaFunctionConfiguration]
Maybe [TopicConfiguration]
Maybe EventBridgeConfiguration
topicConfigurations :: Maybe [TopicConfiguration]
queueConfigurations :: Maybe [QueueConfiguration]
lambdaFunctionConfigurations :: Maybe [LambdaFunctionConfiguration]
eventBridgeConfiguration :: Maybe EventBridgeConfiguration
$sel:topicConfigurations:NotificationConfiguration' :: NotificationConfiguration -> Maybe [TopicConfiguration]
$sel:queueConfigurations:NotificationConfiguration' :: NotificationConfiguration -> Maybe [QueueConfiguration]
$sel:lambdaFunctionConfigurations:NotificationConfiguration' :: NotificationConfiguration -> Maybe [LambdaFunctionConfiguration]
$sel:eventBridgeConfiguration:NotificationConfiguration' :: NotificationConfiguration -> Maybe EventBridgeConfiguration
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"EventBridgeConfiguration"
          forall a. ToXML a => Name -> a -> XML
Data.@= Maybe EventBridgeConfiguration
eventBridgeConfiguration,
        forall a. ToXML a => a -> XML
Data.toXML
          ( forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Data.toXMLList Name
"CloudFunctionConfiguration"
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [LambdaFunctionConfiguration]
lambdaFunctionConfigurations
          ),
        forall a. ToXML a => a -> XML
Data.toXML
          ( forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Data.toXMLList Name
"QueueConfiguration"
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [QueueConfiguration]
queueConfigurations
          ),
        forall a. ToXML a => a -> XML
Data.toXML
          ( forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Data.toXMLList Name
"TopicConfiguration"
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [TopicConfiguration]
topicConfigurations
          )
      ]