{-# 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.SQS.Types.Message
-- 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.SQS.Types.Message 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.SQS.Types.MessageAttribute
import Amazonka.SQS.Types.MessageAttributeValue

-- | An Amazon SQS message.
--
-- /See:/ 'newMessage' smart constructor.
data Message = Message'
  { -- | A map of the attributes requested in @ @@ReceiveMessage@@ @ to their
    -- respective values. Supported attributes:
    --
    -- -   @ApproximateReceiveCount@
    --
    -- -   @ApproximateFirstReceiveTimestamp@
    --
    -- -   @MessageDeduplicationId@
    --
    -- -   @MessageGroupId@
    --
    -- -   @SenderId@
    --
    -- -   @SentTimestamp@
    --
    -- -   @SequenceNumber@
    --
    -- @ApproximateFirstReceiveTimestamp@ and @SentTimestamp@ are each returned
    -- as an integer representing the
    -- <http://en.wikipedia.org/wiki/Unix_time epoch time> in milliseconds.
    Message -> Maybe (HashMap MessageAttribute Text)
attributes :: Prelude.Maybe (Prelude.HashMap MessageAttribute Prelude.Text),
    -- | The message\'s contents (not URL-encoded).
    Message -> Maybe Text
body :: Prelude.Maybe Prelude.Text,
    -- | An MD5 digest of the non-URL-encoded message body string.
    Message -> Maybe Text
mD5OfBody :: Prelude.Maybe Prelude.Text,
    -- | An MD5 digest of the non-URL-encoded message attribute string. You can
    -- use this attribute to verify that Amazon SQS received the message
    -- correctly. Amazon SQS URL-decodes the message before creating the MD5
    -- digest. For information about MD5, see
    -- <https://www.ietf.org/rfc/rfc1321.txt RFC1321>.
    Message -> Maybe Text
mD5OfMessageAttributes :: Prelude.Maybe Prelude.Text,
    -- | Each message attribute consists of a @Name@, @Type@, and @Value@. For
    -- more information, see
    -- <https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-metadata.html#sqs-message-attributes Amazon SQS message attributes>
    -- in the /Amazon SQS Developer Guide/.
    Message -> Maybe (HashMap Text MessageAttributeValue)
messageAttributes :: Prelude.Maybe (Prelude.HashMap Prelude.Text MessageAttributeValue),
    -- | A unique identifier for the message. A @MessageId@is considered unique
    -- across all Amazon Web Services accounts for an extended period of time.
    Message -> Maybe Text
messageId :: Prelude.Maybe Prelude.Text,
    -- | An identifier associated with the act of receiving the message. A new
    -- receipt handle is returned every time you receive a message. When
    -- deleting a message, you provide the last received receipt handle to
    -- delete the message.
    Message -> Maybe Text
receiptHandle :: Prelude.Maybe Prelude.Text
  }
  deriving (Message -> Message -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Message -> Message -> Bool
$c/= :: Message -> Message -> Bool
== :: Message -> Message -> Bool
$c== :: Message -> Message -> Bool
Prelude.Eq, ReadPrec [Message]
ReadPrec Message
Int -> ReadS Message
ReadS [Message]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Message]
$creadListPrec :: ReadPrec [Message]
readPrec :: ReadPrec Message
$creadPrec :: ReadPrec Message
readList :: ReadS [Message]
$creadList :: ReadS [Message]
readsPrec :: Int -> ReadS Message
$creadsPrec :: Int -> ReadS Message
Prelude.Read, Int -> Message -> ShowS
[Message] -> ShowS
Message -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Message] -> ShowS
$cshowList :: [Message] -> ShowS
show :: Message -> String
$cshow :: Message -> String
showsPrec :: Int -> Message -> ShowS
$cshowsPrec :: Int -> Message -> ShowS
Prelude.Show, forall x. Rep Message x -> Message
forall x. Message -> Rep Message x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Message x -> Message
$cfrom :: forall x. Message -> Rep Message x
Prelude.Generic)

