{-# 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.IoT.Types.IotSiteWiseAction
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoT.Types.IotSiteWiseAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoT.Types.PutAssetPropertyValueEntry
import qualified Amazonka.Prelude as Prelude

-- | Describes an action to send data from an MQTT message that triggered the
-- rule to IoT SiteWise asset properties.
--
-- /See:/ 'newIotSiteWiseAction' smart constructor.
data IotSiteWiseAction = IotSiteWiseAction'
  { -- | A list of asset property value entries.
    IotSiteWiseAction -> NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries :: Prelude.NonEmpty PutAssetPropertyValueEntry,
    -- | The ARN of the role that grants IoT permission to send an asset property
    -- value to IoT SiteWise.
    -- (@\"Action\": \"iotsitewise:BatchPutAssetPropertyValue\"@). The trust
    -- policy can restrict access to specific asset hierarchy paths.
    IotSiteWiseAction -> Text
roleArn :: Prelude.Text
  }
  deriving (IotSiteWiseAction -> IotSiteWiseAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IotSiteWiseAction -> IotSiteWiseAction -> Bool
$c/= :: IotSiteWiseAction -> IotSiteWiseAction -> Bool
== :: IotSiteWiseAction -> IotSiteWiseAction -> Bool
$c== :: IotSiteWiseAction -> IotSiteWiseAction -> Bool
Prelude.Eq, ReadPrec [IotSiteWiseAction]
ReadPrec IotSiteWiseAction
Int -> ReadS IotSiteWiseAction
ReadS [IotSiteWiseAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IotSiteWiseAction]
$creadListPrec :: ReadPrec [IotSiteWiseAction]
readPrec :: ReadPrec IotSiteWiseAction
$creadPrec :: ReadPrec IotSiteWiseAction
readList :: ReadS [IotSiteWiseAction]
$creadList :: ReadS [IotSiteWiseAction]
readsPrec :: Int -> ReadS IotSiteWiseAction
$creadsPrec :: Int -> ReadS IotSiteWiseAction
Prelude.Read, Int -> IotSiteWiseAction -> ShowS
[IotSiteWiseAction] -> ShowS
IotSiteWiseAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IotSiteWiseAction] -> ShowS
$cshowList :: [IotSiteWiseAction] -> ShowS
show :: IotSiteWiseAction -> String
$cshow :: IotSiteWiseAction -> String
showsPrec :: Int -> IotSiteWiseAction -> ShowS
$cshowsPrec :: Int -> IotSiteWiseAction -> ShowS
Prelude.Show, forall x. Rep IotSiteWiseAction x -> IotSiteWiseAction
forall x. IotSiteWiseAction -> Rep IotSiteWiseAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IotSiteWiseAction x -> IotSiteWiseAction
$cfrom :: forall x. IotSiteWiseAction -> Rep IotSiteWiseAction x
Prelude.Generic)

-- |
-- Create a value of 'IotSiteWiseAction' 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:
--
-- 'putAssetPropertyValueEntries', 'iotSiteWiseAction_putAssetPropertyValueEntries' - A list of asset property value entries.
--
-- 'roleArn', 'iotSiteWiseAction_roleArn' - The ARN of the role that grants IoT permission to send an asset property
-- value to IoT SiteWise.
-- (@\"Action\": \"iotsitewise:BatchPutAssetPropertyValue\"@). The trust
-- policy can restrict access to specific asset hierarchy paths.
newIotSiteWiseAction ::
  -- | 'putAssetPropertyValueEntries'
  Prelude.NonEmpty PutAssetPropertyValueEntry ->
  -- | 'roleArn'
  Prelude.Text ->
  IotSiteWiseAction
newIotSiteWiseAction :: NonEmpty PutAssetPropertyValueEntry -> Text -> IotSiteWiseAction
newIotSiteWiseAction
  NonEmpty PutAssetPropertyValueEntry
pPutAssetPropertyValueEntries_
  Text
pRoleArn_ =
    IotSiteWiseAction'
      { $sel:putAssetPropertyValueEntries:IotSiteWiseAction' :: NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries =
          forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty PutAssetPropertyValueEntry
pPutAssetPropertyValueEntries_,
        $sel:roleArn:IotSiteWiseAction' :: Text
roleArn = Text
pRoleArn_
      }

-- | A list of asset property value entries.
iotSiteWiseAction_putAssetPropertyValueEntries :: Lens.Lens' IotSiteWiseAction (Prelude.NonEmpty PutAssetPropertyValueEntry)
iotSiteWiseAction_putAssetPropertyValueEntries :: Lens' IotSiteWiseAction (NonEmpty PutAssetPropertyValueEntry)
iotSiteWiseAction_putAssetPropertyValueEntries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotSiteWiseAction' {NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries :: NonEmpty PutAssetPropertyValueEntry
$sel:putAssetPropertyValueEntries:IotSiteWiseAction' :: IotSiteWiseAction -> NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries} -> NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries) (\s :: IotSiteWiseAction
s@IotSiteWiseAction' {} NonEmpty PutAssetPropertyValueEntry
a -> IotSiteWiseAction
s {$sel:putAssetPropertyValueEntries:IotSiteWiseAction' :: NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries = NonEmpty PutAssetPropertyValueEntry
a} :: IotSiteWiseAction) 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

-- | The ARN of the role that grants IoT permission to send an asset property
-- value to IoT SiteWise.
-- (@\"Action\": \"iotsitewise:BatchPutAssetPropertyValue\"@). The trust
-- policy can restrict access to specific asset hierarchy paths.
iotSiteWiseAction_roleArn :: Lens.Lens' IotSiteWiseAction Prelude.Text
iotSiteWiseAction_roleArn :: Lens' IotSiteWiseAction Text
iotSiteWiseAction_roleArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotSiteWiseAction' {Text
roleArn :: Text
$sel:roleArn:IotSiteWiseAction' :: IotSiteWiseAction -> Text
roleArn} -> Text
roleArn) (\s :: IotSiteWiseAction
s@IotSiteWiseAction' {} Text
a -> IotSiteWiseAction
s {$sel:roleArn:IotSiteWiseAction' :: Text
roleArn = Text
a} :: IotSiteWiseAction)

