{-# 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.IoTEvents.Types.SimpleRule
-- 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.IoTEvents.Types.SimpleRule where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoTEvents.Types.ComparisonOperator
import qualified Amazonka.Prelude as Prelude

-- | A rule that compares an input property value to a threshold value with a
-- comparison operator.
--
-- /See:/ 'newSimpleRule' smart constructor.
data SimpleRule = SimpleRule'
  { -- | The value on the left side of the comparison operator. You can specify
    -- an AWS IoT Events input attribute as an input property.
    SimpleRule -> Text
inputProperty :: Prelude.Text,
    -- | The comparison operator.
    SimpleRule -> ComparisonOperator
comparisonOperator :: ComparisonOperator,
    -- | The value on the right side of the comparison operator. You can enter a
    -- number or specify an AWS IoT Events input attribute.
    SimpleRule -> Text
threshold :: Prelude.Text
  }
  deriving (SimpleRule -> SimpleRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SimpleRule -> SimpleRule -> Bool
$c/= :: SimpleRule -> SimpleRule -> Bool
== :: SimpleRule -> SimpleRule -> Bool
$c== :: SimpleRule -> SimpleRule -> Bool
Prelude.Eq, ReadPrec [SimpleRule]
ReadPrec SimpleRule
Int -> ReadS SimpleRule
ReadS [SimpleRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SimpleRule]
$creadListPrec :: ReadPrec [SimpleRule]
readPrec :: ReadPrec SimpleRule
$creadPrec :: ReadPrec SimpleRule
readList :: ReadS [SimpleRule]
$creadList :: ReadS [SimpleRule]
readsPrec :: Int -> ReadS SimpleRule
$creadsPrec :: Int -> ReadS SimpleRule
Prelude.Read, Int -> SimpleRule -> ShowS
[SimpleRule] -> ShowS
SimpleRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SimpleRule] -> ShowS
$cshowList :: [SimpleRule] -> ShowS
show :: SimpleRule -> String
$cshow :: SimpleRule -> String
showsPrec :: Int -> SimpleRule -> ShowS
$cshowsPrec :: Int -> SimpleRule -> ShowS
Prelude.Show, forall x. Rep SimpleRule x -> SimpleRule
forall x. SimpleRule -> Rep SimpleRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SimpleRule x -> SimpleRule
$cfrom :: forall x. SimpleRule -> Rep SimpleRule x
Prelude.Generic)

-- |
-- Create a value of 'SimpleRule' 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:
--
-- 'inputProperty', 'simpleRule_inputProperty' - The value on the left side of the comparison operator. You can specify
-- an AWS IoT Events input attribute as an input property.
--
-- 'comparisonOperator', 'simpleRule_comparisonOperator' - The comparison operator.
--
-- 'threshold', 'simpleRule_threshold' - The value on the right side of the comparison operator. You can enter a
-- number or specify an AWS IoT Events input attribute.
newSimpleRule ::
  -- | 'inputProperty'
  Prelude.Text ->
  -- | 'comparisonOperator'
  ComparisonOperator ->
  -- | 'threshold'
  Prelude.Text ->
  SimpleRule
newSimpleRule :: Text -> ComparisonOperator -> Text -> SimpleRule
newSimpleRule
  Text
pInputProperty_
  ComparisonOperator
pComparisonOperator_
  Text
pThreshold_ =
    SimpleRule'
      { $sel:inputProperty:SimpleRule' :: Text
inputProperty = Text
pInputProperty_,
        $sel:comparisonOperator:SimpleRule' :: ComparisonOperator
comparisonOperator = ComparisonOperator
pComparisonOperator_,
        $sel:threshold:SimpleRule' :: Text
threshold = Text
pThreshold_
      }

-- | The value on the left side of the comparison operator. You can specify
-- an AWS IoT Events input attribute as an input property.
simpleRule_inputProperty :: Lens.Lens' SimpleRule Prelude.Text
simpleRule_inputProperty :: Lens' SimpleRule Text
simpleRule_inputProperty = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SimpleRule' {Text
inputProperty :: Text
$sel:inputProperty:SimpleRule' :: SimpleRule -> Text
inputProperty} -> Text
inputProperty) (\s :: SimpleRule
s@SimpleRule' {} Text
a -> SimpleRule
s {$sel:inputProperty:SimpleRule' :: Text
inputProperty = Text
a} :: SimpleRule)

-- | The comparison operator.
simpleRule_comparisonOperator :: Lens.Lens' SimpleRule ComparisonOperator
simpleRule_comparisonOperator :: Lens' SimpleRule ComparisonOperator
simpleRule_comparisonOperator = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SimpleRule' {ComparisonOperator
comparisonOperator :: ComparisonOperator
$sel:comparisonOperator:SimpleRule' :: SimpleRule -> ComparisonOperator
comparisonOperator} -> ComparisonOperator
comparisonOperator) (\s :: SimpleRule
s@SimpleRule' {} ComparisonOperator
a -> SimpleRule
s {$sel:comparisonOperator:SimpleRule' :: ComparisonOperator
comparisonOperator = ComparisonOperator
a} :: SimpleRule)

-- | The value on the right side of the comparison operator. You can enter a
-- number or specify an AWS IoT Events input attribute.
simpleRule_threshold :: Lens.Lens' SimpleRule Prelude.Text
simpleRule_threshold :: Lens' SimpleRule Text
simpleRule_threshold = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SimpleRule' {Text
threshold :: Text
$sel:threshold:SimpleRule' :: SimpleRule -> Text
threshold} -> Text
threshold) (\s :: SimpleRule
s@SimpleRule' {} Text
a -> SimpleRule
s {$sel:threshold:SimpleRule' :: Text
threshold = Text
a} :: SimpleRule)

instance Data.FromJSON SimpleRule where
  parseJSON :: Value -> Parser SimpleRule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SimpleRule"
      ( \Object
x ->
          Text -> ComparisonOperator -> Text -> SimpleRule
SimpleRule'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"inputProperty")
            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
"comparisonOperator")
            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
"threshold")
      )

instance Prelude.Hashable SimpleRule where
  hashWithSalt :: Int -> SimpleRule -> Int
hashWithSalt Int
_salt SimpleRule' {Text
ComparisonOperator
threshold :: Text
comparisonOperator :: ComparisonOperator
inputProperty :: Text
$sel:threshold:SimpleRule' :: SimpleRule -> Text
$sel:comparisonOperator:SimpleRule' :: SimpleRule -> ComparisonOperator
$sel:inputProperty:SimpleRule' :: SimpleRule -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
inputProperty
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ComparisonOperator
comparisonOperator
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
threshold

instance Prelude.NFData SimpleRule where
  rnf :: SimpleRule -> ()
rnf SimpleRule' {Text
ComparisonOperator
threshold :: Text
comparisonOperator :: ComparisonOperator
inputProperty :: Text
$sel:threshold:SimpleRule' :: SimpleRule -> Text
$sel:comparisonOperator:SimpleRule' :: SimpleRule -> ComparisonOperator
$sel:inputProperty:SimpleRule' :: SimpleRule -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
inputProperty
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ComparisonOperator
comparisonOperator
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
threshold

instance Data.ToJSON SimpleRule where
  toJSON :: SimpleRule -> Value
toJSON SimpleRule' {Text
ComparisonOperator
threshold :: Text
comparisonOperator :: ComparisonOperator
inputProperty :: Text
$sel:threshold:SimpleRule' :: SimpleRule -> Text
$sel:comparisonOperator:SimpleRule' :: SimpleRule -> ComparisonOperator
$sel:inputProperty:SimpleRule' :: SimpleRule -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"inputProperty" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
inputProperty),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"comparisonOperator" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ComparisonOperator
comparisonOperator),
            forall a. a -> Maybe a
Prelude.Just (Key
"threshold" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
threshold)
          ]
      )