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

-- | Specifies the configuration for publishing messages to an Amazon Simple
-- Queue Service (Amazon SQS) queue when Amazon S3 detects specified
-- events.
--
-- /See:/ 'newQueueConfiguration' smart constructor.
data QueueConfiguration = QueueConfiguration'
  { QueueConfiguration -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    QueueConfiguration -> Maybe NotificationConfigurationFilter
filter' :: Prelude.Maybe NotificationConfigurationFilter,
    -- | The Amazon Resource Name (ARN) of the Amazon SQS queue to which Amazon
    -- S3 publishes a message when it detects events of the specified type.
    QueueConfiguration -> Text
queueArn :: Prelude.Text,
    -- | A collection of bucket events for which to send notifications
    QueueConfiguration -> [Event]
events :: [Event]
  }
  deriving (QueueConfiguration -> QueueConfiguration -> Bool
(QueueConfiguration -> QueueConfiguration -> Bool)
-> (QueueConfiguration -> QueueConfiguration -> Bool)
-> Eq QueueConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueueConfiguration -> QueueConfiguration -> Bool
$c/= :: QueueConfiguration -> QueueConfiguration -> Bool
== :: QueueConfiguration -> QueueConfiguration -> Bool
$c== :: QueueConfiguration -> QueueConfiguration -> Bool
Prelude.Eq, ReadPrec [QueueConfiguration]
ReadPrec QueueConfiguration
Int -> ReadS QueueConfiguration
ReadS [QueueConfiguration]
(Int -> ReadS QueueConfiguration)
-> ReadS [QueueConfiguration]
-> ReadPrec QueueConfiguration
-> ReadPrec [QueueConfiguration]
-> Read QueueConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [QueueConfiguration]
$creadListPrec :: ReadPrec [QueueConfiguration]
readPrec :: ReadPrec QueueConfiguration
$creadPrec :: ReadPrec QueueConfiguration
readList :: ReadS [QueueConfiguration]
$creadList :: ReadS [QueueConfiguration]
readsPrec :: Int -> ReadS QueueConfiguration
$creadsPrec :: Int -> ReadS QueueConfiguration
Prelude.Read, Int -> QueueConfiguration -> ShowS
[QueueConfiguration] -> ShowS
QueueConfiguration -> String
(Int -> QueueConfiguration -> ShowS)
-> (QueueConfiguration -> String)
-> ([QueueConfiguration] -> ShowS)
-> Show QueueConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueueConfiguration] -> ShowS
$cshowList :: [QueueConfiguration] -> ShowS
show :: QueueConfiguration -> String
$cshow :: QueueConfiguration -> String
showsPrec :: Int -> QueueConfiguration -> ShowS
$cshowsPrec :: Int -> QueueConfiguration -> ShowS
Prelude.Show, (forall x. QueueConfiguration -> Rep QueueConfiguration x)
-> (forall x. Rep QueueConfiguration x -> QueueConfiguration)
-> Generic QueueConfiguration
forall x. Rep QueueConfiguration x -> QueueConfiguration
forall x. QueueConfiguration -> Rep QueueConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep QueueConfiguration x -> QueueConfiguration
$cfrom :: forall x. QueueConfiguration -> Rep QueueConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'QueueConfiguration' 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:
--
-- 'id', 'queueConfiguration_id' - Undocumented member.
--
-- 'filter'', 'queueConfiguration_filter' - Undocumented member.
--
-- 'queueArn', 'queueConfiguration_queueArn' - The Amazon Resource Name (ARN) of the Amazon SQS queue to which Amazon
-- S3 publishes a message when it detects events of the specified type.
--
-- 'events', 'queueConfiguration_events' - A collection of bucket events for which to send notifications
newQueueConfiguration ::
  -- | 'queueArn'
  Prelude.Text ->
  QueueConfiguration
newQueueConfiguration :: Text -> QueueConfiguration
newQueueConfiguration Text
pQueueArn_ =
  QueueConfiguration' :: Maybe Text
-> Maybe NotificationConfigurationFilter
-> Text
-> [Event]
-> QueueConfiguration
QueueConfiguration'
    { $sel:id:QueueConfiguration' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:filter':QueueConfiguration' :: Maybe NotificationConfigurationFilter
filter' = Maybe NotificationConfigurationFilter
forall a. Maybe a
Prelude.Nothing,
      $sel:queueArn:QueueConfiguration' :: Text
queueArn = Text
pQueueArn_,
      $sel:events:QueueConfiguration' :: [Event]
events = [Event]
forall a. Monoid a => a
Prelude.mempty
    }

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

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

-- | The Amazon Resource Name (ARN) of the Amazon SQS queue to which Amazon
-- S3 publishes a message when it detects events of the specified type.
queueConfiguration_queueArn :: Lens.Lens' QueueConfiguration Prelude.Text
queueConfiguration_queueArn :: (Text -> f Text) -> QueueConfiguration -> f QueueConfiguration
queueConfiguration_queueArn = (QueueConfiguration -> Text)
-> (QueueConfiguration -> Text -> QueueConfiguration)
-> Lens QueueConfiguration QueueConfiguration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueueConfiguration' {Text
queueArn :: Text
$sel:queueArn:QueueConfiguration' :: QueueConfiguration -> Text
queueArn} -> Text
queueArn) (\s :: QueueConfiguration
s@QueueConfiguration' {} Text
a -> QueueConfiguration
s {$sel:queueArn:QueueConfiguration' :: Text
queueArn = Text
a} :: QueueConfiguration)

-- | A collection of bucket events for which to send notifications
queueConfiguration_events :: Lens.Lens' QueueConfiguration [Event]
queueConfiguration_events :: ([Event] -> f [Event])
-> QueueConfiguration -> f QueueConfiguration
queueConfiguration_events = (QueueConfiguration -> [Event])
-> (QueueConfiguration -> [Event] -> QueueConfiguration)
-> Lens QueueConfiguration QueueConfiguration [Event] [Event]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueueConfiguration' {[Event]
events :: [Event]
$sel:events:QueueConfiguration' :: QueueConfiguration -> [Event]
events} -> [Event]
events) (\s :: QueueConfiguration
s@QueueConfiguration' {} [Event]
a -> QueueConfiguration
s {$sel:events:QueueConfiguration' :: [Event]
events = [Event]
a} :: QueueConfiguration) (([Event] -> f [Event])
 -> QueueConfiguration -> f QueueConfiguration)
-> (([Event] -> f [Event]) -> [Event] -> f [Event])
-> ([Event] -> f [Event])
-> QueueConfiguration
-> f QueueConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Event] -> f [Event]) -> [Event] -> f [Event]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable QueueConfiguration

instance Prelude.NFData QueueConfiguration

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