{-# 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.IoTSiteWise.BatchPutAssetPropertyValue
-- 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 a list of asset property values to IoT SiteWise. Each value is a
-- timestamp-quality-value (TQV) data point. For more information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/ingest-api.html Ingesting data using the API>
-- in the /IoT SiteWise User Guide/.
--
-- To identify an asset property, you must specify one of the following:
--
-- -   The @assetId@ and @propertyId@ of an asset property.
--
-- -   A @propertyAlias@, which is a data stream alias (for example,
--     @\/company\/windfarm\/3\/turbine\/7\/temperature@). To define an
--     asset property\'s alias, see
--     <https://docs.aws.amazon.com/iot-sitewise/latest/APIReference/API_UpdateAssetProperty.html UpdateAssetProperty>.
--
-- With respect to Unix epoch time, IoT SiteWise accepts only TQVs that
-- have a timestamp of no more than 7 days in the past and no more than 10
-- minutes in the future. IoT SiteWise rejects timestamps outside of the
-- inclusive range of [-7 days, +10 minutes] and returns a
-- @TimestampOutOfRangeException@ error.
--
-- For each asset property, IoT SiteWise overwrites TQVs with duplicate
-- timestamps unless the newer TQV has a different quality. For example, if
-- you store a TQV @{T1, GOOD, V1}@, then storing @{T1, GOOD, V2}@ replaces
-- the existing TQV.
--
-- IoT SiteWise authorizes access to each @BatchPutAssetPropertyValue@
-- entry individually. For more information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/security_iam_service-with-iam.html#security_iam_service-with-iam-id-based-policies-batchputassetpropertyvalue-action BatchPutAssetPropertyValue authorization>
-- in the /IoT SiteWise User Guide/.
module Amazonka.IoTSiteWise.BatchPutAssetPropertyValue
  ( -- * Creating a Request
    BatchPutAssetPropertyValue (..),
    newBatchPutAssetPropertyValue,

    -- * Request Lenses
    batchPutAssetPropertyValue_entries,

    -- * Destructuring the Response
    BatchPutAssetPropertyValueResponse (..),
    newBatchPutAssetPropertyValueResponse,

    -- * Response Lenses
    batchPutAssetPropertyValueResponse_httpStatus,
    batchPutAssetPropertyValueResponse_errorEntries,
  )
where

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

-- | /See:/ 'newBatchPutAssetPropertyValue' smart constructor.
data BatchPutAssetPropertyValue = BatchPutAssetPropertyValue'
  { -- | The list of asset property value entries for the batch put request. You
    -- can specify up to 10 entries per request.
    BatchPutAssetPropertyValue -> [PutAssetPropertyValueEntry]
entries :: [PutAssetPropertyValueEntry]
  }
  deriving (BatchPutAssetPropertyValue -> BatchPutAssetPropertyValue -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchPutAssetPropertyValue -> BatchPutAssetPropertyValue -> Bool
$c/= :: BatchPutAssetPropertyValue -> BatchPutAssetPropertyValue -> Bool
== :: BatchPutAssetPropertyValue -> BatchPutAssetPropertyValue -> Bool
$c== :: BatchPutAssetPropertyValue -> BatchPutAssetPropertyValue -> Bool
Prelude.Eq, ReadPrec [BatchPutAssetPropertyValue]
ReadPrec BatchPutAssetPropertyValue
Int -> ReadS BatchPutAssetPropertyValue
ReadS [BatchPutAssetPropertyValue]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchPutAssetPropertyValue]
$creadListPrec :: ReadPrec [BatchPutAssetPropertyValue]
readPrec :: ReadPrec BatchPutAssetPropertyValue
$creadPrec :: ReadPrec BatchPutAssetPropertyValue
readList :: ReadS [BatchPutAssetPropertyValue]
$creadList :: ReadS [BatchPutAssetPropertyValue]
readsPrec :: Int -> ReadS BatchPutAssetPropertyValue
$creadsPrec :: Int -> ReadS BatchPutAssetPropertyValue
Prelude.Read, Int -> BatchPutAssetPropertyValue -> ShowS
[BatchPutAssetPropertyValue] -> ShowS
BatchPutAssetPropertyValue -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchPutAssetPropertyValue] -> ShowS
$cshowList :: [BatchPutAssetPropertyValue] -> ShowS
show :: BatchPutAssetPropertyValue -> String
$cshow :: BatchPutAssetPropertyValue -> String
showsPrec :: Int -> BatchPutAssetPropertyValue -> ShowS
$cshowsPrec :: Int -> BatchPutAssetPropertyValue -> ShowS
Prelude.Show, forall x.
Rep BatchPutAssetPropertyValue x -> BatchPutAssetPropertyValue
forall x.
BatchPutAssetPropertyValue -> Rep BatchPutAssetPropertyValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BatchPutAssetPropertyValue x -> BatchPutAssetPropertyValue
$cfrom :: forall x.
BatchPutAssetPropertyValue -> Rep BatchPutAssetPropertyValue x
Prelude.Generic)

-- |
-- Create a value of 'BatchPutAssetPropertyValue' 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:
--
-- 'entries', 'batchPutAssetPropertyValue_entries' - The list of asset property value entries for the batch put request. You
-- can specify up to 10 entries per request.
newBatchPutAssetPropertyValue ::
  BatchPutAssetPropertyValue
newBatchPutAssetPropertyValue :: BatchPutAssetPropertyValue
newBatchPutAssetPropertyValue =
  BatchPutAssetPropertyValue'
    { $sel:entries:BatchPutAssetPropertyValue' :: [PutAssetPropertyValueEntry]
entries =
        forall a. Monoid a => a
Prelude.mempty
    }

-- | The list of asset property value entries for the batch put request. You
-- can specify up to 10 entries per request.
batchPutAssetPropertyValue_entries :: Lens.Lens' BatchPutAssetPropertyValue [PutAssetPropertyValueEntry]
batchPutAssetPropertyValue_entries :: Lens' BatchPutAssetPropertyValue [PutAssetPropertyValueEntry]
batchPutAssetPropertyValue_entries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchPutAssetPropertyValue' {[PutAssetPropertyValueEntry]
entries :: [PutAssetPropertyValueEntry]
$sel:entries:BatchPutAssetPropertyValue' :: BatchPutAssetPropertyValue -> [PutAssetPropertyValueEntry]
entries} -> [PutAssetPropertyValueEntry]
entries) (\s :: BatchPutAssetPropertyValue
s@BatchPutAssetPropertyValue' {} [PutAssetPropertyValueEntry]
a -> BatchPutAssetPropertyValue
s {$sel:entries:BatchPutAssetPropertyValue' :: [PutAssetPropertyValueEntry]
entries = [PutAssetPropertyValueEntry]
a} :: BatchPutAssetPropertyValue) 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 BatchPutAssetPropertyValue where
  type
    AWSResponse BatchPutAssetPropertyValue =
      BatchPutAssetPropertyValueResponse
  request :: (Service -> Service)
-> BatchPutAssetPropertyValue -> Request BatchPutAssetPropertyValue
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 BatchPutAssetPropertyValue
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse BatchPutAssetPropertyValue)))
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 ->
          Int
-> [BatchPutAssetPropertyErrorEntry]
-> BatchPutAssetPropertyValueResponse
BatchPutAssetPropertyValueResponse'
            forall (f :: * -> *) a b. Functor 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))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"errorEntries" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable BatchPutAssetPropertyValue where
  hashWithSalt :: Int -> BatchPutAssetPropertyValue -> Int
hashWithSalt Int
_salt BatchPutAssetPropertyValue' {[PutAssetPropertyValueEntry]
entries :: [PutAssetPropertyValueEntry]
$sel:entries:BatchPutAssetPropertyValue' :: BatchPutAssetPropertyValue -> [PutAssetPropertyValueEntry]
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [PutAssetPropertyValueEntry]
entries

instance Prelude.NFData BatchPutAssetPropertyValue where
  rnf :: BatchPutAssetPropertyValue -> ()
rnf BatchPutAssetPropertyValue' {[PutAssetPropertyValueEntry]
entries :: [PutAssetPropertyValueEntry]
$sel:entries:BatchPutAssetPropertyValue' :: BatchPutAssetPropertyValue -> [PutAssetPropertyValueEntry]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf [PutAssetPropertyValueEntry]
entries

instance Data.ToHeaders BatchPutAssetPropertyValue where
  toHeaders :: BatchPutAssetPropertyValue -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

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

instance Data.ToPath BatchPutAssetPropertyValue where
  toPath :: BatchPutAssetPropertyValue -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/properties"

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

-- | /See:/ 'newBatchPutAssetPropertyValueResponse' smart constructor.
data BatchPutAssetPropertyValueResponse = BatchPutAssetPropertyValueResponse'
  { -- | The response's http status code.
    BatchPutAssetPropertyValueResponse -> Int
httpStatus :: Prelude.Int,
    -- | A list of the errors (if any) associated with the batch put request.
    -- Each error entry contains the @entryId@ of the entry that failed.
    BatchPutAssetPropertyValueResponse
-> [BatchPutAssetPropertyErrorEntry]
errorEntries :: [BatchPutAssetPropertyErrorEntry]
  }
  deriving (BatchPutAssetPropertyValueResponse
-> BatchPutAssetPropertyValueResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchPutAssetPropertyValueResponse
-> BatchPutAssetPropertyValueResponse -> Bool
$c/= :: BatchPutAssetPropertyValueResponse
-> BatchPutAssetPropertyValueResponse -> Bool
== :: BatchPutAssetPropertyValueResponse
-> BatchPutAssetPropertyValueResponse -> Bool
$c== :: BatchPutAssetPropertyValueResponse
-> BatchPutAssetPropertyValueResponse -> Bool
Prelude.Eq, ReadPrec [BatchPutAssetPropertyValueResponse]
ReadPrec BatchPutAssetPropertyValueResponse
Int -> ReadS BatchPutAssetPropertyValueResponse
ReadS [BatchPutAssetPropertyValueResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchPutAssetPropertyValueResponse]
$creadListPrec :: ReadPrec [BatchPutAssetPropertyValueResponse]
readPrec :: ReadPrec BatchPutAssetPropertyValueResponse
$creadPrec :: ReadPrec BatchPutAssetPropertyValueResponse
readList :: ReadS [BatchPutAssetPropertyValueResponse]
$creadList :: ReadS [BatchPutAssetPropertyValueResponse]
readsPrec :: Int -> ReadS BatchPutAssetPropertyValueResponse
$creadsPrec :: Int -> ReadS BatchPutAssetPropertyValueResponse
Prelude.Read, Int -> BatchPutAssetPropertyValueResponse -> ShowS
[BatchPutAssetPropertyValueResponse] -> ShowS
BatchPutAssetPropertyValueResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchPutAssetPropertyValueResponse] -> ShowS
$cshowList :: [BatchPutAssetPropertyValueResponse] -> ShowS
show :: BatchPutAssetPropertyValueResponse -> String
$cshow :: BatchPutAssetPropertyValueResponse -> String
showsPrec :: Int -> BatchPutAssetPropertyValueResponse -> ShowS
$cshowsPrec :: Int -> BatchPutAssetPropertyValueResponse -> ShowS
Prelude.Show, forall x.
Rep BatchPutAssetPropertyValueResponse x
-> BatchPutAssetPropertyValueResponse
forall x.
BatchPutAssetPropertyValueResponse
-> Rep BatchPutAssetPropertyValueResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BatchPutAssetPropertyValueResponse x
-> BatchPutAssetPropertyValueResponse
$cfrom :: forall x.
BatchPutAssetPropertyValueResponse
-> Rep BatchPutAssetPropertyValueResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchPutAssetPropertyValueResponse' 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:
--
-- 'httpStatus', 'batchPutAssetPropertyValueResponse_httpStatus' - The response's http status code.
--
-- 'errorEntries', 'batchPutAssetPropertyValueResponse_errorEntries' - A list of the errors (if any) associated with the batch put request.
-- Each error entry contains the @entryId@ of the entry that failed.
newBatchPutAssetPropertyValueResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchPutAssetPropertyValueResponse
newBatchPutAssetPropertyValueResponse :: Int -> BatchPutAssetPropertyValueResponse
newBatchPutAssetPropertyValueResponse Int
pHttpStatus_ =
  BatchPutAssetPropertyValueResponse'
    { $sel:httpStatus:BatchPutAssetPropertyValueResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:errorEntries:BatchPutAssetPropertyValueResponse' :: [BatchPutAssetPropertyErrorEntry]
errorEntries = forall a. Monoid a => a
Prelude.mempty
    }

-- | The response's http status code.
batchPutAssetPropertyValueResponse_httpStatus :: Lens.Lens' BatchPutAssetPropertyValueResponse Prelude.Int
batchPutAssetPropertyValueResponse_httpStatus :: Lens' BatchPutAssetPropertyValueResponse Int
batchPutAssetPropertyValueResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchPutAssetPropertyValueResponse' {Int
httpStatus :: Int
$sel:httpStatus:BatchPutAssetPropertyValueResponse' :: BatchPutAssetPropertyValueResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: BatchPutAssetPropertyValueResponse
s@BatchPutAssetPropertyValueResponse' {} Int
a -> BatchPutAssetPropertyValueResponse
s {$sel:httpStatus:BatchPutAssetPropertyValueResponse' :: Int
httpStatus = Int
a} :: BatchPutAssetPropertyValueResponse)

-- | A list of the errors (if any) associated with the batch put request.
-- Each error entry contains the @entryId@ of the entry that failed.
batchPutAssetPropertyValueResponse_errorEntries :: Lens.Lens' BatchPutAssetPropertyValueResponse [BatchPutAssetPropertyErrorEntry]
batchPutAssetPropertyValueResponse_errorEntries :: Lens'
  BatchPutAssetPropertyValueResponse
  [BatchPutAssetPropertyErrorEntry]
batchPutAssetPropertyValueResponse_errorEntries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchPutAssetPropertyValueResponse' {[BatchPutAssetPropertyErrorEntry]
errorEntries :: [BatchPutAssetPropertyErrorEntry]
$sel:errorEntries:BatchPutAssetPropertyValueResponse' :: BatchPutAssetPropertyValueResponse
-> [BatchPutAssetPropertyErrorEntry]
errorEntries} -> [BatchPutAssetPropertyErrorEntry]
errorEntries) (\s :: BatchPutAssetPropertyValueResponse
s@BatchPutAssetPropertyValueResponse' {} [BatchPutAssetPropertyErrorEntry]
a -> BatchPutAssetPropertyValueResponse
s {$sel:errorEntries:BatchPutAssetPropertyValueResponse' :: [BatchPutAssetPropertyErrorEntry]
errorEntries = [BatchPutAssetPropertyErrorEntry]
a} :: BatchPutAssetPropertyValueResponse) 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
  Prelude.NFData
    BatchPutAssetPropertyValueResponse
  where
  rnf :: BatchPutAssetPropertyValueResponse -> ()
rnf BatchPutAssetPropertyValueResponse' {Int
[BatchPutAssetPropertyErrorEntry]
errorEntries :: [BatchPutAssetPropertyErrorEntry]
httpStatus :: Int
$sel:errorEntries:BatchPutAssetPropertyValueResponse' :: BatchPutAssetPropertyValueResponse
-> [BatchPutAssetPropertyErrorEntry]
$sel:httpStatus:BatchPutAssetPropertyValueResponse' :: BatchPutAssetPropertyValueResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [BatchPutAssetPropertyErrorEntry]
errorEntries