{-# 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.ExpressionVariable
-- 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.ExpressionVariable where

import qualified Amazonka.Core as Core
import Amazonka.IoTSiteWise.Types.VariableValue
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains expression variable information.
--
-- /See:/ 'newExpressionVariable' smart constructor.
data ExpressionVariable = ExpressionVariable'
  { -- | The friendly name of the variable to be used in the expression.
    ExpressionVariable -> Text
name :: Prelude.Text,
    -- | The variable that identifies an asset property from which to use values.
    ExpressionVariable -> VariableValue
value :: VariableValue
  }
  deriving (ExpressionVariable -> ExpressionVariable -> Bool
(ExpressionVariable -> ExpressionVariable -> Bool)
-> (ExpressionVariable -> ExpressionVariable -> Bool)
-> Eq ExpressionVariable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExpressionVariable -> ExpressionVariable -> Bool
$c/= :: ExpressionVariable -> ExpressionVariable -> Bool
== :: ExpressionVariable -> ExpressionVariable -> Bool
$c== :: ExpressionVariable -> ExpressionVariable -> Bool
Prelude.Eq, ReadPrec [ExpressionVariable]
ReadPrec ExpressionVariable
Int -> ReadS ExpressionVariable
ReadS [ExpressionVariable]
(Int -> ReadS ExpressionVariable)
-> ReadS [ExpressionVariable]
-> ReadPrec ExpressionVariable
-> ReadPrec [ExpressionVariable]
-> Read ExpressionVariable
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ExpressionVariable]
$creadListPrec :: ReadPrec [ExpressionVariable]
readPrec :: ReadPrec ExpressionVariable
$creadPrec :: ReadPrec ExpressionVariable
readList :: ReadS [ExpressionVariable]
$creadList :: ReadS [ExpressionVariable]
readsPrec :: Int -> ReadS ExpressionVariable
$creadsPrec :: Int -> ReadS ExpressionVariable
Prelude.Read, Int -> ExpressionVariable -> ShowS
[ExpressionVariable] -> ShowS
ExpressionVariable -> String
(Int -> ExpressionVariable -> ShowS)
-> (ExpressionVariable -> String)
-> ([ExpressionVariable] -> ShowS)
-> Show ExpressionVariable
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExpressionVariable] -> ShowS
$cshowList :: [ExpressionVariable] -> ShowS
show :: ExpressionVariable -> String
$cshow :: ExpressionVariable -> String
showsPrec :: Int -> ExpressionVariable -> ShowS
$cshowsPrec :: Int -> ExpressionVariable -> ShowS
Prelude.Show, (forall x. ExpressionVariable -> Rep ExpressionVariable x)
-> (forall x. Rep ExpressionVariable x -> ExpressionVariable)
-> Generic ExpressionVariable
forall x. Rep ExpressionVariable x -> ExpressionVariable
forall x. ExpressionVariable -> Rep ExpressionVariable x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ExpressionVariable x -> ExpressionVariable
$cfrom :: forall x. ExpressionVariable -> Rep ExpressionVariable x
Prelude.Generic)

-- |
-- Create a value of 'ExpressionVariable' 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:
--
-- 'name', 'expressionVariable_name' - The friendly name of the variable to be used in the expression.
--
-- 'value', 'expressionVariable_value' - The variable that identifies an asset property from which to use values.
newExpressionVariable ::
  -- | 'name'
  Prelude.Text ->
  -- | 'value'
  VariableValue ->
  ExpressionVariable
newExpressionVariable :: Text -> VariableValue -> ExpressionVariable
newExpressionVariable Text
pName_ VariableValue
pValue_ =
  ExpressionVariable' :: Text -> VariableValue -> ExpressionVariable
ExpressionVariable' {$sel:name:ExpressionVariable' :: Text
name = Text
pName_, $sel:value:ExpressionVariable' :: VariableValue
value = VariableValue
pValue_}

-- | The friendly name of the variable to be used in the expression.
expressionVariable_name :: Lens.Lens' ExpressionVariable Prelude.Text
expressionVariable_name :: (Text -> f Text) -> ExpressionVariable -> f ExpressionVariable
expressionVariable_name = (ExpressionVariable -> Text)
-> (ExpressionVariable -> Text -> ExpressionVariable)
-> Lens ExpressionVariable ExpressionVariable Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExpressionVariable' {Text
name :: Text
$sel:name:ExpressionVariable' :: ExpressionVariable -> Text
name} -> Text
name) (\s :: ExpressionVariable
s@ExpressionVariable' {} Text
a -> ExpressionVariable
s {$sel:name:ExpressionVariable' :: Text
name = Text
a} :: ExpressionVariable)

-- | The variable that identifies an asset property from which to use values.
expressionVariable_value :: Lens.Lens' ExpressionVariable VariableValue
expressionVariable_value :: (VariableValue -> f VariableValue)
-> ExpressionVariable -> f ExpressionVariable
expressionVariable_value = (ExpressionVariable -> VariableValue)
-> (ExpressionVariable -> VariableValue -> ExpressionVariable)
-> Lens
     ExpressionVariable ExpressionVariable VariableValue VariableValue
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExpressionVariable' {VariableValue
value :: VariableValue
$sel:value:ExpressionVariable' :: ExpressionVariable -> VariableValue
value} -> VariableValue
value) (\s :: ExpressionVariable
s@ExpressionVariable' {} VariableValue
a -> ExpressionVariable
s {$sel:value:ExpressionVariable' :: VariableValue
value = VariableValue
a} :: ExpressionVariable)

instance Core.FromJSON ExpressionVariable where
  parseJSON :: Value -> Parser ExpressionVariable
parseJSON =
    String
-> (Object -> Parser ExpressionVariable)
-> Value
-> Parser ExpressionVariable
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ExpressionVariable"
      ( \Object
x ->
          Text -> VariableValue -> ExpressionVariable
ExpressionVariable'
            (Text -> VariableValue -> ExpressionVariable)
-> Parser Text -> Parser (VariableValue -> ExpressionVariable)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"name") Parser (VariableValue -> ExpressionVariable)
-> Parser VariableValue -> Parser ExpressionVariable
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser VariableValue
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"value")
      )

instance Prelude.Hashable ExpressionVariable

instance Prelude.NFData ExpressionVariable

instance Core.ToJSON ExpressionVariable where
  toJSON :: ExpressionVariable -> Value
toJSON ExpressionVariable' {Text
VariableValue
value :: VariableValue
name :: Text
$sel:value:ExpressionVariable' :: ExpressionVariable -> VariableValue
$sel:name:ExpressionVariable' :: ExpressionVariable -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"value" Text -> VariableValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= VariableValue
value)
          ]
      )