{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.SES.Types.BounceAction 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

-- | 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 SMTP enhanced status code, as defined by
    -- <https://tools.ietf.org/html/rfc3463 RFC 3463>.
    BounceAction -> Maybe Text
statusCode :: Prelude.Maybe Prelude.Text,
    -- | 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 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
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]
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
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. 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:
--
-- 'statusCode', 'bounceAction_statusCode' - The SMTP enhanced status code, as defined by
-- <https://tools.ietf.org/html/rfc3463 RFC 3463>.
--
-- '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>.
--
-- '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'
    { $sel:statusCode:BounceAction' :: Maybe Text
statusCode = forall a. Maybe a
Prelude.Nothing,
      $sel:topicArn:BounceAction' :: Maybe Text
topicArn = 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 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 :: Lens' BounceAction (Maybe Text)
bounceAction_statusCode = 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 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 :: Lens' BounceAction (Maybe Text)
bounceAction_topicArn = 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 reply code, as defined by
-- <https://tools.ietf.org/html/rfc5321 RFC 5321>.
bounceAction_smtpReplyCode :: Lens.Lens' BounceAction Prelude.Text
bounceAction_smtpReplyCode :: Lens' BounceAction Text
bounceAction_smtpReplyCode = 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 :: Lens' BounceAction Text
bounceAction_message = 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 :: Lens' BounceAction Text
bounceAction_sender = 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 Data.FromXML BounceAction where
  parseXML :: [Node] -> Either String BounceAction
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> Text -> Text -> Text -> BounceAction
BounceAction'
      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
"StatusCode")
      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
"TopicArn")
      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
"SmtpReplyCode")
      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
"Message")
      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
"Sender")

instance Prelude.Hashable BounceAction where
  hashWithSalt :: Int -> BounceAction -> Int
hashWithSalt Int
_salt BounceAction' {Maybe Text
Text
sender :: Text
message :: Text
smtpReplyCode :: Text
topicArn :: Maybe Text
statusCode :: Maybe Text
$sel:sender:BounceAction' :: BounceAction -> Text
$sel:message:BounceAction' :: BounceAction -> Text
$sel:smtpReplyCode:BounceAction' :: BounceAction -> Text
$sel:topicArn:BounceAction' :: BounceAction -> Maybe Text
$sel:statusCode:BounceAction' :: BounceAction -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
statusCode
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
topicArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
smtpReplyCode
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
message
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
sender

instance Prelude.NFData BounceAction where
  rnf :: BounceAction -> ()
rnf BounceAction' {Maybe Text
Text
sender :: Text
message :: Text
smtpReplyCode :: Text
topicArn :: Maybe Text
statusCode :: Maybe Text
$sel:sender:BounceAction' :: BounceAction -> Text
$sel:message:BounceAction' :: BounceAction -> Text
$sel:smtpReplyCode:BounceAction' :: BounceAction -> Text
$sel:topicArn:BounceAction' :: BounceAction -> Maybe Text
$sel:statusCode:BounceAction' :: BounceAction -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
statusCode
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
topicArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
smtpReplyCode
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
message
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
sender

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