{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoTAnalytics.Types.MathActivity 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

-- | 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
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]
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
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. 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'
    { $sel:next:MathActivity' :: Maybe Text
next = 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 :: Lens' MathActivity (Maybe Text)
mathActivity_next = 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 :: Lens' MathActivity Text
mathActivity_name = 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 :: Lens' MathActivity Text
mathActivity_attribute = 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 :: Lens' MathActivity Text
mathActivity_math = 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 Data.FromJSON MathActivity where
  parseJSON :: Value -> Parser MathActivity
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MathActivity"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> Text -> MathActivity
MathActivity'
            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
"next")
            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
"name")
            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
"attribute")
            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
"math")
      )

instance Prelude.Hashable MathActivity where
  hashWithSalt :: Int -> MathActivity -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
next
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
attribute
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
math

instance Prelude.NFData MathActivity where
  rnf :: MathActivity -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
next
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
attribute
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
math

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"next" 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
next,
            forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"attribute" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
attribute),
            forall a. a -> Maybe a
Prelude.Just (Key
"math" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
math)
          ]
      )