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

import qualified Amazonka.Core as Core
import Amazonka.IoTSiteWise.Types.ExpressionVariable
import Amazonka.IoTSiteWise.Types.TransformProcessingConfig
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains an asset transform property. A transform is a one-to-one
-- mapping of a property\'s data points from one form to another. For
-- example, you can use a transform to convert a Celsius data stream to
-- Fahrenheit by applying the transformation expression to each data point
-- of the Celsius stream. A transform can only have a data type of @DOUBLE@
-- and consume properties with data types of @INTEGER@ or @DOUBLE@.
--
-- For more information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/asset-properties.html#transforms Transforms>
-- in the /IoT SiteWise User Guide/.
--
-- /See:/ 'newTransform' smart constructor.
data Transform = Transform'
  { -- | The processing configuration for the given transform property. You can
    -- configure transforms to be kept at the edge or forwarded to the Amazon
    -- Web Services Cloud. You can also configure transforms to be computed at
    -- the edge or in the cloud.
    Transform -> Maybe TransformProcessingConfig
processingConfig :: Prelude.Maybe TransformProcessingConfig,
    -- | The mathematical expression that defines the transformation function.
    -- You can specify up to 10 variables per expression. You can specify up to
    -- 10 functions per expression.
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/quotas.html Quotas>
    -- in the /IoT SiteWise User Guide/.
    Transform -> Text
expression :: Prelude.Text,
    -- | The list of variables used in the expression.
    Transform -> [ExpressionVariable]
variables :: [ExpressionVariable]
  }
  deriving (Transform -> Transform -> Bool
(Transform -> Transform -> Bool)
-> (Transform -> Transform -> Bool) -> Eq Transform
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Transform -> Transform -> Bool
$c/= :: Transform -> Transform -> Bool
== :: Transform -> Transform -> Bool
$c== :: Transform -> Transform -> Bool
Prelude.Eq, ReadPrec [Transform]
ReadPrec Transform
Int -> ReadS Transform
ReadS [Transform]
(Int -> ReadS Transform)
-> ReadS [Transform]
-> ReadPrec Transform
-> ReadPrec [Transform]
-> Read Transform
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Transform]
$creadListPrec :: ReadPrec [Transform]
readPrec :: ReadPrec Transform
$creadPrec :: ReadPrec Transform
readList :: ReadS [Transform]
$creadList :: ReadS [Transform]
readsPrec :: Int -> ReadS Transform
$creadsPrec :: Int -> ReadS Transform
Prelude.Read, Int -> Transform -> ShowS
[Transform] -> ShowS
Transform -> String
(Int -> Transform -> ShowS)
-> (Transform -> String)
-> ([Transform] -> ShowS)
-> Show Transform
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Transform] -> ShowS
$cshowList :: [Transform] -> ShowS
show :: Transform -> String
$cshow :: Transform -> String
showsPrec :: Int -> Transform -> ShowS
$cshowsPrec :: Int -> Transform -> ShowS
Prelude.Show, (forall x. Transform -> Rep Transform x)
-> (forall x. Rep Transform x -> Transform) -> Generic Transform
forall x. Rep Transform x -> Transform
forall x. Transform -> Rep Transform x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Transform x -> Transform
$cfrom :: forall x. Transform -> Rep Transform x
Prelude.Generic)

-- |
-- Create a value of 'Transform' 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:
--
-- 'processingConfig', 'transform_processingConfig' - The processing configuration for the given transform property. You can
-- configure transforms to be kept at the edge or forwarded to the Amazon
-- Web Services Cloud. You can also configure transforms to be computed at
-- the edge or in the cloud.
--
-- 'expression', 'transform_expression' - The mathematical expression that defines the transformation function.
-- You can specify up to 10 variables per expression. You can specify up to
-- 10 functions per expression.
--
-- For more information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/quotas.html Quotas>
-- in the /IoT SiteWise User Guide/.
--
-- 'variables', 'transform_variables' - The list of variables used in the expression.
newTransform ::
  -- | 'expression'
  Prelude.Text ->
  Transform
newTransform :: Text -> Transform
newTransform Text
pExpression_ =
  Transform' :: Maybe TransformProcessingConfig