instance Data.FromJSON IotSiteWiseAction where
  parseJSON :: Value -> Parser IotSiteWiseAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"IotSiteWiseAction"
      ( \Object
x ->
          NonEmpty PutAssetPropertyValueEntry -> Text -> IotSiteWiseAction
IotSiteWiseAction'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"putAssetPropertyValueEntries")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"roleArn")
      )

instance Prelude.Hashable IotSiteWiseAction where
  hashWithSalt :: Int -> IotSiteWiseAction -> Int
hashWithSalt Int
_salt IotSiteWiseAction' {NonEmpty PutAssetPropertyValueEntry
Text
roleArn :: Text
putAssetPropertyValueEntries :: NonEmpty PutAssetPropertyValueEntry
$sel:roleArn:IotSiteWiseAction' :: IotSiteWiseAction -> Text
$sel:putAssetPropertyValueEntries:IotSiteWiseAction' :: IotSiteWiseAction -> NonEmpty PutAssetPropertyValueEntry
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleArn

instance Prelude.NFData IotSiteWiseAction where
  rnf :: IotSiteWiseAction -> ()
rnf IotSiteWiseAction' {NonEmpty PutAssetPropertyValueEntry
Text
roleArn :: Text
putAssetPropertyValueEntries :: NonEmpty PutAssetPropertyValueEntry
$sel:roleArn:IotSiteWiseAction' :: IotSiteWiseAction -> Text
$sel:putAssetPropertyValueEntries:IotSiteWiseAction' :: IotSiteWiseAction -> NonEmpty PutAssetPropertyValueEntry
..} =
    forall a. NFData a => a -> ()
Prelude.rnf NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
roleArn

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