{-# 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.IoTAnalytics.Types.MathActivity
-- 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.IoTAnalytics.Types.MathActivity where

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

-- | An activity that computes an arithmetic expression using the message\'s
-- attributes.
--
-- /See:/ 'newMathActivity' smart constructor.
data MathActivity = MathActivity'
  { -- | The next activity in the pipeline.
    MathActivity -> Maybe Text
next :: Prelude.Maybe Prelude.Text,
    -- | The name of the math activity.
    MathActivity -> Text
name :: Prelude.Text,
    -- | The name of the attribute that contains the result of the math
    -- operation.
    MathActivity -> Text
attribute :: Prelude.Text,
    -- | An expression that uses one or more existing attributes and must return
    -- an integer value.
    MathActivity -> Text
math :: Prelude.Text
  }
  deriving (MathActivity -> MathActivity -> Bool
(MathActivity -> MathActivity -> Bool)
-> (MathActivity -> MathActivity -> Bool) -> Eq MathActivity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MathActivity -> MathActivity -> Bool
$c/= :: MathActivity -> MathActivity -> Bool
== :: MathActivity -> MathActivity -> Bool
$c== :: MathActivity -> MathActivity -> Bool
Prelude.Eq, ReadPrec [MathActivity]
ReadPrec MathActivity
Int -> ReadS MathActivity
ReadS [MathActivity]
(Int -> ReadS MathActivity)
-> ReadS [MathActivity]
-> ReadPrec MathActivity
-> ReadPrec [MathActivity]
-> Read MathActivity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MathActivity]
$creadListPrec :: ReadPrec [MathActivity]
readPrec :: ReadPrec MathActivity
$creadPrec :: ReadPrec MathActivity
readList :: ReadS [MathActivity]
$creadList :: ReadS [MathActivity]
readsPrec :: Int -> ReadS MathActivity
$creadsPrec :: Int -> ReadS MathActivity
Prelude.Read, Int -> MathActivity -> ShowS
[MathActivity] -> ShowS
MathActivity -> String
(Int -> MathActivity -> ShowS)
-> (MathActivity -> String)
-> ([MathActivity] -> ShowS)
-> Show MathActivity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MathActivity] -> ShowS
$cshowList :: [MathActivity] -> ShowS
show :: MathActivity -> String
$cshow :: MathActivity -> String
showsPrec :: Int -> MathActivity -> ShowS
$cshowsPrec :: Int -> MathActivity -> ShowS
Prelude.Show, (forall x. MathActivity -> Rep MathActivity x)
-> (forall x. Rep MathActivity x -> MathActivity)
-> Generic MathActivity
forall x. Rep MathActivity x -> MathActivity
forall x. MathActivity -> Rep MathActivity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MathActivity x -> MathActivity
$cfrom :: forall x. MathActivity -> Rep MathActivity x
Prelude.Generic)

-- |
-- Create a value of 'MathActivity' 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:
--
-- 'next', 'mathActivity_next' - The next activity in the pipeline.
--
-- 'name', 'mathActivity_name' - The name of the math activity.
--
-- 'attribute', 'mathActivity_attribute' - The name of the attribute that contains the result of the math
-- operation.
--
-- 'math', 'mathActivity_math' - An expression that uses one or more existing attributes and must return
-- an integer value.
newMathActivity ::
  -- | 'name'
  Prelude.Text ->
  -- | 'attribute'
  Prelude.Text ->
  -- | 'math'
  Prelude.Text ->
  MathActivity
newMathActivity :: Text -> Text -> Text -> MathActivity
newMathActivity Text
pName_ Text
pAttribute_ Text
pMath_ =
  MathActivity' :: Maybe Text -> Text -> Text -> Text -> MathActivity
MathActivity'
    { $sel:next:MathActivity' :: Maybe Text
next = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:MathActivity' :: Text
name = Text
pName_,
      $sel:attribute:MathActivity' :: Text
attribute = Text
pAttribute_,
      $sel:math:MathActivity' :: Text
math = Text
pMath_
    }

