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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(VariableValue -> VariableValue -> Bool)
-> (VariableValue -> VariableValue -> Bool) -> Eq VariableValue
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]
(Int -> ReadS VariableValue)
-> ReadS [VariableValue]
-> ReadPrec VariableValue
-> ReadPrec [VariableValue]
-> Read 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
(Int -> VariableValue -> ShowS)
-> (VariableValue -> String)
-> ([VariableValue] -> ShowS)
-> Show VariableValue
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. VariableValue -> Rep VariableValue x)
-> (forall x. Rep VariableValue x -> VariableValue)
-> Generic VariableValue
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' :: Maybe Text -> Text -> VariableValue
VariableValue'
    { $sel:hierarchyId:VariableValue' :: Maybe Text
hierarchyId = Maybe Text
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 :: (Maybe Text -> f (Maybe Text)) -> VariableValue -> f VariableValue
variableValue_hierarchyId = (VariableValue -> Maybe Text)
-> (VariableValue -> Maybe Text -> VariableValue)
-> Lens VariableValue VariableValue (Maybe Text) (Maybe Text)
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 :: (Text -> f Text) -> VariableValue -> f VariableValue
variableValue_propertyId = (VariableValue -> Text)
-> (VariableValue -> Text -> VariableValue)
-> Lens VariableValue VariableValue Text Text
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 Core.FromJSON VariableValue where
  parseJSON :: Value -> Parser VariableValue
parseJSON =
    String
-> (Object -> Parser VariableValue)
-> Value
-> Parser VariableValue
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"VariableValue"
      ( \Object
x ->
          Maybe Text -> Text -> VariableValue
VariableValue'
            (Maybe Text -> Text -> VariableValue)
-> Parser (Maybe Text) -> Parser (Text -> VariableValue)
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
"hierarchyId")
            Parser (Text -> VariableValue)
-> Parser Text -> Parser VariableValue
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"propertyId")
      )

instance Prelude.Hashable VariableValue

instance Prelude.NFData VariableValue

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"hierarchyId" 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
hierarchyId,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"propertyId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
propertyId)
          ]
      )