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

import qualified Amazonka.Core as Core
import Amazonka.IoTEvents.Types.ComparisonOperator
import qualified Amazonka.Lens as Lens
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
(SimpleRule -> SimpleRule -> Bool)
-> (SimpleRule -> SimpleRule -> Bool) -> Eq SimpleRule
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]
(Int -> ReadS SimpleRule)
-> ReadS [SimpleRule]
-> ReadPrec SimpleRule
-> ReadPrec [SimpleRule]
-> Read 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
(Int -> SimpleRule -> ShowS)
-> (SimpleRule -> String)
-> ([SimpleRule] -> ShowS)
-> Show SimpleRule
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. SimpleRule -> Rep SimpleRule x)
-> (forall x. Rep SimpleRule x -> SimpleRule) -> Generic SimpleRule
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' :: Text -> ComparisonOperator -> Text -> SimpleRule
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 :: (Text -> f Text) -> SimpleRule -> f SimpleRule
simpleRule_inputProperty = (SimpleRule -> Text)
-> (SimpleRule -> Text -> SimpleRule)
-> Lens SimpleRule SimpleRule Text Text
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 :: (ComparisonOperator -> f ComparisonOperator)
-> SimpleRule -> f SimpleRule
simpleRule_comparisonOperator = (SimpleRule -> ComparisonOperator)
-> (SimpleRule -> ComparisonOperator -> SimpleRule)
-> Lens SimpleRule SimpleRule ComparisonOperator 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 :: (Text -> f Text) -> SimpleRule -> f SimpleRule
simpleRule_threshold = (SimpleRule -> Text)
-> (SimpleRule -> Text -> SimpleRule)
-> Lens SimpleRule SimpleRule Text Text
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 Core.FromJSON SimpleRule where
  parseJSON :: Value -> Parser SimpleRule
parseJSON =
    String
-> (Object -> Parser SimpleRule) -> Value -> Parser SimpleRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SimpleRule"
      ( \Object
x ->
          Text -> ComparisonOperator -> Text -> SimpleRule
SimpleRule'
            (Text -> ComparisonOperator -> Text -> SimpleRule)
-> Parser Text -> Parser (ComparisonOperator -> Text -> SimpleRule)
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
"inputProperty")
            Parser (ComparisonOperator -> Text -> SimpleRule)
-> Parser ComparisonOperator -> Parser (Text -> SimpleRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ComparisonOperator
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"comparisonOperator")
            Parser (Text -> SimpleRule) -> Parser Text -> Parser SimpleRule
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
"threshold")
      )

instance Prelude.Hashable SimpleRule

instance Prelude.NFData SimpleRule

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"inputProperty" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
inputProperty),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"comparisonOperator" Text -> ComparisonOperator -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ComparisonOperator
comparisonOperator),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"threshold" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
threshold)
          ]
      )