{-# 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.IoTAnalytics.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.IoTAnalytics.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

-- | Information about a message.
--
-- /See:/ 'newMessage' smart constructor.
data Message = Message'
  { -- | The ID you want to assign to the message. Each @messageId@ must be
    -- unique within each batch sent.
    Message -> Text
messageId :: Prelude.Text,
    -- | The payload of the message. This can be a JSON string or a
    -- base64-encoded string representing binary data, in which case you must
    -- decode it by means of a pipeline activity.
    Message -> Base64
payload :: Data.Base64
  }
  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:
--
-- 'messageId', 'message_messageId' - The ID you want to assign to the message. Each @messageId@ must be
-- unique within each batch sent.
--
-- 'payload', 'message_payload' - The payload of the message. This can be a JSON string or a
-- base64-encoded string representing binary data, in which case you must
-- decode it by means of a pipeline activity.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
newMessage ::
  -- | 'messageId'
  Prelude.Text ->
  -- | 'payload'
  Prelude.ByteString ->
  Message
newMessage :: Text -> ByteString -> Message
newMessage Text
pMessageId_ ByteString
pPayload_ =
  Message'
    { $sel:messageId:Message' :: Text
messageId = Text
pMessageId_,
      $sel:payload:Message' :: Base64
payload = Iso' Base64 ByteString
Data._Base64 forall t b. AReview t b -> b -> t
Lens.# ByteString
pPayload_
    }

-- | The ID you want to assign to the message. Each @messageId@ must be
-- unique within each batch sent.
message_messageId :: Lens.Lens' Message Prelude.Text
message_messageId :: Lens' Message Text
message_messageId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {Text
messageId :: Text
$sel:messageId:Message' :: Message -> Text
messageId} -> Text
messageId) (\s :: Message
s@Message' {} Text
a -> Message
s {$sel:messageId:Message' :: Text
messageId = Text
a} :: Message)

-- | The payload of the message. This can be a JSON string or a
-- base64-encoded string representing binary data, in which case you must
-- decode it by means of a pipeline activity.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
message_payload :: Lens.Lens' Message Prelude.ByteString
message_payload :: Lens' Message ByteString
message_payload = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {Base64
payload :: Base64
$sel:payload:Message' :: Message -> Base64
payload} -> Base64
payload) (\s :: Message
s@Message' {} Base64
a -> Message
s {$sel:payload:Message' :: Base64
payload = Base64
a} :: Message) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Iso' Base64 ByteString
Data._Base64

instance Prelude.Hashable Message where
  hashWithSalt :: Int -> Message -> Int
hashWithSalt Int
_salt Message' {Text
Base64
payload :: Base64
messageId :: Text
$sel:payload:Message' :: Message -> Base64
$sel:messageId:Message' :: Message -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
messageId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Base64
payload

instance Prelude.NFData Message where
  rnf :: Message -> ()
rnf Message' {Text
Base64
payload :: Base64
messageId :: Text
$sel:payload:Message' :: Message -> Base64
$sel:messageId:Message' :: Message -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
messageId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Base64
payload

instance Data.ToJSON Message where
  toJSON :: Message -> Value
toJSON Message' {Text
Base64
payload :: Base64
messageId :: Text
$sel:payload:Message' :: Message -> Base64
$sel:messageId:Message' :: Message -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"messageId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
messageId),
            forall a. a -> Maybe a
Prelude.Just (Key
"payload" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Base64
payload)
          ]
      )