-- |
-- Create a value of 'Message' 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:
--
-- 'attributes', 'message_attributes' - A map of the attributes requested in @ @@ReceiveMessage@@ @ to their
-- respective values. Supported attributes:
--
-- -   @ApproximateReceiveCount@
--
-- -   @ApproximateFirstReceiveTimestamp@
--
-- -   @MessageDeduplicationId@
--
-- -   @MessageGroupId@
--
-- -   @SenderId@
--
-- -   @SentTimestamp@
--
-- -   @SequenceNumber@
--
-- @ApproximateFirstReceiveTimestamp@ and @SentTimestamp@ are each returned
-- as an integer representing the
-- <http://en.wikipedia.org/wiki/Unix_time epoch time> in milliseconds.
--
-- 'body', 'message_body' - The message\'s contents (not URL-encoded).
--
-- 'mD5OfBody', 'message_mD5OfBody' - An MD5 digest of the non-URL-encoded message body string.
--
-- 'mD5OfMessageAttributes', 'message_mD5OfMessageAttributes' - An MD5 digest of the non-URL-encoded message attribute string. You can
-- use this attribute to verify that Amazon SQS received the message
-- correctly. Amazon SQS URL-decodes the message before creating the MD5
-- digest. For information about MD5, see
-- <https://www.ietf.org/rfc/rfc1321.txt RFC1321>.
--
-- 'messageAttributes', 'message_messageAttributes' - Each message attribute consists of a @Name@, @Type@, and @Value@. For
-- more information, see
-- <https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-metadata.html#sqs-message-attributes Amazon SQS message attributes>
-- in the /Amazon SQS Developer Guide/.
--
-- 'messageId', 'message_messageId' - A unique identifier for the message. A @MessageId@is considered unique
-- across all Amazon Web Services accounts for an extended period of time.
--
-- 'receiptHandle', 'message_receiptHandle' - An identifier associated with the act of receiving the message. A new
-- receipt handle is returned every time you receive a message. When
-- deleting a message, you provide the last received receipt handle to
-- delete the message.
newMessage ::
  Message
newMessage :: Message
newMessage =
  Message'
    { $sel:attributes:Message' :: Maybe (HashMap MessageAttribute Text)
attributes = forall a. Maybe a
Prelude.Nothing,
      $sel:body:Message' :: Maybe Text
body = forall a. Maybe a
Prelude.Nothing,
      $sel:mD5OfBody:Message' :: Maybe Text
mD5OfBody = forall a. Maybe a
Prelude.Nothing,
      $sel:mD5OfMessageAttributes:Message' :: Maybe Text
mD5OfMessageAttributes = forall a. Maybe a
Prelude.Nothing,
      $sel:messageAttributes:Message' :: Maybe (HashMap Text MessageAttributeValue)
messageAttributes = forall a. Maybe a
Prelude.Nothing,
      $sel:messageId:Message' :: Maybe Text
messageId = forall a. Maybe a
Prelude.Nothing,
      $sel:receiptHandle:Message' :: Maybe Text
receiptHandle = forall a. Maybe a
Prelude.Nothing
    }

-- | A map of the attributes requested in @ @@ReceiveMessage@@ @ to their
-- respective values. Supported attributes:
--
-- -   @ApproximateReceiveCount@
--
-- -   @ApproximateFirstReceiveTimestamp@
--
-- -   @MessageDeduplicationId@
--
-- -   @MessageGroupId@
--
-- -   @SenderId@
--
-- -   @SentTimestamp@
--
-- -   @SequenceNumber@
--
-- @ApproximateFirstReceiveTimestamp@ and @SentTimestamp@ are each returned
-- as an integer representing the
-- <http://en.wikipedia.org/wiki/Unix_time epoch time> in milliseconds.
message_attributes :: Lens.Lens' Message (Prelude.Maybe (Prelude.HashMap MessageAttribute Prelude.Text))
message_attributes :: Lens' Message (Maybe (HashMap MessageAttribute Text))
message_attributes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {Maybe (HashMap MessageAttribute Text)
attributes :: Maybe (HashMap MessageAttribute Text)
$sel:attributes:Message' :: Message -> Maybe (HashMap MessageAttribute Text)
attributes} -> Maybe (HashMap MessageAttribute Text)
attributes) (\s :: Message
s@Message' {} Maybe (HashMap MessageAttribute Text)
a -> Message
s {$sel:attributes:Message' :: Maybe (HashMap MessageAttribute Text)
attributes = Maybe (HashMap MessageAttribute Text)
a} :: Message) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The message\'s contents (not URL-encoded).
message_body :: Lens.Lens' Message (Prelude.Maybe Prelude.Text)
message_body :: Lens' Message (Maybe Text)
message_body = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {Maybe Text
body :: Maybe Text
$sel:body:Message' :: Message -> Maybe Text
body} -> Maybe Text
body) (\s :: Message
s@Message' {} Maybe Text
a -> Message
s {$sel:body:Message' :: Maybe Text
body = Maybe Text
a} :: Message)

