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

-- | A structure that contains value information. For more information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/APIReference/API_AssetPropertyValue.html AssetPropertyValue>
-- in the /AWS IoT SiteWise API Reference/.
--
-- You must use expressions for all parameters in @AssetPropertyValue@. The
-- expressions accept literals, operators, functions, references, and
-- substitution templates.
--
-- __Examples__
--
-- -   For literal values, the expressions must contain single quotes. For
--     example, the value for the @quality@ parameter can be @\'GOOD\'@.
--
-- -   For references, you must specify either variables or input values.
--     For example, the value for the @quality@ parameter can be
--     @$input.TemperatureInput.sensorData.quality@.
--
-- For more information, see
-- <https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-expressions.html Expressions>
-- in the /AWS IoT Events Developer Guide/.
--
-- /See:/ 'newAssetPropertyValue' smart constructor.
data AssetPropertyValue = AssetPropertyValue'
  { -- | The quality of the asset property value. The value must be @\'GOOD\'@,
    -- @\'BAD\'@, or @\'UNCERTAIN\'@.
    AssetPropertyValue -> Maybe Text
quality :: Prelude.Maybe Prelude.Text,
    -- | The timestamp associated with the asset property value. The default is
    -- the current event time.
    AssetPropertyValue -> Maybe AssetPropertyTimestamp
timestamp :: Prelude.Maybe AssetPropertyTimestamp,
    -- | The value to send to an asset property.
    AssetPropertyValue -> Maybe AssetPropertyVariant
value :: Prelude.Maybe AssetPropertyVariant
  }
  deriving (AssetPropertyValue -> AssetPropertyValue -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssetPropertyValue -> AssetPropertyValue -> Bool
$c/= :: AssetPropertyValue -> AssetPropertyValue -> Bool
== :: AssetPropertyValue -> AssetPropertyValue -> Bool
$c== :: AssetPropertyValue -> AssetPropertyValue -> Bool
Prelude.Eq, ReadPrec [AssetPropertyValue]
ReadPrec AssetPropertyValue
Int -> ReadS AssetPropertyValue
ReadS [AssetPropertyValue]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssetPropertyValue]
$creadListPrec :: ReadPrec [AssetPropertyValue]
readPrec :: ReadPrec AssetPropertyValue
$creadPrec :: ReadPrec AssetPropertyValue
readList :: ReadS [AssetPropertyValue]
$creadList :: ReadS [AssetPropertyValue]
readsPrec :: Int -> ReadS AssetPropertyValue
$creadsPrec :: Int -> ReadS AssetPropertyValue
Prelude.Read, Int -> AssetPropertyValue -> ShowS
[AssetPropertyValue] -> ShowS
AssetPropertyValue -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssetPropertyValue] -> ShowS
$cshowList :: [AssetPropertyValue] -> ShowS
show :: AssetPropertyValue -> String
$cshow :: AssetPropertyValue -> String
showsPrec :: Int -> AssetPropertyValue -> ShowS
$cshowsPrec :: Int -> AssetPropertyValue -> ShowS
Prelude.Show, forall x. Rep AssetPropertyValue x -> AssetPropertyValue
forall x. AssetPropertyValue -> Rep AssetPropertyValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssetPropertyValue x -> AssetPropertyValue
$cfrom :: forall x. AssetPropertyValue -> Rep AssetPropertyValue x
Prelude.Generic)

-- |
-- Create a value of 'AssetPropertyValue' 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:
--
-- 'quality', 'assetPropertyValue_quality' - The quality of the asset property value. The value must be @\'GOOD\'@,
-- @\'BAD\'@, or @\'UNCERTAIN\'@.
--
-- 'timestamp', 'assetPropertyValue_timestamp' - The timestamp associated with the asset property value. The default is
-- the current event time.
--
-- 'value', 'assetPropertyValue_value' - The value to send to an asset property.
newAssetPropertyValue ::
  AssetPropertyValue
newAssetPropertyValue :: AssetPropertyValue
newAssetPropertyValue =
  AssetPropertyValue'
    { $sel:quality:AssetPropertyValue' :: Maybe Text
quality = forall a. Maybe a
Prelude.Nothing,
      $sel:timestamp:AssetPropertyValue' :: Maybe AssetPropertyTimestamp
timestamp = forall a. Maybe a
Prelude.Nothing,
      $sel:value:AssetPropertyValue' :: Maybe AssetPropertyVariant
value = forall a. Maybe a
Prelude.Nothing
    }

-- | The quality of the asset property value. The value must be @\'GOOD\'@,
-- @\'BAD\'@, or @\'UNCERTAIN\'@.
assetPropertyValue_quality :: Lens.Lens' AssetPropertyValue (Prelude.Maybe Prelude.Text)
assetPropertyValue_quality :: Lens' AssetPropertyValue (Maybe Text)
assetPropertyValue_quality = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssetPropertyValue' {Maybe Text
quality :: Maybe Text
$sel:quality:AssetPropertyValue' :: AssetPropertyValue -> Maybe Text
quality} -> Maybe Text
quality) (\s :: AssetPropertyValue
s@AssetPropertyValue' {} Maybe Text
a -> AssetPropertyValue
s {$sel:quality:AssetPropertyValue' :: Maybe Text
quality = Maybe Text
a} :: AssetPropertyValue)

