{-# 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.SNSAction
-- 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.SNSAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SES.Types.SNSActionEncoding

-- | When included in a receipt rule, this action publishes a notification to
-- Amazon Simple Notification Service (Amazon SNS). This action includes a
-- complete copy of the email content in the Amazon SNS notifications.
-- Amazon SNS notifications for all other actions simply provide
-- information about the email. They do not include the email content
-- itself.
--
-- If you own the Amazon SNS topic, you don\'t need to do anything to give
-- Amazon SES permission to publish emails to it. However, if you don\'t
-- own the Amazon SNS topic, you need to attach a policy to the topic to
-- give Amazon SES permissions to access it. For information about giving
-- permissions, see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-permissions.html Amazon SES Developer Guide>.
--
-- You can only publish emails that are 150 KB or less (including the
-- header) to Amazon SNS. Larger emails will bounce. If you anticipate
-- emails larger than 150 KB, use the S3 action instead.
--
-- For information about using a receipt rule to publish an Amazon SNS
-- notification, see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-action-sns.html Amazon SES Developer Guide>.
--
-- /See:/ 'newSNSAction' smart constructor.
data SNSAction = SNSAction'
  { -- | The encoding to use for the email within the Amazon SNS notification.
    -- UTF-8 is easier to use, but may not preserve all special characters when
    -- a message was encoded with a different encoding format. Base64 preserves
    -- all special characters. The default value is UTF-8.
    SNSAction -> Maybe SNSActionEncoding
encoding :: Prelude.Maybe SNSActionEncoding,
    -- | The Amazon Resource Name (ARN) of the Amazon SNS topic to notify. An
    -- example of an Amazon SNS topic ARN is
    -- @arn:aws:sns:us-west-2:123456789012:MyTopic@. For more information about
    -- Amazon SNS topics, see the
    -- <https://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html Amazon SNS Developer Guide>.
    SNSAction -> Text
topicArn :: Prelude.Text
  }
  deriving (SNSAction -> SNSAction -> Bool
(SNSAction -> SNSAction -> Bool)
-> (SNSAction -> SNSAction -> Bool) -> Eq SNSAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SNSAction -> SNSAction -> Bool
$c/= :: SNSAction -> SNSAction -> Bool
== :: SNSAction -> SNSAction -> Bool
$c== :: SNSAction -> SNSAction -> Bool
Prelude.Eq, ReadPrec [SNSAction]
ReadPrec SNSAction
Int -> ReadS SNSAction
ReadS [SNSAction]
(Int -> ReadS SNSAction)
-> ReadS [SNSAction]
-> ReadPrec SNSAction
-> ReadPrec [SNSAction]
-> Read SNSAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SNSAction]
$creadListPrec :: ReadPrec [SNSAction]
readPrec :: ReadPrec SNSAction
$creadPrec :: ReadPrec SNSAction
readList :: ReadS [SNSAction]
$creadList :: ReadS [SNSAction]
readsPrec :: Int -> ReadS SNSAction
$creadsPrec :: Int -> ReadS SNSAction
Prelude.Read, Int -> SNSAction -> ShowS
[SNSAction] -> ShowS
SNSAction -> String
(Int -> SNSAction -> ShowS)
-> (SNSAction -> String)
-> ([SNSAction] -> ShowS)
-> Show SNSAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SNSAction] -> ShowS
$cshowList :: [SNSAction] -> ShowS
show :: SNSAction -> String
$cshow :: SNSAction -> String
showsPrec :: Int -> SNSAction -> ShowS
$cshowsPrec :: Int -> SNSAction -> ShowS
Prelude.Show, (forall x. SNSAction -> Rep SNSAction x)
-> (forall x. Rep SNSAction x -> SNSAction) -> Generic SNSAction
forall x. Rep SNSAction x -> SNSAction
forall x. SNSAction -> Rep SNSAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SNSAction x -> SNSAction
$cfrom :: forall x. SNSAction -> Rep SNSAction x
Prelude.Generic)

