{-# 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.IoTEvents.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.IoTEvents.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.IoTEvents.Types.AssetPropertyValue
import qualified Amazonka.Prelude as Prelude

-- | Sends information about the detector model instance and the event that
-- triggered the action to a specified asset property in AWS IoT SiteWise.
--
-- You must use expressions for all parameters in @IotSiteWiseAction@. The
-- expressions accept literals, operators, functions, references, and
-- substitutions templates.
--
-- __Examples__
--
-- -   For literal values, the expressions must contain single quotes. For
--     example, the value for the @propertyAlias@ parameter can be
--     @\'\/company\/windfarm\/3\/turbine\/7\/temperature\'@.
--
-- -   For references, you must specify either variables or input values.
--     For example, the value for the @assetId@ parameter can be
--     @$input.TurbineInput.assetId1@.
--
-- -   For a substitution template, you must use @${}@, and the template
--     must be in single quotes. A substitution template can also contain a
--     combination of literals, operators, functions, references, and
--     substitution templates.
--
--     In the following example, the value for the @propertyAlias@
--     parameter uses a substitution template.
--
--     @\'company\/windfarm\/${$input.TemperatureInput.sensorData.windfarmID}\/turbine\/ ${$input.TemperatureInput.sensorData.turbineID}\/temperature\'@
--
-- You must specify either @propertyAlias@ or both @assetId@ and
-- @propertyId@ to identify the target asset property in AWS IoT SiteWise.
--
-- For more information, see
-- <https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-expressions.html Expressions>
-- in the /AWS IoT Events Developer Guide/.
--
-- /See:/ 'newIotSiteWiseAction' smart constructor.
data IotSiteWiseAction = IotSiteWiseAction'
  { -- | The ID of the asset that has the specified property.
    IotSiteWiseAction -> Maybe Text
assetId :: Prelude.Maybe Prelude.Text,
    -- | A unique identifier for this entry. You can use the entry ID to track
    -- which data entry causes an error in case of failure. The default is a
    -- new unique identifier.
    IotSiteWiseAction -> Maybe Text
entryId :: Prelude.Maybe Prelude.Text,
    -- | The alias of the asset property.
    IotSiteWiseAction -> Maybe Text
propertyAlias :: Prelude.Maybe Prelude.Text,
    -- | The ID of the asset property.
    IotSiteWiseAction -> Maybe Text
propertyId :: Prelude.Maybe Prelude.Text,
    -- | The value to send to the asset property. This value contains timestamp,
    -- quality, and value (TQV) information.
    IotSiteWiseAction -> Maybe AssetPropertyValue
propertyValue :: Prelude.Maybe AssetPropertyValue
  }
  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:
--
-- 'assetId', 'iotSiteWiseAction_assetId' - The ID of the asset that has the specified property.
--
-- 'entryId', 'iotSiteWiseAction_entryId' - A unique identifier for this entry. You can use the entry ID to track
-- which data entry causes an error in case of failure. The default is a
-- new unique identifier.
--
-- 'propertyAlias', 'iotSiteWiseAction_propertyAlias' - The alias of the asset property.
--
-- 'propertyId', 'iotSiteWiseAction_propertyId' - The ID of the asset property.
--
-- 'propertyValue', 'iotSiteWiseAction_propertyValue' - The value to send to the asset property. This value contains timestamp,
-- quality, and value (TQV) information.
newIotSiteWiseAction ::
  IotSiteWiseAction
newIotSiteWiseAction :: IotSiteWiseAction
newIotSiteWiseAction =
  IotSiteWiseAction'
    { $sel:assetId:IotSiteWiseAction' :: Maybe Text
assetId = forall a. Maybe a
Prelude.Nothing,
      $sel:entryId:IotSiteWiseAction' :: Maybe Text
entryId = forall a. Maybe a
Prelude.Nothing,
      $sel:propertyAlias:IotSiteWiseAction' :: Maybe Text
propertyAlias = forall a. Maybe a
Prelude.Nothing,
      $sel:propertyId:IotSiteWiseAction' :: Maybe Text
propertyId = forall a. Maybe a
Prelude.Nothing,
      $sel:propertyValue:IotSiteWiseAction' :: Maybe AssetPropertyValue
propertyValue = forall a. Maybe a
Prelude.Nothing
    }

-- | The ID of the asset that has the specified property.
iotSiteWiseAction_assetId :: Lens.Lens' IotSiteWiseAction (Prelude.Maybe Prelude.Text)
iotSiteWiseAction_assetId :: Lens' IotSiteWiseAction (Maybe Text)
iotSiteWiseAction_assetId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotSiteWiseAction' {Maybe Text
assetId :: Maybe Text
$sel:assetId:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
assetId} -> Maybe Text
assetId) (\s :: IotSiteWiseAction
s@IotSiteWiseAction' {} Maybe Text
a -> IotSiteWiseAction
s {$sel:assetId:IotSiteWiseAction' :: Maybe Text
assetId = Maybe Text
a} :: IotSiteWiseAction)

