{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.BatchPutMessage
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Sends messages to a channel.
module Amazonka.IoTAnalytics.BatchPutMessage
  ( -- * Creating a Request
    BatchPutMessage (..),
    newBatchPutMessage,

    -- * Request Lenses
    batchPutMessage_channelName,
    batchPutMessage_messages,

    -- * Destructuring the Response
    BatchPutMessageResponse (..),
    newBatchPutMessageResponse,

    -- * Response Lenses
    batchPutMessageResponse_batchPutMessageErrorEntries,
    batchPutMessageResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoTAnalytics.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newBatchPutMessage' smart constructor.
data BatchPutMessage = BatchPutMessage'
  { -- | The name of the channel where the messages are sent.
    BatchPutMessage -> Text
channelName :: Prelude.Text,
    -- | The list of messages to be sent. Each message has the format: {
    -- \"messageId\": \"string\", \"payload\": \"string\"}.
    --
    -- The field names of message payloads (data) that you send to IoT
    -- Analytics:
    --
    -- -   Must contain only alphanumeric characters and undescores (_). No
    --     other special characters are allowed.
    --
    -- -   Must begin with an alphabetic character or single underscore (_).
    --
    -- -   Cannot contain hyphens (-).
    --
    -- -   In regular expression terms:
    --     \"^[A-Za-z_]([A-Za-z0-9]*|[A-Za-z0-9][A-Za-z0-9_]*)$\".
    --
    -- -   Cannot be more than 255 characters.
    --
    -- -   Are case insensitive. (Fields named foo and FOO in the same payload
    --     are considered duplicates.)
    --
    -- For example, {\"temp_01\": 29} or {\"_temp_01\": 29} are valid, but
    -- {\"temp-01\": 29}, {\"01_temp\": 29} or {\"__temp_01\": 29} are invalid
    -- in message payloads.
    BatchPutMessage -> [Message]
messages :: [Message]
  }
  deriving (BatchPutMessage -> BatchPutMessage -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchPutMessage -> BatchPutMessage -> Bool
$c/= :: BatchPutMessage -> BatchPutMessage -> Bool
== :: BatchPutMessage -> BatchPutMessage -> Bool
$c== :: BatchPutMessage -> BatchPutMessage -> Bool
Prelude.Eq, ReadPrec [BatchPutMessage]
ReadPrec BatchPutMessage
Int -> ReadS BatchPutMessage
ReadS [BatchPutMessage]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchPutMessage]
$creadListPrec :: ReadPrec [BatchPutMessage]
readPrec :: ReadPrec BatchPutMessage
$creadPrec :: ReadPrec BatchPutMessage
readList :: ReadS [BatchPutMessage]
$creadList :: ReadS [BatchPutMessage]
readsPrec :: Int -> ReadS BatchPutMessage
$creadsPrec :: Int -> ReadS BatchPutMessage
Prelude.Read, Int -> BatchPutMessage -> ShowS
[BatchPutMessage] -> ShowS
BatchPutMessage -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchPutMessage] -> ShowS
$cshowList :: [BatchPutMessage] -> ShowS
show :: BatchPutMessage -> String
$cshow :: BatchPutMessage -> String
showsPrec :: Int -> BatchPutMessage -> ShowS
$cshowsPrec :: Int -> BatchPutMessage -> ShowS
Prelude.Show, forall x. Rep BatchPutMessage x -> BatchPutMessage
forall x. BatchPutMessage -> Rep BatchPutMessage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchPutMessage x -> BatchPutMessage
$cfrom :: forall x. BatchPutMessage -> Rep BatchPutMessage x
Prelude.Generic)

-- |
-- Create a value of 'BatchPutMessage' 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:
--
-- 'channelName', 'batchPutMessage_channelName' - The name of the channel where the messages are sent.
--
-- 'messages', 'batchPutMessage_messages' - The list of messages to be sent. Each message has the format: {
-- \"messageId\": \"string\", \"payload\": \"string\"}.
--
-- The field names of message payloads (data) that you send to IoT
-- Analytics:
--
-- -   Must contain only alphanumeric characters and undescores (_). No
--     other special characters are allowed.
--
-- -   Must begin with an alphabetic character or single underscore (_).
--
-- -   Cannot contain hyphens (-).
--
-- -   In regular expression terms:
--     \"^[A-Za-z_]([A-Za-z0-9]*|[A-Za-z0-9][A-Za-z0-9_]*)$\".
--
-- -   Cannot be more than 255 characters.
--
-- -   Are case insensitive. (Fields named foo and FOO in the same payload
--     are considered duplicates.)
--
-- For example, {\"temp_01\": 29} or {\"_temp_01\": 29} are valid, but
-- {\"temp-01\": 29}, {\"01_temp\": 29} or {\"__temp_01\": 29} are invalid
-- in message payloads.
newBatchPutMessage ::
  -- | 'channelName'
  Prelude.Text ->
  BatchPutMessage
newBatchPutMessage :: Text -> BatchPutMessage
newBatchPutMessage Text
pChannelName_ =
  BatchPutMessage'
    { $sel:channelName:BatchPutMessage' :: Text
channelName = Text
pChannelName_,
      $sel:messages:BatchPutMessage' :: [Message]
messages = forall a. Monoid a => a
Prelude.mempty
    }

-- | The name of the channel where the messages are sent.
batchPutMessage_channelName :: Lens.Lens' BatchPutMessage Prelude.Text
batchPutMessage_channelName :: Lens' BatchPutMessage Text
batchPutMessage_channelName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchPutMessage' {Text
channelName :: Text
$sel:channelName:BatchPutMessage' :: BatchPutMessage -> Text
channelName} -> Text
channelName) (\s :: BatchPutMessage
s@BatchPutMessage' {} Text
a -> BatchPutMessage
s {$sel:channelName:BatchPutMessage' :: Text
channelName = Text
a} :: BatchPutMessage)

-- | The list of messages to be sent. Each message has the format: {
-- \"messageId\": \"string\", \"payload\": \"string\"}.
--
-- The field names of message payloads (data) that you send to IoT
-- Analytics:
--
-- -   Must contain only alphanumeric characters and undescores (_). No
--     other special characters are allowed.
--
-- -   Must begin with an alphabetic character or single underscore (_).
--
-- -   Cannot contain hyphens (-).
--
-- -   In regular expression terms:
--     \"^[A-Za-z_]([A-Za-z0-9]*|[A-Za-z0-9][A-Za-z0-9_]*)$\".
--
-- -   Cannot be more than 255 characters.
--
-- -   Are case insensitive. (Fields named foo and FOO in the same payload
--     are considered duplicates.)
--
-- For example, {\"temp_01\": 29} or {\"_temp_01\": 29} are valid, but
-- {\"temp-01\": 29}, {\"01_temp\": 29} or {\"__temp_01\": 29} are invalid
-- in message payloads.
batchPutMessage_messages :: Lens.Lens' BatchPutMessage [Message]
batchPutMessage_messages :: Lens' BatchPutMessage [Message]
batchPutMessage_messages = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchPutMessage' {[Message]
messages :: [Message]
$sel:messages:BatchPutMessage' :: BatchPutMessage -> [Message]
messages} -> [Message]
messages) (\s :: BatchPutMessage
s@BatchPutMessage' {} [Message]
a -> BatchPutMessage
s {$sel:messages:BatchPutMessage' :: [Message]
messages = [Message]
a} :: BatchPutMessage) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest BatchPutMessage where
  type
    AWSResponse BatchPutMessage =
      BatchPutMessageResponse
  request :: (Service -> Service) -> BatchPutMessage -> Request BatchPutMessage
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy BatchPutMessage
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse BatchPutMessage)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [BatchPutMessageErrorEntry] -> Int -> BatchPutMessageResponse
BatchPutMessageResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"batchPutMessageErrorEntries"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable BatchPutMessage where
  hashWithSalt :: Int -> BatchPutMessage -> Int
hashWithSalt Int
_salt BatchPutMessage' {[Message]
Text
messages :: [Message]
channelName :: Text
$sel:messages:BatchPutMessage' :: BatchPutMessage -> [Message]
$sel:channelName:BatchPutMessage' :: BatchPutMessage -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
channelName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Message]
messages

instance Prelude.NFData BatchPutMessage where
  rnf :: BatchPutMessage -> ()
rnf BatchPutMessage' {[Message]
Text
messages :: [Message]
channelName :: Text
$sel:messages:BatchPutMessage' :: BatchPutMessage -> [Message]
$sel:channelName:BatchPutMessage' :: BatchPutMessage -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
channelName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Message]
messages

instance Data.ToHeaders BatchPutMessage where
  toHeaders :: BatchPutMessage -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

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

instance Data.ToPath BatchPutMessage where
  toPath :: BatchPutMessage -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/messages/batch"

instance Data.ToQuery BatchPutMessage where
  toQuery :: BatchPutMessage -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newBatchPutMessageResponse' smart constructor.
data BatchPutMessageResponse = BatchPutMessageResponse'
  { -- | A list of any errors encountered when sending the messages to the
    -- channel.
    BatchPutMessageResponse -> Maybe [BatchPutMessageErrorEntry]
batchPutMessageErrorEntries :: Prelude.Maybe [BatchPutMessageErrorEntry],
    -- | The response's http status code.
    BatchPutMessageResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BatchPutMessageResponse -> BatchPutMessageResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchPutMessageResponse -> BatchPutMessageResponse -> Bool
$c/= :: BatchPutMessageResponse -> BatchPutMessageResponse -> Bool
== :: BatchPutMessageResponse -> BatchPutMessageResponse -> Bool
$c== :: BatchPutMessageResponse -> BatchPutMessageResponse -> Bool
Prelude.Eq, ReadPrec [BatchPutMessageResponse]
ReadPrec BatchPutMessageResponse
Int -> ReadS BatchPutMessageResponse
ReadS [BatchPutMessageResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchPutMessageResponse]
$creadListPrec :: ReadPrec [BatchPutMessageResponse]
readPrec :: ReadPrec BatchPutMessageResponse
$creadPrec :: ReadPrec BatchPutMessageResponse
readList :: ReadS [BatchPutMessageResponse]
$creadList :: ReadS [BatchPutMessageResponse]
readsPrec :: Int -> ReadS BatchPutMessageResponse
$creadsPrec :: Int -> ReadS BatchPutMessageResponse
Prelude.Read, Int -> BatchPutMessageResponse -> ShowS
[BatchPutMessageResponse] -> ShowS
BatchPutMessageResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchPutMessageResponse] -> ShowS
$cshowList :: [BatchPutMessageResponse] -> ShowS
show :: BatchPutMessageResponse -> String
$cshow :: BatchPutMessageResponse -> String
showsPrec :: Int -> BatchPutMessageResponse -> ShowS
$cshowsPrec :: Int -> BatchPutMessageResponse -> ShowS
Prelude.Show, forall x. Rep BatchPutMessageResponse x -> BatchPutMessageResponse
forall x. BatchPutMessageResponse -> Rep BatchPutMessageResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchPutMessageResponse x -> BatchPutMessageResponse
$cfrom :: forall x. BatchPutMessageResponse -> Rep BatchPutMessageResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchPutMessageResponse' 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:
--
-- 'batchPutMessageErrorEntries', 'batchPutMessageResponse_batchPutMessageErrorEntries' - A list of any errors encountered when sending the messages to the
-- channel.
--
-- 'httpStatus', 'batchPutMessageResponse_httpStatus' - The response's http status code.
newBatchPutMessageResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchPutMessageResponse
newBatchPutMessageResponse :: Int -> BatchPutMessageResponse
newBatchPutMessageResponse Int
pHttpStatus_ =
  BatchPutMessageResponse'
    { $sel:batchPutMessageErrorEntries:BatchPutMessageResponse' :: Maybe [BatchPutMessageErrorEntry]
batchPutMessageErrorEntries =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BatchPutMessageResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of any errors encountered when sending the messages to the
-- channel.
batchPutMessageResponse_batchPutMessageErrorEntries :: Lens.Lens' BatchPutMessageResponse (Prelude.Maybe [BatchPutMessageErrorEntry])
batchPutMessageResponse_batchPutMessageErrorEntries :: Lens' BatchPutMessageResponse (Maybe [BatchPutMessageErrorEntry])
batchPutMessageResponse_batchPutMessageErrorEntries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchPutMessageResponse' {Maybe [BatchPutMessageErrorEntry]
batchPutMessageErrorEntries :: Maybe [BatchPutMessageErrorEntry]
$sel:batchPutMessageErrorEntries:BatchPutMessageResponse' :: BatchPutMessageResponse -> Maybe [BatchPutMessageErrorEntry]
batchPutMessageErrorEntries} -> Maybe [BatchPutMessageErrorEntry]
batchPutMessageErrorEntries) (\s :: BatchPutMessageResponse
s@BatchPutMessageResponse' {} Maybe [BatchPutMessageErrorEntry]
a -> BatchPutMessageResponse
s {$sel:batchPutMessageErrorEntries:BatchPutMessageResponse' :: Maybe [BatchPutMessageErrorEntry]
batchPutMessageErrorEntries = Maybe [BatchPutMessageErrorEntry]
a} :: BatchPutMessageResponse) 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 response's http status code.
batchPutMessageResponse_httpStatus :: Lens.Lens' BatchPutMessageResponse Prelude.Int
batchPutMessageResponse_httpStatus :: Lens' BatchPutMessageResponse Int
batchPutMessageResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchPutMessageResponse' {Int
httpStatus :: Int
$sel:httpStatus:BatchPutMessageResponse' :: BatchPutMessageResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: BatchPutMessageResponse
s@BatchPutMessageResponse' {} Int
a -> BatchPutMessageResponse
s {$sel:httpStatus:BatchPutMessageResponse' :: Int
httpStatus = Int
a} :: BatchPutMessageResponse)

instance Prelude.NFData BatchPutMessageResponse where
  rnf :: BatchPutMessageResponse -> ()
rnf BatchPutMessageResponse' {Int
Maybe [BatchPutMessageErrorEntry]
httpStatus :: Int
batchPutMessageErrorEntries :: Maybe [BatchPutMessageErrorEntry]
$sel:httpStatus:BatchPutMessageResponse' :: BatchPutMessageResponse -> Int
$sel:batchPutMessageErrorEntries:BatchPutMessageResponse' :: BatchPutMessageResponse -> Maybe [BatchPutMessageErrorEntry]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [BatchPutMessageErrorEntry]
batchPutMessageErrorEntries
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus