{-# 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 #-}
module Amazonka.IoTEventsData.Types.Message where
import qualified Amazonka.Core as Core
import Amazonka.IoTEventsData.Types.TimestampValue
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
data Message = Message'
{
Message -> Maybe TimestampValue
timestamp :: Prelude.Maybe TimestampValue,
Message -> Text
messageId :: Prelude.Text,
Message -> Text
inputName :: Prelude.Text,
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)
newMessage ::
Prelude.Text ->
Prelude.Text ->
Prelude.ByteString ->
Message
newMessage :: Text -> Text -> ByteString -> Message
newMessage Text
pMessageId_ Text
pInputName_ ByteString
pPayload_ =
Message' :: Maybe TimestampValue -> Text -> Text -> Base64 -> Message
Message'
{ $sel:timestamp:Message' :: Maybe TimestampValue
timestamp = Maybe TimestampValue
forall a. Maybe a
Prelude.Nothing,
$sel:messageId:Message' :: Text
messageId = Text
pMessageId_,
$sel:inputName:Message' :: Text
inputName = Text
pInputName_,
$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_
}
message_timestamp :: Lens.Lens' Message (Prelude.Maybe TimestampValue)
message_timestamp :: (Maybe TimestampValue -> f (Maybe TimestampValue))
-> Message -> f Message
message_timestamp = (Message -> Maybe TimestampValue)
-> (Message -> Maybe TimestampValue -> Message)
-> Lens
Message Message (Maybe TimestampValue) (Maybe TimestampValue)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {Maybe TimestampValue
timestamp :: Maybe TimestampValue
$sel:timestamp:Message' :: Message -> Maybe TimestampValue
timestamp} -> Maybe TimestampValue
timestamp) (\s :: Message
s@Message' {} Maybe TimestampValue
a -> Message
s {$sel:timestamp:Message' :: Maybe TimestampValue
timestamp = Maybe TimestampValue
a} :: Message)
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)
message_inputName :: Lens.Lens' Message Prelude.Text
message_inputName :: (Text -> f Text) -> Message -> f Message
message_inputName = (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
inputName :: Text
$sel:inputName:Message' :: Message -> Text
inputName} -> Text
inputName) (\s :: Message
s@Message' {} Text
a -> Message
s {$sel:inputName:Message' :: Text
inputName = Text
a} :: Message)
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' {Maybe TimestampValue
Text
Base64
payload :: Base64
inputName :: Text
messageId :: Text
timestamp :: Maybe TimestampValue
$sel:payload:Message' :: Message -> Base64
$sel:inputName:Message' :: Message -> Text
$sel:messageId:Message' :: Message -> Text
$sel:timestamp:Message' :: Message -> Maybe TimestampValue
..} =
[Pair] -> Value
Core.object
( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
[ (Text
"timestamp" Text -> TimestampValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (TimestampValue -> Pair) -> Maybe TimestampValue -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TimestampValue
timestamp,
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
"inputName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
inputName),
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)
]
)