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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | When included in a receipt rule, this action rejects the received email
-- by returning a bounce response to the sender and, optionally, publishes
-- a notification to Amazon Simple Notification Service (Amazon SNS).
--
-- For information about sending a bounce message in response to a received
-- email, see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-action-bounce.html Amazon SES Developer Guide>.
--
-- /See:/ 'newBounceAction' smart constructor.
data BounceAction = BounceAction'
  { -- | The Amazon Resource Name (ARN) of the Amazon SNS topic to notify when
    -- the bounce action is taken. 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>.
    BounceAction -> Maybe Text
topicArn :: Prelude.Maybe Prelude.Text,
    -- | The SMTP enhanced status code, as defined by
    -- <https://tools.ietf.org/html/rfc3463 RFC 3463>.
    BounceAction -> Maybe Text
statusCode :: Prelude.Maybe Prelude.Text,
    -- | The SMTP reply code, as defined by
    -- <https://tools.ietf.org/html/rfc5321 RFC 5321>.
    BounceAction -> Text
smtpReplyCode :: Prelude.Text,
    -- | Human-readable text to include in the bounce message.
    BounceAction -> Text
message :: Prelude.Text,
    -- | The email address of the sender of the bounced email. This is the
    -- address from which the bounce message will be sent.
    BounceAction -> Text
sender :: Prelude.Text
  }
  deriving (BounceAction -> BounceAction -> Bool
(BounceAction -> BounceAction -> Bool)
-> (BounceAction -> BounceAction -> Bool) -> Eq BounceAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BounceAction -> BounceAction -> Bool
$c/= :: BounceAction -> BounceAction -> Bool
== :: BounceAction -> BounceAction -> Bool
$c== :: BounceAction -> BounceAction -> Bool
Prelude.Eq, ReadPrec [BounceAction]
ReadPrec BounceAction
Int -> ReadS BounceAction
ReadS [BounceAction]
(Int -> ReadS BounceAction)
-> ReadS [BounceAction]
-> ReadPrec BounceAction
-> ReadPrec [BounceAction]
-> Read BounceAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BounceAction]
$creadListPrec :: ReadPrec [BounceAction]
readPrec :: ReadPrec BounceAction
$creadPrec :: ReadPrec BounceAction
readList :: ReadS [BounceAction]
$creadList :: ReadS [BounceAction]
readsPrec :: Int -> ReadS BounceAction
$creadsPrec :: Int -> ReadS BounceAction
Prelude.Read, Int -> BounceAction -> ShowS
[BounceAction] -> ShowS
BounceAction -> String
(Int -> BounceAction -> ShowS)
-> (BounceAction -> String)
-> ([BounceAction] -> ShowS)
-> Show BounceAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BounceAction] -> ShowS
$cshowList :: [BounceAction] -> ShowS
show :: BounceAction -> String
$cshow :: BounceAction -> String
showsPrec :: Int -> BounceAction -> ShowS
$cshowsPrec :: Int -> BounceAction -> ShowS
Prelude.Show, (forall x. BounceAction -> Rep BounceAction x)
-> (forall x. Rep BounceAction x -> BounceAction)
-> Generic BounceAction
forall x. Rep BounceAction x -> BounceAction
forall x. BounceAction -> Rep BounceAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BounceAction x -> BounceAction
$cfrom :: forall x. BounceAction -> Rep BounceAction x
Prelude.Generic)

-- |
-- Create a value of 'BounceAction' 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:
--
-- 'topicArn', 'bounceAction_topicArn' - The Amazon Resource Name (ARN) of the Amazon SNS topic to notify when
-- the bounce action is taken. 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>.
--
-- 'statusCode', 'bounceAction_statusCode' - The SMTP enhanced status code, as defined by
-- <https://tools.ietf.org/html/rfc3463 RFC 3463>.
--
-- 'smtpReplyCode', 'bounceAction_smtpReplyCode' - The SMTP reply code, as defined by
-- <https://tools.ietf.org/html/rfc5321 RFC 5321>.
--
-- 'message', 'bounceAction_message' - Human-readable text to include in the bounce message.
--
-- 'sender', 'bounceAction_sender' - The email address of the sender of the bounced email. This is the
-- address from which the bounce message will be sent.
newBounceAction ::
  -- | 'smtpReplyCode'
  Prelude.Text ->
  -- | 'message'
  Prelude.Text ->
  -- | 'sender'
  Prelude.Text ->
  BounceAction
newBounceAction :: Text -> Text -> Text -> BounceAction
newBounceAction Text
pSmtpReplyCode_ Text
pMessage_ Text
pSender_ =
  BounceAction' :: Maybe Text -> Maybe Text -> Text -> Text -> Text -> BounceAction
BounceAction'
    { $sel:topicArn:BounceAction' :: Maybe Text
topicArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:statusCode:BounceAction' :: Maybe Text
statusCode = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:smtpReplyCode:BounceAction' :: Text
smtpReplyCode = Text
pSmtpReplyCode_,
      $sel:message:BounceAction' :: Text
message = Text
pMessage_,
      $sel:sender:BounceAction' :: Text
sender = Text
pSender_
    }

-- | The Amazon Resource Name (ARN) of the Amazon SNS topic to notify when
-- the bounce action is taken. 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>.
bounceAction_topicArn :: Lens.Lens' BounceAction (Prelude.Maybe Prelude.Text)
bounceAction_topicArn :: (Maybe Text -> f (Maybe Text)) -> BounceAction -> f BounceAction
bounceAction_topicArn = (BounceAction -> Maybe Text)
-> (BounceAction -> Maybe Text -> BounceAction)
-> Lens BounceAction BounceAction (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BounceAction' {Maybe Text
topicArn :: Maybe Text
$sel:topicArn:BounceAction' :: BounceAction -> Maybe Text
topicArn} -> Maybe Text
topicArn) (\s :: BounceAction
s@BounceAction' {} Maybe Text
a -> BounceAction
s {$sel:topicArn:BounceAction' :: Maybe Text
topicArn = Maybe Text
a} :: BounceAction)