-- |
-- Create a value of 'SNSAction' 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:
--
-- 'encoding', 'sNSAction_encoding' - The encoding to use for the email within the Amazon SNS notification.
-- UTF-8 is easier to use, but may not preserve all special characters when
-- a message was encoded with a different encoding format. Base64 preserves
-- all special characters. The default value is UTF-8.
--
-- 'topicArn', 'sNSAction_topicArn' - The Amazon Resource Name (ARN) of the Amazon SNS topic to notify. An
-- example of an Amazon SNS topic ARN is
-- @arn:aws:sns:us-west-2:123456789012:MyTopic@. For more information about
-- Amazon SNS topics, see the
-- <https://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html Amazon SNS Developer Guide>.
newSNSAction ::
  -- | 'topicArn'
  Prelude.Text ->
  SNSAction
newSNSAction :: Text -> SNSAction
newSNSAction Text
pTopicArn_ =
  SNSAction' :: Maybe SNSActionEncoding -> Text -> SNSAction
SNSAction'
    { $sel:encoding:SNSAction' :: Maybe SNSActionEncoding
encoding = Maybe SNSActionEncoding
forall a. Maybe a
Prelude.Nothing,
      $sel:topicArn:SNSAction' :: Text
topicArn = Text
pTopicArn_
    }

-- | The encoding to use for the email within the Amazon SNS notification.
-- UTF-8 is easier to use, but may not preserve all special characters when
-- a message was encoded with a different encoding format. Base64 preserves
-- all special characters. The default value is UTF-8.
sNSAction_encoding :: Lens.Lens' SNSAction (Prelude.Maybe SNSActionEncoding)
sNSAction_encoding :: (Maybe SNSActionEncoding -> f (Maybe SNSActionEncoding))
-> SNSAction -> f SNSAction
sNSAction_encoding = (SNSAction -> Maybe SNSActionEncoding)
-> (SNSAction -> Maybe SNSActionEncoding -> SNSAction)
-> Lens
     SNSAction
     SNSAction
     (Maybe SNSActionEncoding)
     (Maybe SNSActionEncoding)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SNSAction' {Maybe SNSActionEncoding
encoding :: Maybe SNSActionEncoding
$sel:encoding:SNSAction' :: SNSAction -> Maybe SNSActionEncoding
encoding} -> Maybe SNSActionEncoding
encoding) (\s :: SNSAction
s@SNSAction' {} Maybe SNSActionEncoding
a -> SNSAction
s {$sel:encoding:SNSAction' :: Maybe SNSActionEncoding
encoding = Maybe SNSActionEncoding
a} :: SNSAction)

-- | The Amazon Resource Name (ARN) of the Amazon SNS topic to notify. An
-- example of an Amazon SNS topic ARN is
-- @arn:aws:sns:us-west-2:123456789012:MyTopic@. For more information about
-- Amazon SNS topics, see the
-- <https://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html Amazon SNS Developer Guide>.
sNSAction_topicArn :: Lens.Lens' SNSAction Prelude.Text
sNSAction_topicArn :: (Text -> f Text) -> SNSAction -> f SNSAction
sNSAction_topicArn = (SNSAction -> Text)
-> (SNSAction -> Text -> SNSAction)
-> Lens SNSAction SNSAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SNSAction' {Text
topicArn :: Text
$sel:topicArn:SNSAction' :: SNSAction -> Text
topicArn} -> Text
topicArn) (\s :: SNSAction
s@SNSAction' {} Text
a -> SNSAction
s {$sel:topicArn:SNSAction' :: Text
topicArn = Text
a} :: SNSAction)

instance Core.FromXML SNSAction where
  parseXML :: [Node] -> Either String SNSAction
parseXML [Node]
x =
    Maybe SNSActionEncoding -> Text -> SNSAction
SNSAction'
      (Maybe SNSActionEncoding -> Text -> SNSAction)
-> Either String (Maybe SNSActionEncoding)
-> Either String (Text -> SNSAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe SNSActionEncoding)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Encoding")
      Either String (Text -> SNSAction)
-> Either String Text -> Either String SNSAction
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
"TopicArn")

instance Prelude.Hashable SNSAction

instance Prelude.NFData SNSAction

instance Core.ToQuery SNSAction where
  toQuery :: SNSAction -> QueryString
toQuery SNSAction' {Maybe SNSActionEncoding
Text
topicArn :: Text
encoding :: Maybe SNSActionEncoding
$sel:topicArn:SNSAction' :: SNSAction -> Text
$sel:encoding:SNSAction' :: SNSAction -> Maybe SNSActionEncoding
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Encoding" ByteString -> Maybe SNSActionEncoding -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe SNSActionEncoding
encoding,
        ByteString
"TopicArn" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
topicArn
      ]