{-# 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.TopicConfiguration
-- 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.TopicConfiguration 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.Event
import Amazonka.S3.Types.NotificationConfigurationFilter

-- | A container for specifying the configuration for publication of messages
-- to an Amazon Simple Notification Service (Amazon SNS) topic when Amazon
-- S3 detects specified events.
--
-- /See:/ 'newTopicConfiguration' smart constructor.
data TopicConfiguration = TopicConfiguration'
  { TopicConfiguration -> Maybe NotificationConfigurationFilter
filter' :: Prelude.Maybe NotificationConfigurationFilter,
    TopicConfiguration -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the Amazon SNS topic to which Amazon
    -- S3 publishes a message when it detects events of the specified type.
    TopicConfiguration -> Text
topicArn :: Prelude.Text,
    -- | The Amazon S3 bucket event about which to send notifications. For more
    -- information, see
    -- <https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html Supported Event Types>
    -- in the /Amazon S3 User Guide/.
    TopicConfiguration -> [Event]
events :: [Event]
  }
  deriving (TopicConfiguration -> TopicConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TopicConfiguration -> TopicConfiguration -> Bool
$c/= :: TopicConfiguration -> TopicConfiguration -> Bool
== :: TopicConfiguration -> TopicConfiguration -> Bool
$c== :: TopicConfiguration -> TopicConfiguration -> Bool
Prelude.Eq, ReadPrec [TopicConfiguration]
ReadPrec TopicConfiguration
Int -> ReadS TopicConfiguration
ReadS [TopicConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TopicConfiguration]
$creadListPrec :: ReadPrec [TopicConfiguration]
readPrec :: ReadPrec TopicConfiguration
$creadPrec :: ReadPrec TopicConfiguration
readList :: ReadS [TopicConfiguration]
$creadList :: ReadS [TopicConfiguration]
readsPrec :: Int -> ReadS TopicConfiguration
$creadsPrec :: Int -> ReadS TopicConfiguration
Prelude.Read, Int -> TopicConfiguration -> ShowS
[TopicConfiguration] -> ShowS
TopicConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TopicConfiguration] -> ShowS
$cshowList :: [TopicConfiguration] -> ShowS
show :: TopicConfiguration -> String
$cshow :: TopicConfiguration -> String
showsPrec :: Int -> TopicConfiguration -> ShowS
$cshowsPrec :: Int -> TopicConfiguration -> ShowS
Prelude.Show, forall x. Rep TopicConfiguration x -> TopicConfiguration
forall x. TopicConfiguration -> Rep TopicConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TopicConfiguration x -> TopicConfiguration
$cfrom :: forall x. TopicConfiguration -> Rep TopicConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'TopicConfiguration' 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:
--
-- 'filter'', 'topicConfiguration_filter' - Undocumented member.
--
-- 'id', 'topicConfiguration_id' - Undocumented member.
--
-- 'topicArn', 'topicConfiguration_topicArn' - The Amazon Resource Name (ARN) of the Amazon SNS topic to which Amazon
-- S3 publishes a message when it detects events of the specified type.
--
-- 'events', 'topicConfiguration_events' - The Amazon S3 bucket event about which to send notifications. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html Supported Event Types>
-- in the /Amazon S3 User Guide/.
newTopicConfiguration ::
  -- | 'topicArn'
  Prelude.Text ->
  TopicConfiguration
newTopicConfiguration :: Text -> TopicConfiguration
newTopicConfiguration Text
pTopicArn_ =
  TopicConfiguration'
    { $sel:filter':TopicConfiguration' :: Maybe NotificationConfigurationFilter
filter' = forall a. Maybe a
Prelude.Nothing,
      $sel:id:TopicConfiguration' :: Maybe Text
id = forall a. Maybe a
Prelude.Nothing,
      $sel:topicArn:TopicConfiguration' :: Text
topicArn = Text
pTopicArn_,
      $sel:events:TopicConfiguration' :: [Event]
events = forall a. Monoid a => a
Prelude.mempty
    }

-- | Undocumented member.
topicConfiguration_filter :: Lens.Lens' TopicConfiguration (Prelude.Maybe NotificationConfigurationFilter)
topicConfiguration_filter :: Lens' TopicConfiguration (Maybe NotificationConfigurationFilter)
topicConfiguration_filter = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TopicConfiguration' {Maybe NotificationConfigurationFilter
filter' :: Maybe NotificationConfigurationFilter
$sel:filter':TopicConfiguration' :: TopicConfiguration -> Maybe NotificationConfigurationFilter
filter'} -> Maybe NotificationConfigurationFilter
filter') (\s :: TopicConfiguration
s@TopicConfiguration' {} Maybe NotificationConfigurationFilter
a -> TopicConfiguration
s {$sel:filter':TopicConfiguration' :: Maybe NotificationConfigurationFilter
filter' = Maybe NotificationConfigurationFilter
a} :: TopicConfiguration)

