{-# 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.IoTEventsData.BatchPutMessage
-- 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)
--
-- Sends a set of messages to the AWS IoT Events system. Each message
-- payload is transformed into the input you specify (@\"inputName\"@) and
-- ingested into any detectors that monitor that input. If multiple
-- messages are sent, the order in which the messages are processed isn\'t
-- guaranteed. To guarantee ordering, you must send messages one at a time
-- and wait for a successful response.
module Amazonka.IoTEventsData.BatchPutMessage
  ( -- * Creating a Request
    BatchPutMessage (..),
    newBatchPutMessage,

    -- * Request Lenses
    batchPutMessage_messages,

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

    -- * Response Lenses
    batchPutMessageResponse_batchPutMessageErrorEntries,
    batchPutMessageResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoTEventsData.Types
import qualified Amazonka.Lens as Lens
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 list of messages to send. Each message has the following format:
    -- @\'{ \"messageId\": \"string\", \"inputName\": \"string\", \"payload\": \"string\"}\'@
    BatchPutMessage -> NonEmpty Message
messages :: Prelude.NonEmpty Message
  }
  deriving (BatchPutMessage -> BatchPutMessage -> Bool
(BatchPutMessage -> BatchPutMessage -> Bool)
-> (BatchPutMessage -> BatchPutMessage -> Bool)
-> Eq BatchPutMessage
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]
(Int -> ReadS BatchPutMessage)
-> ReadS [BatchPutMessage]
-> ReadPrec BatchPutMessage
-> ReadPrec [BatchPutMessage]
-> Read 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
(Int -> BatchPutMessage -> ShowS)
-> (BatchPutMessage -> String)
-> ([BatchPutMessage] -> ShowS)
-> Show BatchPutMessage
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. BatchPutMessage -> Rep BatchPutMessage x)
-> (forall x. Rep BatchPutMessage x -> BatchPutMessage)
-> Generic BatchPutMessage
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:
--
-- 'messages', 'batchPutMessage_messages' - The list of messages to send. Each message has the following format:
-- @\'{ \"messageId\": \"string\", \"inputName\": \"string\", \"payload\": \"string\"}\'@
newBatchPutMessage ::
  -- | 'messages'
  Prelude.NonEmpty Message ->
  BatchPutMessage
newBatchPutMessage :: NonEmpty Message -> BatchPutMessage
newBatchPutMessage NonEmpty Message
pMessages_ =
  BatchPutMessage' :: NonEmpty Message -> BatchPutMessage
BatchPutMessage'
    { $sel:messages:BatchPutMessage' :: NonEmpty Message
messages =
        Tagged (NonEmpty Message) (Identity (NonEmpty Message))
-> Tagged (NonEmpty Message) (Identity (NonEmpty Message))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Message) (Identity (NonEmpty Message))
 -> Tagged (NonEmpty Message) (Identity (NonEmpty Message)))
-> NonEmpty Message -> NonEmpty Message
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Message
pMessages_
    }

-- | The list of messages to send. Each message has the following format:
-- @\'{ \"messageId\": \"string\", \"inputName\": \"string\", \"payload\": \"string\"}\'@
batchPutMessage_messages :: Lens.Lens' BatchPutMessage (Prelude.NonEmpty Message)
batchPutMessage_messages :: (NonEmpty Message -> f (NonEmpty Message))
-> BatchPutMessage -> f BatchPutMessage
batchPutMessage_messages = (BatchPutMessage -> NonEmpty Message)
-> (BatchPutMessage -> NonEmpty Message -> BatchPutMessage)
-> Lens
     BatchPutMessage
     BatchPutMessage
     (NonEmpty Message)
     (NonEmpty Message)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchPutMessage' {NonEmpty Message
messages :: NonEmpty Message
$sel:messages:BatchPutMessage' :: BatchPutMessage -> NonEmpty Message
messages} -> NonEmpty Message
messages) (\s :: BatchPutMessage
s@BatchPutMessage' {} NonEmpty Message
a -> BatchPutMessage
s {$sel:messages:BatchPutMessage' :: NonEmpty Message
messages = NonEmpty Message
a} :: BatchPutMessage) ((NonEmpty Message -> f (NonEmpty Message))
 -> BatchPutMessage -> f BatchPutMessage)
-> ((NonEmpty Message -> f (NonEmpty Message))
    -> NonEmpty Message -> f (NonEmpty Message))
-> (NonEmpty Message -> f (NonEmpty Message))
-> BatchPutMessage
-> f BatchPutMessage
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Message -> f (NonEmpty Message))
-> NonEmpty Message -> f (NonEmpty Message)
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 :: BatchPutMessage -> Request BatchPutMessage
request = Service -> BatchPutMessage -> Request BatchPutMessage
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy BatchPutMessage
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse BatchPutMessage)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse BatchPutMessage))
-> Logger
-> Service
-> Proxy BatchPutMessage
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse BatchPutMessage)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [BatchPutMessageErrorEntry] -> Int -> BatchPutMessageResponse
BatchPutMessageResponse'
            (Maybe [BatchPutMessageErrorEntry]
 -> Int -> BatchPutMessageResponse)