-- | The next activity in the pipeline.
mathActivity_next :: Lens.Lens' MathActivity (Prelude.Maybe Prelude.Text)
mathActivity_next :: (Maybe Text -> f (Maybe Text)) -> MathActivity -> f MathActivity
mathActivity_next = (MathActivity -> Maybe Text)
-> (MathActivity -> Maybe Text -> MathActivity)
-> Lens MathActivity MathActivity (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MathActivity' {Maybe Text
next :: Maybe Text
$sel:next:MathActivity' :: MathActivity -> Maybe Text
next} -> Maybe Text
next) (\s :: MathActivity
s@MathActivity' {} Maybe Text
a -> MathActivity
s {$sel:next:MathActivity' :: Maybe Text
next = Maybe Text
a} :: MathActivity)

-- | The name of the math activity.
mathActivity_name :: Lens.Lens' MathActivity Prelude.Text
mathActivity_name :: (Text -> f Text) -> MathActivity -> f MathActivity
mathActivity_name = (MathActivity -> Text)
-> (MathActivity -> Text -> MathActivity)
-> Lens MathActivity MathActivity Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MathActivity' {Text
name :: Text
$sel:name:MathActivity' :: MathActivity -> Text
name} -> Text
name) (\s :: MathActivity
s@MathActivity' {} Text
a -> MathActivity
s {$sel:name:MathActivity' :: Text
name = Text
a} :: MathActivity)

-- | The name of the attribute that contains the result of the math
-- operation.
mathActivity_attribute :: Lens.Lens' MathActivity Prelude.Text
mathActivity_attribute :: (Text -> f Text) -> MathActivity -> f MathActivity
mathActivity_attribute = (MathActivity -> Text)
-> (MathActivity -> Text -> MathActivity)
-> Lens MathActivity MathActivity Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MathActivity' {Text
attribute :: Text
$sel:attribute:MathActivity' :: MathActivity -> Text
attribute} -> Text
attribute) (\s :: MathActivity
s@MathActivity' {} Text
a -> MathActivity
s {$sel:attribute:MathActivity' :: Text
attribute = Text
a} :: MathActivity)

-- | An expression that uses one or more existing attributes and must return
-- an integer value.
mathActivity_math :: Lens.Lens' MathActivity Prelude.Text
mathActivity_math :: (Text -> f Text) -> MathActivity -> f MathActivity
mathActivity_math = (MathActivity -> Text)
-> (MathActivity -> Text -> MathActivity)
-> Lens MathActivity MathActivity Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MathActivity' {Text
math :: Text
$sel:math:MathActivity' :: MathActivity -> Text
math} -> Text
math) (\s :: MathActivity
s@MathActivity' {} Text
a -> MathActivity
s {$sel:math:MathActivity' :: Text
math = Text
a} :: MathActivity)

instance Core.FromJSON MathActivity where
  parseJSON :: Value -> Parser MathActivity
parseJSON =
    String
-> (Object -> Parser MathActivity) -> Value -> Parser MathActivity
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"MathActivity"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> Text -> MathActivity
MathActivity'
            (Maybe Text -> Text -> Text -> Text -> MathActivity)
-> Parser (Maybe Text)
-> Parser (Text -> Text -> Text -> MathActivity)
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
"next")
            Parser (Text -> Text -> Text -> MathActivity)
-> Parser Text -> Parser (Text -> Text -> MathActivity)
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
"name")
            Parser (Text -> Text -> MathActivity)
-> Parser Text -> Parser (Text -> MathActivity)
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
"attribute")
            Parser (Text -> MathActivity) -> Parser Text -> Parser MathActivity
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
"math")
      )

instance Prelude.Hashable MathActivity

instance Prelude.NFData MathActivity

instance Core.ToJSON MathActivity where
  toJSON :: MathActivity -> Value
toJSON MathActivity' {Maybe Text
Text
math :: Text
attribute :: Text
name :: Text
next :: Maybe Text
$sel:math:MathActivity' :: MathActivity -> Text
$sel:attribute:MathActivity' :: MathActivity -> Text
$sel:name:MathActivity' :: MathActivity -> Text
$sel:next:MathActivity' :: MathActivity -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"next" 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
next,
            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
"attribute" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
attribute),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"math" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
math)
          ]
      )