{-# 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.IoTSiteWise.Types.VariableValue
-- 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.IoTSiteWise.Types.VariableValue where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Identifies a property value used in an expression.
--
-- /See:/ 'newVariableValue' smart constructor.
data VariableValue = VariableValue'
  { -- | The ID of the hierarchy to query for the property ID. You can use the
    -- hierarchy\'s name instead of the hierarchy\'s ID.
    --
    -- You use a hierarchy ID instead of a model ID because you can have
    -- several hierarchies using the same model and therefore the same
    -- @propertyId@. For example, you might have separately grouped assets that
    -- come from the same asset model. For more information, see
    -- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/asset-hierarchies.html Asset hierarchies>
    -- in the /IoT SiteWise User Guide/.
    VariableValue -> Maybe Text
hierarchyId :: Prelude.Maybe Prelude.Text,
    -- | The ID of the property to use as the variable. You can use the property
    -- @name@ if it\'s from the same asset model.
    VariableValue -> Text
propertyId :: Prelude.Text
  }
  deriving (VariableValue -> VariableValue -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VariableValue -> VariableValue -> Bool
$c/= :: VariableValue -> VariableValue -> Bool
== :: VariableValue -> VariableValue -> Bool
$c== :: VariableValue -> VariableValue -> Bool
Prelude.Eq, ReadPrec [VariableValue]
ReadPrec VariableValue
Int -> ReadS VariableValue
ReadS [VariableValue]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [VariableValue]
$creadListPrec :: ReadPrec [VariableValue]
readPrec :: ReadPrec VariableValue
$creadPrec :: ReadPrec VariableValue
readList :: ReadS [VariableValue]
$creadList :: ReadS [VariableValue]
readsPrec :: Int -> ReadS VariableValue
$creadsPrec :: Int -> ReadS VariableValue
Prelude.Read, Int -> VariableValue -> ShowS
[VariableValue] -> ShowS
VariableValue -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VariableValue] -> ShowS
$cshowList :: [VariableValue] -> ShowS
show :: VariableValue -> String
$cshow :: VariableValue -> String
showsPrec :: Int -> VariableValue -> ShowS
$cshowsPrec :: Int -> VariableValue -> ShowS
Prelude.Show, forall x. Rep VariableValue x -> VariableValue
forall x. VariableValue -> Rep VariableValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VariableValue x -> VariableValue
$cfrom :: forall x. VariableValue -> Rep VariableValue x
Prelude.Generic)

-- |
-- Create a value of 'VariableValue' 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:
--
-- 'hierarchyId', 'variableValue_hierarchyId' - The ID of the hierarchy to query for the property ID. You can use the
-- hierarchy\'s name instead of the hierarchy\'s ID.
--
-- You use a hierarchy ID instead of a model ID because you can have
-- several hierarchies using the same model and therefore the same
-- @propertyId@. For example, you might have separately grouped assets that
-- come from the same asset model. For more information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/asset-hierarchies.html Asset hierarchies>
-- in the /IoT SiteWise User Guide/.
--
-- 'propertyId', 'variableValue_propertyId' - The ID of the property to use as the variable. You can use the property
-- @name@ if it\'s from the same asset model.
newVariableValue ::
  -- | 'propertyId'
  Prelude.Text ->
  VariableValue
newVariableValue :: Text -> VariableValue
newVariableValue Text
pPropertyId_ =
  VariableValue'
    { $sel:hierarchyId:VariableValue' :: Maybe Text
hierarchyId = forall a. Maybe a
Prelude.Nothing,
      $sel:propertyId:VariableValue' :: Text
propertyId = Text
pPropertyId_
    }

-- | The ID of the hierarchy to query for the property ID. You can use the
-- hierarchy\'s name instead of the hierarchy\'s ID.
--
-- You use a hierarchy ID instead of a model ID because you can have
-- several hierarchies using the same model and therefore the same
-- @propertyId@. For example, you might have separately grouped assets that
-- come from the same asset model. For more information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/asset-hierarchies.html Asset hierarchies>
-- in the /IoT SiteWise User Guide/.
variableValue_hierarchyId :: Lens.Lens' VariableValue (Prelude.Maybe Prelude.Text)
variableValue_hierarchyId :: Lens' VariableValue (Maybe Text)
variableValue_hierarchyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VariableValue' {Maybe Text
hierarchyId :: Maybe Text
$sel:hierarchyId:VariableValue' :: VariableValue -> Maybe Text
hierarchyId} -> Maybe Text
hierarchyId) (\s :: VariableValue
s@VariableValue' {} Maybe Text
a -> VariableValue
s {$sel:hierarchyId:VariableValue' :: Maybe Text
hierarchyId = Maybe Text
a} :: VariableValue)

-- | The ID of the property to use as the variable. You can use the property
-- @name@ if it\'s from the same asset model.
variableValue_propertyId :: Lens.Lens' VariableValue Prelude.Text
variableValue_propertyId :: Lens' VariableValue Text
variableValue_propertyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VariableValue' {Text
propertyId :: Text
$sel:propertyId:VariableValue' :: VariableValue -> Text
propertyId} -> Text
propertyId) (\s :: VariableValue
s@VariableValue' {} Text
a -> VariableValue
s {$sel:propertyId:VariableValue' :: Text
propertyId = Text
a} :: VariableValue)

instance Data.FromJSON VariableValue where
  parseJSON :: Value -> Parser VariableValue
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"VariableValue"
      ( \Object
x ->
          Maybe Text -> Text -> VariableValue
VariableValue'
            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
"hierarchyId")
            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
"propertyId")
      )

instance Prelude.Hashable VariableValue where
  hashWithSalt :: Int -> VariableValue -> Int
hashWithSalt Int
_salt VariableValue' {Maybe Text
Text
propertyId :: Text
hierarchyId :: Maybe Text
$sel:propertyId:VariableValue' :: VariableValue -> Text
$sel:hierarchyId:VariableValue' :: VariableValue -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
hierarchyId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
propertyId

instance Prelude.NFData VariableValue where
  rnf :: VariableValue -> ()
rnf VariableValue' {Maybe Text
Text
propertyId :: Text
hierarchyId :: Maybe Text
$sel:propertyId:VariableValue' :: VariableValue -> Text
$sel:hierarchyId:VariableValue' :: VariableValue -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
hierarchyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
propertyId

instance Data.ToJSON VariableValue where
  toJSON :: VariableValue -> Value
toJSON VariableValue' {Maybe Text
Text
propertyId :: Text
hierarchyId :: Maybe Text
$sel:propertyId:VariableValue' :: VariableValue -> Text
$sel:hierarchyId:VariableValue' :: VariableValue -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"hierarchyId" 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
hierarchyId,
            forall a. a -> Maybe a
Prelude.Just (Key
"propertyId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
propertyId)
          ]
      )