-> Either String (Maybe [BatchPutMessageErrorEntry])
-> Either String (Int -> BatchPutMessageResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object
-> Key -> Either String (Maybe (Maybe [BatchPutMessageErrorEntry]))
forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Core..?> Key
"BatchPutMessageErrorEntries"
                            Either String (Maybe (Maybe [BatchPutMessageErrorEntry]))
-> Maybe [BatchPutMessageErrorEntry]
-> Either String (Maybe [BatchPutMessageErrorEntry])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [BatchPutMessageErrorEntry]
forall a. Monoid a => a
Prelude.mempty
                        )
            Either String (Int -> BatchPutMessageResponse)
-> Either String Int -> Either String BatchPutMessageResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable BatchPutMessage

instance Prelude.NFData BatchPutMessage

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

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

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

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

-- | /See:/ 'newBatchPutMessageResponse' smart constructor.
data BatchPutMessageResponse = BatchPutMessageResponse'
  { -- | A list of any errors encountered when sending the messages.
    BatchPutMessageResponse -> Maybe [BatchPutMessageErrorEntry]
batchPutMessageErrorEntries :: Prelude.Maybe [BatchPutMessageErrorEntry],
    -- | The response's http status code.
    BatchPutMessageResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BatchPutMessageResponse -> BatchPutMessageResponse -> Bool
(BatchPutMessageResponse -> BatchPutMessageResponse -> Bool)
-> (BatchPutMessageResponse -> BatchPutMessageResponse -> Bool)
-> Eq BatchPutMessageResponse
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]
(Int -> ReadS BatchPutMessageResponse)
-> ReadS [BatchPutMessageResponse]
-> ReadPrec BatchPutMessageResponse
-> ReadPrec [BatchPutMessageResponse]
-> Read 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
(Int -> BatchPutMessageResponse -> ShowS)
-> (BatchPutMessageResponse -> String)
-> ([BatchPutMessageResponse] -> ShowS)
-> Show BatchPutMessageResponse
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.
 BatchPutMessageResponse -> Rep BatchPutMessageResponse x)
-> (forall x.
    Rep BatchPutMessageResponse x -> BatchPutMessageResponse)
-> Generic BatchPutMessageResponse
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.
--
-- 'httpStatus', 'batchPutMessageResponse_httpStatus' - The response's http status code.
newBatchPutMessageResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchPutMessageResponse
newBatchPutMessageResponse :: Int -> BatchPutMessageResponse
newBatchPutMessageResponse Int
pHttpStatus_ =
  BatchPutMessageResponse' :: Maybe [BatchPutMessageErrorEntry] -> Int -> BatchPutMessageResponse
BatchPutMessageResponse'
    { $sel:batchPutMessageErrorEntries:BatchPutMessageResponse' :: Maybe [BatchPutMessageErrorEntry]
batchPutMessageErrorEntries =
        Maybe [BatchPutMessageErrorEntry]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BatchPutMessageResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of any errors encountered when sending the messages.
batchPutMessageResponse_batchPutMessageErrorEntries :: Lens.Lens' BatchPutMessageResponse (Prelude.Maybe [BatchPutMessageErrorEntry])
batchPutMessageResponse_batchPutMessageErrorEntries :: (Maybe [BatchPutMessageErrorEntry]
 -> f (Maybe [BatchPutMessageErrorEntry]))
-> BatchPutMessageResponse -> f BatchPutMessageResponse
batchPutMessageResponse_batchPutMessageErrorEntries = (BatchPutMessageResponse -> Maybe [BatchPutMessageErrorEntry])
-> (BatchPutMessageResponse
    -> Maybe [BatchPutMessageErrorEntry] -> BatchPutMessageResponse)
-> Lens
     BatchPutMessageResponse
     BatchPutMessageResponse
     (Maybe [BatchPutMessageErrorEntry])
     (Maybe [BatchPutMessageErrorEntry])
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) ((Maybe [BatchPutMessageErrorEntry]
  -> f (Maybe [BatchPutMessageErrorEntry]))
 -> BatchPutMessageResponse -> f BatchPutMessageResponse)
-> ((Maybe [BatchPutMessageErrorEntry]
     -> f (Maybe [BatchPutMessageErrorEntry]))
    -> Maybe [BatchPutMessageErrorEntry]
    -> f (Maybe [BatchPutMessageErrorEntry]))
-> (Maybe [BatchPutMessageErrorEntry]
    -> f (Maybe [BatchPutMessageErrorEntry]))
-> BatchPutMessageResponse
-> f BatchPutMessageResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [BatchPutMessageErrorEntry]
  [BatchPutMessageErrorEntry]
  [BatchPutMessageErrorEntry]
  [BatchPutMessageErrorEntry]
-> Iso
     (Maybe [BatchPutMessageErrorEntry])
     (Maybe [BatchPutMessageErrorEntry])
     (Maybe [BatchPutMessageErrorEntry])
     (Maybe [BatchPutMessageErrorEntry])
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 AnIso
  [BatchPutMessageErrorEntry]
  [BatchPutMessageErrorEntry]
  [BatchPutMessageErrorEntry]
  [BatchPutMessageErrorEntry]
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 :: (Int -> f Int)
-> BatchPutMessageResponse -> f BatchPutMessageResponse
batchPutMessageResponse_httpStatus = (BatchPutMessageResponse -> Int)
-> (BatchPutMessageResponse -> Int -> BatchPutMessageResponse)
-> Lens BatchPutMessageResponse BatchPutMessageResponse Int Int
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