{-# 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-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)
module Amazonka.IoTEvents.Types.IotSiteWiseAction where

import qualified Amazonka.Core as Core
import Amazonka.IoTEvents.Types.AssetPropertyValue
import qualified Amazonka.Lens as Lens
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'
  { -- | 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 value to send to the asset property. This value contains timestamp,
    -- quality, and value (TQV) information.
    IotSiteWiseAction -> Maybe AssetPropertyValue
propertyValue :: Prelude.Maybe AssetPropertyValue,
    -- | The ID of the asset property.
    IotSiteWiseAction -> Maybe Text
propertyId :: Prelude.Maybe Prelude.Text,
    -- | The ID of the asset that has the specified property.
    IotSiteWiseAction -> Maybe Text
assetId :: Prelude.Maybe Prelude.Text
  }
  deriving (IotSiteWiseAction -> IotSiteWiseAction -> Bool
(IotSiteWiseAction -> IotSiteWiseAction -> Bool)
-> (IotSiteWiseAction -> IotSiteWiseAction -> Bool)
-> Eq IotSiteWiseAction
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]
(Int -> ReadS IotSiteWiseAction)
-> ReadS [IotSiteWiseAction]
-> ReadPrec IotSiteWiseAction
-> ReadPrec [IotSiteWiseAction]
-> Read 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
(Int -> IotSiteWiseAction -> ShowS)
-> (IotSiteWiseAction -> String)
-> ([IotSiteWiseAction] -> ShowS)
-> Show IotSiteWiseAction
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. IotSiteWiseAction -> Rep IotSiteWiseAction x)
-> (forall x. Rep IotSiteWiseAction x -> IotSiteWiseAction)
-> Generic IotSiteWiseAction
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:
--
-- '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.
--
-- 'propertyValue', 'iotSiteWiseAction_propertyValue' - The value to send to the asset property. This value contains timestamp,
-- quality, and value (TQV) information.
--
-- 'propertyId', 'iotSiteWiseAction_propertyId' - The ID of the asset property.
--
-- 'assetId', 'iotSiteWiseAction_assetId' - The ID of the asset that has the specified property.
newIotSiteWiseAction ::
  IotSiteWiseAction
newIotSiteWiseAction :: IotSiteWiseAction
newIotSiteWiseAction =
  IotSiteWiseAction' :: Maybe Text
-> Maybe Text
-> Maybe AssetPropertyValue
-> Maybe Text
-> Maybe Text
-> IotSiteWiseAction
IotSiteWiseAction'
    { $sel:entryId:IotSiteWiseAction' :: Maybe Text
entryId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:propertyAlias:IotSiteWiseAction' :: Maybe Text
propertyAlias = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:propertyValue:IotSiteWiseAction' :: Maybe AssetPropertyValue
propertyValue = Maybe AssetPropertyValue
forall a. Maybe a
Prelude.Nothing,
      $sel:propertyId:IotSiteWiseAction' :: Maybe Text
propertyId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:assetId:IotSiteWiseAction' :: Maybe Text
assetId = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe Text -> f (Maybe Text))
-> IotSiteWiseAction -> f IotSiteWiseAction
iotSiteWiseAction_entryId = (IotSiteWiseAction -> Maybe Text)
-> (IotSiteWiseAction -> Maybe Text -> IotSiteWiseAction)
-> Lens
     IotSiteWiseAction IotSiteWiseAction (Maybe Text) (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text))
-> IotSiteWiseAction -> f IotSiteWiseAction
iotSiteWiseAction_propertyAlias = (IotSiteWiseAction -> Maybe Text)
-> (IotSiteWiseAction -> Maybe Text -> IotSiteWiseAction)
-> Lens
     IotSiteWiseAction IotSiteWiseAction (Maybe Text) (Maybe Text)
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 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 :: (Maybe AssetPropertyValue -> f (Maybe AssetPropertyValue))
-> IotSiteWiseAction -> f IotSiteWiseAction
iotSiteWiseAction_propertyValue = (IotSiteWiseAction -> Maybe AssetPropertyValue)
-> (IotSiteWiseAction
    -> Maybe AssetPropertyValue -> IotSiteWiseAction)
-> Lens
     IotSiteWiseAction
     IotSiteWiseAction
     (Maybe AssetPropertyValue)
     (Maybe AssetPropertyValue)
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)

-- | The ID of the asset property.
iotSiteWiseAction_propertyId :: Lens.Lens' IotSiteWiseAction (Prelude.Maybe Prelude.Text)
iotSiteWiseAction_propertyId :: (Maybe Text -> f (Maybe Text))
-> IotSiteWiseAction -> f IotSiteWiseAction
iotSiteWiseAction_propertyId = (IotSiteWiseAction -> Maybe Text)
-> (IotSiteWiseAction -> Maybe Text -> IotSiteWiseAction)
-> Lens
     IotSiteWiseAction IotSiteWiseAction (Maybe Text) (Maybe Text)
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 ID of the asset that has the specified property.
iotSiteWiseAction_assetId :: Lens.Lens' IotSiteWiseAction (Prelude.Maybe Prelude.Text)
iotSiteWiseAction_assetId :: (Maybe Text -> f (Maybe Text))
-> IotSiteWiseAction -> f IotSiteWiseAction
iotSiteWiseAction_assetId = (IotSiteWiseAction -> Maybe Text)
-> (IotSiteWiseAction -> Maybe Text -> IotSiteWiseAction)
-> Lens
     IotSiteWiseAction IotSiteWiseAction (Maybe Text) (Maybe Text)
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)

instance Core.FromJSON IotSiteWiseAction where
  parseJSON :: Value -> Parser IotSiteWiseAction
parseJSON =
    String
-> (Object -> Parser IotSiteWiseAction)
-> Value
-> Parser IotSiteWiseAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"IotSiteWiseAction"
      ( \Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe AssetPropertyValue
-> Maybe Text
-> Maybe Text
-> IotSiteWiseAction
IotSiteWiseAction'
            (Maybe Text
 -> Maybe Text
 -> Maybe AssetPropertyValue
 -> Maybe Text
 -> Maybe Text
 -> IotSiteWiseAction)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe AssetPropertyValue
      -> Maybe Text
      -> Maybe Text
      -> IotSiteWiseAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"entryId")
            Parser
  (Maybe Text
   -> Maybe AssetPropertyValue
   -> Maybe Text
   -> Maybe Text
   -> IotSiteWiseAction)
-> Parser (Maybe Text)
-> Parser
     (Maybe AssetPropertyValue
      -> Maybe Text -> Maybe Text -> IotSiteWiseAction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"propertyAlias")
            Parser
  (Maybe AssetPropertyValue
   -> Maybe Text -> Maybe Text -> IotSiteWiseAction)
-> Parser (Maybe AssetPropertyValue)
-> Parser (Maybe Text -> Maybe Text -> IotSiteWiseAction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe AssetPropertyValue)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"propertyValue")
            Parser (Maybe Text -> Maybe Text -> IotSiteWiseAction)
-> Parser (Maybe Text) -> Parser (Maybe Text -> IotSiteWiseAction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"propertyId")
            Parser (Maybe Text -> IotSiteWiseAction)
-> Parser (Maybe Text) -> Parser IotSiteWiseAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"assetId")
      )

instance Prelude.Hashable IotSiteWiseAction

instance Prelude.NFData IotSiteWiseAction

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