-> Text -> [ExpressionVariable] -> Transform
Transform'
    { $sel:processingConfig:Transform' :: Maybe TransformProcessingConfig
processingConfig = Maybe TransformProcessingConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:expression:Transform' :: Text
expression = Text
pExpression_,
      $sel:variables:Transform' :: [ExpressionVariable]
variables = [ExpressionVariable]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The processing configuration for the given transform property. You can
-- configure transforms to be kept at the edge or forwarded to the Amazon
-- Web Services Cloud. You can also configure transforms to be computed at
-- the edge or in the cloud.
transform_processingConfig :: Lens.Lens' Transform (Prelude.Maybe TransformProcessingConfig)
transform_processingConfig :: (Maybe TransformProcessingConfig
 -> f (Maybe TransformProcessingConfig))
-> Transform -> f Transform
transform_processingConfig = (Transform -> Maybe TransformProcessingConfig)
-> (Transform -> Maybe TransformProcessingConfig -> Transform)
-> Lens
     Transform
     Transform
     (Maybe TransformProcessingConfig)
     (Maybe TransformProcessingConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Transform' {Maybe TransformProcessingConfig
processingConfig :: Maybe TransformProcessingConfig
$sel:processingConfig:Transform' :: Transform -> Maybe TransformProcessingConfig
processingConfig} -> Maybe TransformProcessingConfig
processingConfig) (\s :: Transform
s@Transform' {} Maybe TransformProcessingConfig
a -> Transform
s {$sel:processingConfig:Transform' :: Maybe TransformProcessingConfig
processingConfig = Maybe TransformProcessingConfig
a} :: Transform)

-- | The mathematical expression that defines the transformation function.
-- You can specify up to 10 variables per expression. You can specify up to
-- 10 functions per expression.
--
-- For more information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/quotas.html Quotas>
-- in the /IoT SiteWise User Guide/.
transform_expression :: Lens.Lens' Transform Prelude.Text
transform_expression :: (Text -> f Text) -> Transform -> f Transform
transform_expression = (Transform -> Text)
-> (Transform -> Text -> Transform)
-> Lens Transform Transform Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Transform' {Text
expression :: Text
$sel:expression:Transform' :: Transform -> Text
expression} -> Text
expression) (\s :: Transform
s@Transform' {} Text
a -> Transform
s {$sel:expression:Transform' :: Text
expression = Text
a} :: Transform)

-- | The list of variables used in the expression.
transform_variables :: Lens.Lens' Transform [ExpressionVariable]
transform_variables :: ([ExpressionVariable] -> f [ExpressionVariable])
-> Transform -> f Transform
transform_variables = (Transform -> [ExpressionVariable])
-> (Transform -> [ExpressionVariable] -> Transform)
-> Lens
     Transform Transform [ExpressionVariable] [ExpressionVariable]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Transform' {[ExpressionVariable]
variables :: [ExpressionVariable]
$sel:variables:Transform' :: Transform -> [ExpressionVariable]
variables} -> [ExpressionVariable]
variables) (\s :: Transform
s@Transform' {} [ExpressionVariable]
a -> Transform
s {$sel:variables:Transform' :: [ExpressionVariable]
variables = [ExpressionVariable]
a} :: Transform) (([ExpressionVariable] -> f [ExpressionVariable])
 -> Transform -> f Transform)
-> (([ExpressionVariable] -> f [ExpressionVariable])
    -> [ExpressionVariable] -> f [ExpressionVariable])
-> ([ExpressionVariable] -> f [ExpressionVariable])
-> Transform
-> f Transform
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([ExpressionVariable] -> f [ExpressionVariable])
-> [ExpressionVariable] -> f [ExpressionVariable]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON Transform where
  parseJSON :: Value -> Parser Transform
parseJSON =
    String -> (Object -> Parser Transform) -> Value -> Parser Transform
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Transform"
      ( \Object
x ->
          Maybe TransformProcessingConfig
-> Text -> [ExpressionVariable] -> Transform
Transform'
            (Maybe TransformProcessingConfig
 -> Text -> [ExpressionVariable] -> Transform)
-> Parser (Maybe TransformProcessingConfig)
-> Parser (Text -> [ExpressionVariable] -> Transform)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe TransformProcessingConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"processingConfig")
            Parser (Text -> [ExpressionVariable] -> Transform)
-> Parser Text -> Parser ([ExpressionVariable] -> Transform)
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
"expression")
            Parser ([ExpressionVariable] -> Transform)
-> Parser [ExpressionVariable] -> Parser Transform
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [ExpressionVariable])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"variables" Parser (Maybe [ExpressionVariable])
-> [ExpressionVariable] -> Parser [ExpressionVariable]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [ExpressionVariable]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Transform

instance Prelude.NFData Transform

instance Core.ToJSON Transform where
  toJSON :: Transform -> Value
toJSON Transform' {[ExpressionVariable]
Maybe TransformProcessingConfig
Text
variables :: [ExpressionVariable]
expression :: Text
processingConfig :: Maybe TransformProcessingConfig
$sel:variables:Transform' :: Transform -> [ExpressionVariable]
$sel:expression:Transform' :: Transform -> Text
$sel:processingConfig:Transform' :: Transform -> Maybe TransformProcessingConfig
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"processingConfig" Text -> TransformProcessingConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (TransformProcessingConfig -> Pair)
-> Maybe TransformProcessingConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TransformProcessingConfig
processingConfig,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"expression" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
expression),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"variables" Text -> [ExpressionVariable] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [ExpressionVariable]
variables)
          ]
      )