-- | Undocumented member.
topicConfiguration_id :: Lens.Lens' TopicConfiguration (Prelude.Maybe Prelude.Text)
topicConfiguration_id :: Lens' TopicConfiguration (Maybe Text)
topicConfiguration_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TopicConfiguration' {Maybe Text
id :: Maybe Text
$sel:id:TopicConfiguration' :: TopicConfiguration -> Maybe Text
id} -> Maybe Text
id) (\s :: TopicConfiguration
s@TopicConfiguration' {} Maybe Text
a -> TopicConfiguration
s {$sel:id:TopicConfiguration' :: Maybe Text
id = Maybe Text
a} :: TopicConfiguration)

-- | The Amazon Resource Name (ARN) of the Amazon SNS topic to which Amazon
-- S3 publishes a message when it detects events of the specified type.
topicConfiguration_topicArn :: Lens.Lens' TopicConfiguration Prelude.Text
topicConfiguration_topicArn :: Lens' TopicConfiguration Text
topicConfiguration_topicArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TopicConfiguration' {Text
topicArn :: Text
$sel:topicArn:TopicConfiguration' :: TopicConfiguration -> Text
topicArn} -> Text
topicArn) (\s :: TopicConfiguration
s@TopicConfiguration' {} Text
a -> TopicConfiguration
s {$sel:topicArn:TopicConfiguration' :: Text
topicArn = Text
a} :: TopicConfiguration)

-- | The Amazon S3 bucket event about which to send notifications. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html Supported Event Types>
-- in the /Amazon S3 User Guide/.
topicConfiguration_events :: Lens.Lens' TopicConfiguration [Event]
topicConfiguration_events :: Lens' TopicConfiguration [Event]
topicConfiguration_events = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TopicConfiguration' {[Event]
events :: [Event]
$sel:events:TopicConfiguration' :: TopicConfiguration -> [Event]
events} -> [Event]
events) (\s :: TopicConfiguration
s@TopicConfiguration' {} [Event]
a -> TopicConfiguration
s {$sel:events:TopicConfiguration' :: [Event]
events = [Event]
a} :: TopicConfiguration) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromXML TopicConfiguration where
  parseXML :: [Node] -> Either String TopicConfiguration
parseXML [Node]
x =
    Maybe NotificationConfigurationFilter
-> Maybe Text -> Text -> [Event] -> TopicConfiguration
TopicConfiguration'
      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
"Filter")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Id")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Topic")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"Event" [Node]
x)

instance Prelude.Hashable TopicConfiguration where
  hashWithSalt :: Int -> TopicConfiguration -> Int
hashWithSalt Int
_salt TopicConfiguration' {[Event]
Maybe Text
Maybe NotificationConfigurationFilter
Text
events :: [Event]
topicArn :: Text
id :: Maybe Text
filter' :: Maybe NotificationConfigurationFilter
$sel:events:TopicConfiguration' :: TopicConfiguration -> [Event]
$sel:topicArn:TopicConfiguration' :: TopicConfiguration -> Text
$sel:id:TopicConfiguration' :: TopicConfiguration -> Maybe Text
$sel:filter':TopicConfiguration' :: TopicConfiguration -> Maybe NotificationConfigurationFilter
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe NotificationConfigurationFilter
filter'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
topicArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Event]
events

instance Prelude.NFData TopicConfiguration where
  rnf :: TopicConfiguration -> ()
rnf TopicConfiguration' {[Event]
Maybe Text
Maybe NotificationConfigurationFilter
Text
events :: [Event]
topicArn :: Text
id :: Maybe Text
filter' :: Maybe NotificationConfigurationFilter
$sel:events:TopicConfiguration' :: TopicConfiguration -> [Event]
$sel:topicArn:TopicConfiguration' :: TopicConfiguration -> Text
$sel:id:TopicConfiguration' :: TopicConfiguration -> Maybe Text
$sel:filter':TopicConfiguration' :: TopicConfiguration -> Maybe NotificationConfigurationFilter
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe NotificationConfigurationFilter
filter'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
id
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
topicArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Event]
events

instance Data.ToXML TopicConfiguration where
  toXML :: TopicConfiguration -> XML
toXML TopicConfiguration' {[Event]
Maybe Text
Maybe NotificationConfigurationFilter
Text
events :: [Event]
topicArn :: Text
id :: Maybe Text
filter' :: Maybe NotificationConfigurationFilter
$sel:events:TopicConfiguration' :: TopicConfiguration -> [Event]
$sel:topicArn:TopicConfiguration' :: TopicConfiguration -> Text
$sel:id:TopicConfiguration' :: TopicConfiguration -> Maybe Text
$sel:filter':TopicConfiguration' :: TopicConfiguration -> Maybe NotificationConfigurationFilter
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Filter" forall a. ToXML a => Name -> a -> XML
Data.@= Maybe NotificationConfigurationFilter
filter',
        Name
"Id" forall a. ToXML a => Name -> a -> XML
Data.@= Maybe Text
id,
        Name
"Topic" forall a. ToXML a => Name -> a -> XML
Data.@= Text
topicArn,
        forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Data.toXMLList Name
"Event" [Event]
events
      ]