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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 :: Core.Base64
  }
  deriving (Message -> Message -> Bool
(Message -> Message -> Bool)
-> (Message -> Message -> Bool) -> Eq Message
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]
(Int -> ReadS Message)
-> ReadS [Message]
-> ReadPrec Message
-> ReadPrec [Message]
-> Read 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
(Int -> Message -> ShowS)
-> (Message -> String) -> ([Message] -> ShowS) -> Show Message
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. Message -> Rep Message x)
-> (forall x. Rep Message x -> Message) -> Generic Message
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' :: Text -> Base64 -> Message
Message'
    { $sel:messageId:Message' :: Text
messageId = Text
pMessageId_,
      $sel:payload:Message' :: Base64
payload = Tagged ByteString (Identity ByteString)
-> Tagged Base64 (Identity Base64)
Iso' Base64 ByteString
Core._Base64 (Tagged ByteString (Identity ByteString)
 -> Tagged Base64 (Identity Base64))
-> ByteString -> 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 :: (Text -> f Text) -> Message -> f Message
message_messageId = (Message -> Text)
-> (Message -> Text -> Message) -> Lens Message Message Text Text
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 :: (ByteString -> f ByteString) -> Message -> f Message
message_payload = (Message -> Base64)
-> (Message -> Base64 -> Message)
-> Lens Message Message Base64 Base64
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) ((Base64 -> f Base64) -> Message -> f Message)
-> ((ByteString -> f ByteString) -> Base64 -> f Base64)
-> (ByteString -> f ByteString)
-> Message
-> f Message
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (ByteString -> f ByteString) -> Base64 -> f Base64
Iso' Base64 ByteString
Core._Base64

instance Prelude.Hashable Message

instance Prelude.NFData Message

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"messageId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
messageId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"payload" Text -> Base64 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Base64
payload)
          ]
      )