-- | The SMTP enhanced status code, as defined by
-- <https://tools.ietf.org/html/rfc3463 RFC 3463>.
bounceAction_statusCode :: Lens.Lens' BounceAction (Prelude.Maybe Prelude.Text)
bounceAction_statusCode :: (Maybe Text -> f (Maybe Text)) -> BounceAction -> f BounceAction
bounceAction_statusCode = (BounceAction -> Maybe Text)
-> (BounceAction -> Maybe Text -> BounceAction)
-> Lens BounceAction BounceAction (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BounceAction' {Maybe Text
statusCode :: Maybe Text
$sel:statusCode:BounceAction' :: BounceAction -> Maybe Text
statusCode} -> Maybe Text
statusCode) (\s :: BounceAction
s@BounceAction' {} Maybe Text
a -> BounceAction
s {$sel:statusCode:BounceAction' :: Maybe Text
statusCode = Maybe Text
a} :: BounceAction)

-- | The SMTP reply code, as defined by
-- <https://tools.ietf.org/html/rfc5321 RFC 5321>.
bounceAction_smtpReplyCode :: Lens.Lens' BounceAction Prelude.Text
bounceAction_smtpReplyCode :: (Text -> f Text) -> BounceAction -> f BounceAction
bounceAction_smtpReplyCode = (BounceAction -> Text)
-> (BounceAction -> Text -> BounceAction)
-> Lens BounceAction BounceAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BounceAction' {Text
smtpReplyCode :: Text
$sel:smtpReplyCode:BounceAction' :: BounceAction -> Text
smtpReplyCode} -> Text
smtpReplyCode) (\s :: BounceAction
s@BounceAction' {} Text
a -> BounceAction
s {$sel:smtpReplyCode:BounceAction' :: Text
smtpReplyCode = Text
a} :: BounceAction)

-- | Human-readable text to include in the bounce message.
bounceAction_message :: Lens.Lens' BounceAction Prelude.Text
bounceAction_message :: (Text -> f Text) -> BounceAction -> f BounceAction
bounceAction_message = (BounceAction -> Text)
-> (BounceAction -> Text -> BounceAction)
-> Lens BounceAction BounceAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BounceAction' {Text
message :: Text
$sel:message:BounceAction' :: BounceAction -> Text
message} -> Text
message) (\s :: BounceAction
s@BounceAction' {} Text
a -> BounceAction
s {$sel:message:BounceAction' :: Text
message = Text
a} :: BounceAction)

-- | The email address of the sender of the bounced email. This is the
-- address from which the bounce message will be sent.
bounceAction_sender :: Lens.Lens' BounceAction Prelude.Text
bounceAction_sender :: (Text -> f Text) -> BounceAction -> f BounceAction
bounceAction_sender = (BounceAction -> Text)
-> (BounceAction -> Text -> BounceAction)
-> Lens BounceAction BounceAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BounceAction' {Text
sender :: Text
$sel:sender:BounceAction' :: BounceAction -> Text
sender} -> Text
sender) (\s :: BounceAction
s@BounceAction' {} Text
a -> BounceAction
s {$sel:sender:BounceAction' :: Text
sender = Text
a} :: BounceAction)

instance Core.FromXML BounceAction where
  parseXML :: [Node] -> Either String BounceAction
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> Text -> Text -> Text -> BounceAction
BounceAction'
      (Maybe Text -> Maybe Text -> Text -> Text -> Text -> BounceAction)
-> Either String (Maybe Text)
-> Either
     String (Maybe Text -> Text -> Text -> Text -> BounceAction)
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
"TopicArn")
      Either String (Maybe Text -> Text -> Text -> Text -> BounceAction)
-> Either String (Maybe Text)
-> Either String (Text -> Text -> Text -> BounceAction)
forall (f :: * -> *) a b. Applicative f => 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
"StatusCode")
      Either String (Text -> Text -> Text -> BounceAction)
-> Either String Text
-> Either String (Text -> Text -> BounceAction)
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
"SmtpReplyCode")
      Either String (Text -> Text -> BounceAction)
-> Either String Text -> Either String (Text -> BounceAction)
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
"Message")
      Either String (Text -> BounceAction)
-> Either String Text -> Either String BounceAction
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
"Sender")

instance Prelude.Hashable BounceAction

instance Prelude.NFData BounceAction

instance Core.ToQuery BounceAction where
  toQuery :: BounceAction -> QueryString
toQuery BounceAction' {Maybe Text
Text
sender :: Text
message :: Text
smtpReplyCode :: Text
statusCode :: Maybe Text
topicArn :: Maybe Text
$sel:sender:BounceAction' :: BounceAction -> Text
$sel:message:BounceAction' :: BounceAction -> Text
$sel:smtpReplyCode:BounceAction' :: BounceAction -> Text
$sel:statusCode:BounceAction' :: BounceAction -> Maybe Text
$sel:topicArn:BounceAction' :: BounceAction -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"TopicArn" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
topicArn,
        ByteString
"StatusCode" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
statusCode,
        ByteString
"SmtpReplyCode" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
smtpReplyCode,
        ByteString
"Message" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
message,
        ByteString
"Sender" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
sender
      ]