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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.S3.Internal
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'
  { -- | 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],
    -- | Describes the Lambda functions to invoke and the events for which to
    -- invoke them.
    NotificationConfiguration -> Maybe [LambdaFunctionConfiguration]
lambdaFunctionConfigurations :: Prelude.Maybe [LambdaFunctionConfiguration]
  }
  deriving (NotificationConfiguration -> NotificationConfiguration -> Bool
(NotificationConfiguration -> NotificationConfiguration -> Bool)
-> (NotificationConfiguration -> NotificationConfiguration -> Bool)
-> Eq NotificationConfiguration
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]
(Int -> ReadS NotificationConfiguration)
-> ReadS [NotificationConfiguration]
-> ReadPrec NotificationConfiguration
-> ReadPrec [NotificationConfiguration]
-> Read 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
(Int -> NotificationConfiguration -> ShowS)
-> (NotificationConfiguration -> String)
-> ([NotificationConfiguration] -> ShowS)
-> Show NotificationConfiguration
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.
 NotificationConfiguration -> Rep NotificationConfiguration x)
-> (forall x.
    Rep NotificationConfiguration x -> NotificationConfiguration)
-> Generic NotificationConfiguration
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:
--
-- '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.
--
-- 'lambdaFunctionConfigurations', 'notificationConfiguration_lambdaFunctionConfigurations' - Describes the Lambda functions to invoke and the events for which to
-- invoke them.
newNotificationConfiguration ::
  NotificationConfiguration
newNotificationConfiguration :: NotificationConfiguration
newNotificationConfiguration =
  NotificationConfiguration' :: Maybe [QueueConfiguration]
-> Maybe [TopicConfiguration]
-> Maybe [LambdaFunctionConfiguration]
-> NotificationConfiguration
NotificationConfiguration'
    { $sel:queueConfigurations:NotificationConfiguration' :: Maybe [QueueConfiguration]
queueConfigurations =
        Maybe [QueueConfiguration]
forall a. Maybe a
Prelude.Nothing,
      $sel:topicConfigurations:NotificationConfiguration' :: Maybe [TopicConfiguration]
topicConfigurations = Maybe [TopicConfiguration]
forall a. Maybe a
Prelude.Nothing,
      $sel:lambdaFunctionConfigurations:NotificationConfiguration' :: Maybe [LambdaFunctionConfiguration]
lambdaFunctionConfigurations = Maybe [LambdaFunctionConfiguration]
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe [QueueConfiguration] -> f (Maybe [QueueConfiguration]))
-> NotificationConfiguration -> f NotificationConfiguration
notificationConfiguration_queueConfigurations = (NotificationConfiguration -> Maybe [QueueConfiguration])
-> (NotificationConfiguration
    -> Maybe [QueueConfiguration] -> NotificationConfiguration)
-> Lens
     NotificationConfiguration
     NotificationConfiguration
     (Maybe [QueueConfiguration])
     (Maybe [QueueConfiguration])
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) ((Maybe [QueueConfiguration] -> f (Maybe [QueueConfiguration]))
 -> NotificationConfiguration -> f NotificationConfiguration)
-> ((Maybe [QueueConfiguration] -> f (Maybe [QueueConfiguration]))
    -> Maybe [QueueConfiguration] -> f (Maybe [QueueConfiguration]))
-> (Maybe [QueueConfiguration] -> f (Maybe [QueueConfiguration]))
-> NotificationConfiguration
-> f NotificationConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [QueueConfiguration]
  [QueueConfiguration]
  [QueueConfiguration]
  [QueueConfiguration]
-> Iso
     (Maybe [QueueConfiguration])
     (Maybe [QueueConfiguration])
     (Maybe [QueueConfiguration])
     (Maybe [QueueConfiguration])
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 AnIso
  [QueueConfiguration]
  [QueueConfiguration]
  [QueueConfiguration]
  [QueueConfiguration]
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 :: (Maybe [TopicConfiguration] -> f (Maybe [TopicConfiguration]))
-> NotificationConfiguration -> f NotificationConfiguration
notificationConfiguration_topicConfigurations = (NotificationConfiguration -> Maybe [TopicConfiguration])
-> (NotificationConfiguration
    -> Maybe [TopicConfiguration] -> NotificationConfiguration)
-> Lens
     NotificationConfiguration
     NotificationConfiguration
     (Maybe [TopicConfiguration])
     (Maybe [TopicConfiguration])
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) ((Maybe [TopicConfiguration] -> f (Maybe [TopicConfiguration]))
 -> NotificationConfiguration -> f NotificationConfiguration)
-> ((Maybe [TopicConfiguration] -> f (Maybe [TopicConfiguration]))
    -> Maybe [TopicConfiguration] -> f (Maybe [TopicConfiguration]))
-> (Maybe [TopicConfiguration] -> f (Maybe [TopicConfiguration]))
-> NotificationConfiguration
-> f NotificationConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [TopicConfiguration]
  [TopicConfiguration]
  [TopicConfiguration]
  [TopicConfiguration]
-> Iso
     (Maybe [TopicConfiguration])
     (Maybe [TopicConfiguration])
     (Maybe [TopicConfiguration])
     (Maybe [TopicConfiguration])
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 AnIso
  [TopicConfiguration]
  [TopicConfiguration]
  [TopicConfiguration]
  [TopicConfiguration]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Describes the Lambda functions to invoke and the events for which to
-- invoke them.
notificationConfiguration_lambdaFunctionConfigurations :: Lens.Lens' NotificationConfiguration (Prelude.Maybe [LambdaFunctionConfiguration])
notificationConfiguration_lambdaFunctionConfigurations :: (Maybe [LambdaFunctionConfiguration]
 -> f (Maybe [LambdaFunctionConfiguration]))
-> NotificationConfiguration -> f NotificationConfiguration
notificationConfiguration_lambdaFunctionConfigurations = (NotificationConfiguration -> Maybe [LambdaFunctionConfiguration])
-> (NotificationConfiguration
    -> Maybe [LambdaFunctionConfiguration]
    -> NotificationConfiguration)
-> Lens
     NotificationConfiguration
     NotificationConfiguration
     (Maybe [LambdaFunctionConfiguration])
     (Maybe [LambdaFunctionConfiguration])
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) ((Maybe [LambdaFunctionConfiguration]
  -> f (Maybe [LambdaFunctionConfiguration]))
 -> NotificationConfiguration -> f NotificationConfiguration)
-> ((Maybe [LambdaFunctionConfiguration]
     -> f (Maybe [LambdaFunctionConfiguration]))
    -> Maybe [LambdaFunctionConfiguration]
    -> f (Maybe [LambdaFunctionConfiguration]))
-> (Maybe [LambdaFunctionConfiguration]
    -> f (Maybe [LambdaFunctionConfiguration]))
-> NotificationConfiguration
-> f NotificationConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [LambdaFunctionConfiguration]
  [LambdaFunctionConfiguration]
  [LambdaFunctionConfiguration]
  [LambdaFunctionConfiguration]
-> Iso
     (Maybe [LambdaFunctionConfiguration])
     (Maybe [LambdaFunctionConfiguration])
     (Maybe [LambdaFunctionConfiguration])
     (Maybe [LambdaFunctionConfiguration])
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 AnIso
  [LambdaFunctionConfiguration]
  [LambdaFunctionConfiguration]
  [LambdaFunctionConfiguration]
  [LambdaFunctionConfiguration]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable NotificationConfiguration

instance Prelude.NFData NotificationConfiguration

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