-- | An MD5 digest of the non-URL-encoded message body string.
message_mD5OfBody :: Lens.Lens' Message (Prelude.Maybe Prelude.Text)
message_mD5OfBody :: Lens' Message (Maybe Text)
message_mD5OfBody = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {Maybe Text
mD5OfBody :: Maybe Text
$sel:mD5OfBody:Message' :: Message -> Maybe Text
mD5OfBody} -> Maybe Text
mD5OfBody) (\s :: Message
s@Message' {} Maybe Text
a -> Message
s {$sel:mD5OfBody:Message' :: Maybe Text
mD5OfBody = Maybe Text
a} :: Message)

-- | An MD5 digest of the non-URL-encoded message attribute string. You can
-- use this attribute to verify that Amazon SQS received the message
-- correctly. Amazon SQS URL-decodes the message before creating the MD5
-- digest. For information about MD5, see
-- <https://www.ietf.org/rfc/rfc1321.txt RFC1321>.
message_mD5OfMessageAttributes :: Lens.Lens' Message (Prelude.Maybe Prelude.Text)
message_mD5OfMessageAttributes :: Lens' Message (Maybe Text)
message_mD5OfMessageAttributes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {Maybe Text
mD5OfMessageAttributes :: Maybe Text
$sel:mD5OfMessageAttributes:Message' :: Message -> Maybe Text
mD5OfMessageAttributes} -> Maybe Text
mD5OfMessageAttributes) (\s :: Message
s@Message' {} Maybe Text
a -> Message
s {$sel:mD5OfMessageAttributes:Message' :: Maybe Text
mD5OfMessageAttributes = Maybe Text
a} :: Message)

-- | Each message attribute consists of a @Name@, @Type@, and @Value@. For
-- more information, see
-- <https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-metadata.html#sqs-message-attributes Amazon SQS message attributes>
-- in the /Amazon SQS Developer Guide/.
message_messageAttributes :: Lens.Lens' Message (Prelude.Maybe (Prelude.HashMap Prelude.Text MessageAttributeValue))
message_messageAttributes :: Lens' Message (Maybe (HashMap Text MessageAttributeValue))
message_messageAttributes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {Maybe (HashMap Text MessageAttributeValue)
messageAttributes :: Maybe (HashMap Text MessageAttributeValue)
$sel:messageAttributes:Message' :: Message -> Maybe (HashMap Text MessageAttributeValue)
messageAttributes} -> Maybe (HashMap Text MessageAttributeValue)
messageAttributes) (\s :: Message
s@Message' {} Maybe (HashMap Text MessageAttributeValue)
a -> Message
s {$sel:messageAttributes:Message' :: Maybe (HashMap Text MessageAttributeValue)
messageAttributes = Maybe (HashMap Text MessageAttributeValue)
a} :: Message) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A unique identifier for the message. A @MessageId@is considered unique
-- across all Amazon Web Services accounts for an extended period of time.
message_messageId :: Lens.Lens' Message (Prelude.Maybe Prelude.Text)
message_messageId :: Lens' Message (Maybe Text)
message_messageId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {Maybe Text
messageId :: Maybe Text
$sel:messageId:Message' :: Message -> Maybe Text
messageId} -> Maybe Text
messageId) (\s :: Message
s@Message' {} Maybe Text
a -> Message
s {$sel:messageId:Message' :: Maybe Text
messageId = Maybe Text
a} :: Message)