-- | The timestamp associated with the asset property value. The default is
-- the current event time.
assetPropertyValue_timestamp :: Lens.Lens' AssetPropertyValue (Prelude.Maybe AssetPropertyTimestamp)
assetPropertyValue_timestamp :: Lens' AssetPropertyValue (Maybe AssetPropertyTimestamp)
assetPropertyValue_timestamp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssetPropertyValue' {Maybe AssetPropertyTimestamp
timestamp :: Maybe AssetPropertyTimestamp
$sel:timestamp:AssetPropertyValue' :: AssetPropertyValue -> Maybe AssetPropertyTimestamp
timestamp} -> Maybe AssetPropertyTimestamp
timestamp) (\s :: AssetPropertyValue
s@AssetPropertyValue' {} Maybe AssetPropertyTimestamp
a -> AssetPropertyValue
s {$sel:timestamp:AssetPropertyValue' :: Maybe AssetPropertyTimestamp
timestamp = Maybe AssetPropertyTimestamp
a} :: AssetPropertyValue)

-- | The value to send to an asset property.
assetPropertyValue_value :: Lens.Lens' AssetPropertyValue (Prelude.Maybe AssetPropertyVariant)
assetPropertyValue_value :: Lens' AssetPropertyValue (Maybe AssetPropertyVariant)
assetPropertyValue_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssetPropertyValue' {Maybe AssetPropertyVariant
value :: Maybe AssetPropertyVariant
$sel:value:AssetPropertyValue' :: AssetPropertyValue -> Maybe AssetPropertyVariant
value} -> Maybe AssetPropertyVariant
value) (\s :: AssetPropertyValue
s@AssetPropertyValue' {} Maybe AssetPropertyVariant
a -> AssetPropertyValue
s {$sel:value:AssetPropertyValue' :: Maybe AssetPropertyVariant
value = Maybe AssetPropertyVariant
a} :: AssetPropertyValue)

instance Data.FromJSON AssetPropertyValue where
  parseJSON :: Value -> Parser AssetPropertyValue
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AssetPropertyValue"
      ( \Object
x ->
          Maybe Text
-> Maybe AssetPropertyTimestamp
-> Maybe AssetPropertyVariant
-> AssetPropertyValue
AssetPropertyValue'
            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
"quality")
            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
"timestamp")
            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
"value")
      )

instance Prelude.Hashable AssetPropertyValue where
  hashWithSalt :: Int -> AssetPropertyValue -> Int
hashWithSalt Int
_salt AssetPropertyValue' {Maybe Text
Maybe AssetPropertyTimestamp
Maybe AssetPropertyVariant
value :: Maybe AssetPropertyVariant
timestamp :: Maybe AssetPropertyTimestamp
quality :: Maybe Text
$sel:value:AssetPropertyValue' :: AssetPropertyValue -> Maybe AssetPropertyVariant
$sel:timestamp:AssetPropertyValue' :: AssetPropertyValue -> Maybe AssetPropertyTimestamp
$sel:quality:AssetPropertyValue' :: AssetPropertyValue -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
quality
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AssetPropertyTimestamp
timestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AssetPropertyVariant
value

instance Prelude.NFData AssetPropertyValue where
  rnf :: AssetPropertyValue -> ()
rnf AssetPropertyValue' {Maybe Text
Maybe AssetPropertyTimestamp
Maybe AssetPropertyVariant
value :: Maybe AssetPropertyVariant
timestamp :: Maybe AssetPropertyTimestamp
quality :: Maybe Text
$sel:value:AssetPropertyValue' :: AssetPropertyValue -> Maybe AssetPropertyVariant
$sel:timestamp:AssetPropertyValue' :: AssetPropertyValue -> Maybe AssetPropertyTimestamp
$sel:quality:AssetPropertyValue' :: AssetPropertyValue -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
quality
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe AssetPropertyTimestamp
timestamp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe AssetPropertyVariant
value

instance Data.ToJSON AssetPropertyValue where
  toJSON :: AssetPropertyValue -> Value
toJSON AssetPropertyValue' {Maybe Text
Maybe AssetPropertyTimestamp
Maybe AssetPropertyVariant
value :: Maybe AssetPropertyVariant
timestamp :: Maybe AssetPropertyTimestamp
quality :: Maybe Text
$sel:value:AssetPropertyValue' :: AssetPropertyValue -> Maybe AssetPropertyVariant
$sel:timestamp:AssetPropertyValue' :: AssetPropertyValue -> Maybe AssetPropertyTimestamp
$sel:quality:AssetPropertyValue' :: AssetPropertyValue -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"quality" 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
quality,
            (Key
"timestamp" 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 AssetPropertyTimestamp
timestamp,
            (Key
"value" 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 AssetPropertyVariant
value
          ]
      )