-- | A unique identifier for this entry. You can use the entry ID to track
-- which data entry causes an error in case of failure. The default is a
-- new unique identifier.
iotSiteWiseAction_entryId :: Lens.Lens' IotSiteWiseAction (Prelude.Maybe Prelude.Text)
iotSiteWiseAction_entryId :: Lens' IotSiteWiseAction (Maybe Text)
iotSiteWiseAction_entryId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotSiteWiseAction' {Maybe Text
entryId :: Maybe Text
$sel:entryId:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
entryId} -> Maybe Text
entryId) (\s :: IotSiteWiseAction
s@IotSiteWiseAction' {} Maybe Text
a -> IotSiteWiseAction
s {$sel:entryId:IotSiteWiseAction' :: Maybe Text
entryId = Maybe Text
a} :: IotSiteWiseAction)

-- | The alias of the asset property.
iotSiteWiseAction_propertyAlias :: Lens.Lens' IotSiteWiseAction (Prelude.Maybe Prelude.Text)
iotSiteWiseAction_propertyAlias :: Lens' IotSiteWiseAction (Maybe Text)
iotSiteWiseAction_propertyAlias = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotSiteWiseAction' {Maybe Text
propertyAlias :: Maybe Text
$sel:propertyAlias:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
propertyAlias} -> Maybe Text
propertyAlias) (\s :: IotSiteWiseAction
s@IotSiteWiseAction' {} Maybe Text
a -> IotSiteWiseAction
s {$sel:propertyAlias:IotSiteWiseAction' :: Maybe Text
propertyAlias = Maybe Text
a} :: IotSiteWiseAction)

-- | The ID of the asset property.
iotSiteWiseAction_propertyId :: Lens.Lens' IotSiteWiseAction (Prelude.Maybe Prelude.Text)
iotSiteWiseAction_propertyId :: Lens' IotSiteWiseAction (Maybe Text)
iotSiteWiseAction_propertyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotSiteWiseAction' {Maybe Text
propertyId :: Maybe Text
$sel:propertyId:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
propertyId} -> Maybe Text
propertyId) (\s :: IotSiteWiseAction
s@IotSiteWiseAction' {} Maybe Text
a -> IotSiteWiseAction
s {$sel:propertyId:IotSiteWiseAction' :: Maybe Text
propertyId = Maybe Text
a} :: IotSiteWiseAction)

-- | The value to send to the asset property. This value contains timestamp,
-- quality, and value (TQV) information.
iotSiteWiseAction_propertyValue :: Lens.Lens' IotSiteWiseAction (Prelude.Maybe AssetPropertyValue)
iotSiteWiseAction_propertyValue :: Lens' IotSiteWiseAction (Maybe AssetPropertyValue)
iotSiteWiseAction_propertyValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotSiteWiseAction' {Maybe AssetPropertyValue
propertyValue :: Maybe AssetPropertyValue
$sel:propertyValue:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe AssetPropertyValue
propertyValue} -> Maybe AssetPropertyValue
propertyValue) (\s :: IotSiteWiseAction
s@IotSiteWiseAction' {} Maybe AssetPropertyValue
a -> IotSiteWiseAction
s {$sel:propertyValue:IotSiteWiseAction' :: Maybe AssetPropertyValue
propertyValue = Maybe AssetPropertyValue
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 ->
          Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe AssetPropertyValue
-> IotSiteWiseAction
IotSiteWiseAction'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"assetId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"entryId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"propertyAlias")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"propertyId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"propertyValue")
      )

instance Prelude.Hashable IotSiteWiseAction where
  hashWithSalt :: Int -> IotSiteWiseAction -> Int
hashWithSalt Int
_salt IotSiteWiseAction' {Maybe Text
Maybe AssetPropertyValue
propertyValue :: Maybe AssetPropertyValue
propertyId :: Maybe Text
propertyAlias :: Maybe Text
entryId :: Maybe Text
assetId :: Maybe Text
$sel:propertyValue:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe AssetPropertyValue
$sel:propertyId:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
$sel:propertyAlias:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
$sel:entryId:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
$sel:assetId:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
assetId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
entryId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
propertyAlias
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
propertyId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AssetPropertyValue
propertyValue

instance Prelude.NFData IotSiteWiseAction where
  rnf :: IotSiteWiseAction -> ()
rnf IotSiteWiseAction' {Maybe Text
Maybe AssetPropertyValue
propertyValue :: Maybe AssetPropertyValue
propertyId :: Maybe Text
propertyAlias :: Maybe Text
entryId :: Maybe Text
assetId :: Maybe Text
$sel:propertyValue:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe AssetPropertyValue
$sel:propertyId:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
$sel:propertyAlias:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
$sel:entryId:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
$sel:assetId:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
assetId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
entryId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
propertyAlias
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
propertyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe AssetPropertyValue
propertyValue

instance Data.ToJSON IotSiteWiseAction where
  toJSON :: IotSiteWiseAction -> Value
toJSON IotSiteWiseAction' {Maybe Text
Maybe AssetPropertyValue
propertyValue :: Maybe AssetPropertyValue
propertyId :: Maybe Text
propertyAlias :: Maybe Text
entryId :: Maybe Text
assetId :: Maybe Text
$sel:propertyValue:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe AssetPropertyValue
$sel:propertyId:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
$sel:propertyAlias:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
$sel:entryId:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
$sel:assetId:IotSiteWiseAction' :: IotSiteWiseAction -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"assetId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
assetId,
            (Key
"entryId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
entryId,
            (Key
"propertyAlias" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
propertyAlias,
            (Key
"propertyId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
propertyId,
            (Key
"propertyValue" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AssetPropertyValue
propertyValue
          ]
      )