-- | An identifier associated with the act of receiving the message. A new
-- receipt handle is returned every time you receive a message. When
-- deleting a message, you provide the last received receipt handle to
-- delete the message.
message_receiptHandle :: Lens.Lens' Message (Prelude.Maybe Prelude.Text)
message_receiptHandle :: Lens' Message (Maybe Text)
message_receiptHandle = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {Maybe Text
receiptHandle :: Maybe Text
$sel:receiptHandle:Message' :: Message -> Maybe Text
receiptHandle} -> Maybe Text
receiptHandle) (\s :: Message
s@Message' {} Maybe Text
a -> Message
s {$sel:receiptHandle:Message' :: Maybe Text
receiptHandle = Maybe Text
a} :: Message)

instance Data.FromXML Message where
  parseXML :: [Node] -> Either String Message
parseXML [Node]
x =
    Maybe (HashMap MessageAttribute Text)
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe (HashMap Text MessageAttributeValue)
-> Maybe Text
-> Maybe Text
-> Message
Message'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may
                      (forall k v.
(Eq k, Hashable k, FromText k, FromXML v) =>
Text -> Text -> Text -> [Node] -> Either String (HashMap k v)
Data.parseXMLMap Text
"Attribute" Text
"Name" Text
"Value")
                      [Node]
x
                  )
      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
"Body")
      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
"MD5OfBody")
      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
"MD5OfMessageAttributes")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may
                      (forall k v.
(Eq k, Hashable k, FromText k, FromXML v) =>
Text -> Text -> Text -> [Node] -> Either String (HashMap k v)
Data.parseXMLMap Text
"MessageAttribute" Text
"Name" Text
"Value")
                      [Node]
x
                  )
      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
"MessageId")
      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
"ReceiptHandle")

instance Prelude.Hashable Message where
  hashWithSalt :: Int -> Message -> Int
hashWithSalt Int
_salt Message' {Maybe Text
Maybe (HashMap Text MessageAttributeValue)
Maybe (HashMap MessageAttribute Text)
receiptHandle :: Maybe Text
messageId :: Maybe Text
messageAttributes :: Maybe (HashMap Text MessageAttributeValue)
mD5OfMessageAttributes :: Maybe Text
mD5OfBody :: Maybe Text
body :: Maybe Text
attributes :: Maybe (HashMap MessageAttribute Text)
$sel:receiptHandle:Message' :: Message -> Maybe Text
$sel:messageId:Message' :: Message -> Maybe Text
$sel:messageAttributes:Message' :: Message -> Maybe (HashMap Text MessageAttributeValue)
$sel:mD5OfMessageAttributes:Message' :: Message -> Maybe Text
$sel:mD5OfBody:Message' :: Message -> Maybe Text
$sel:body:Message' :: Message -> Maybe Text
$sel:attributes:Message' :: Message -> Maybe (HashMap MessageAttribute Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap MessageAttribute Text)
attributes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
body
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
mD5OfBody
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
mD5OfMessageAttributes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text MessageAttributeValue)
messageAttributes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
messageId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
receiptHandle

instance Prelude.NFData Message where
  rnf :: Message -> ()
rnf Message' {Maybe Text
Maybe (HashMap Text MessageAttributeValue)
Maybe (HashMap MessageAttribute Text)
receiptHandle :: Maybe Text
messageId :: Maybe Text
messageAttributes :: Maybe (HashMap Text MessageAttributeValue)
mD5OfMessageAttributes :: Maybe Text
mD5OfBody :: Maybe Text
body :: Maybe Text
attributes :: Maybe (HashMap MessageAttribute Text)
$sel:receiptHandle:Message' :: Message -> Maybe Text
$sel:messageId:Message' :: Message -> Maybe Text
$sel:messageAttributes:Message' :: Message -> Maybe (HashMap Text MessageAttributeValue)
$sel:mD5OfMessageAttributes:Message' :: Message -> Maybe Text
$sel:mD5OfBody:Message' :: Message -> Maybe Text
$sel:body:Message' :: Message -> Maybe Text
$sel:attributes:Message' :: Message -> Maybe (HashMap MessageAttribute Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap MessageAttribute Text)
attributes
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
body
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
mD5OfBody
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
mD5OfMessageAttributes
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text MessageAttributeValue)
messageAttributes
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
messageId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
receiptHandle