{-# 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.AlarmRule
-- 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.AlarmRule 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.SimpleRule
import qualified Amazonka.Prelude as Prelude

-- | Defines when your alarm is invoked.
--
-- /See:/ 'newAlarmRule' smart constructor.
data AlarmRule = AlarmRule'
  { -- | A rule that compares an input property value to a threshold value with a
    -- comparison operator.
    AlarmRule -> Maybe SimpleRule
simpleRule :: Prelude.Maybe SimpleRule
  }
  deriving (AlarmRule -> AlarmRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AlarmRule -> AlarmRule -> Bool
$c/= :: AlarmRule -> AlarmRule -> Bool
== :: AlarmRule -> AlarmRule -> Bool
$c== :: AlarmRule -> AlarmRule -> Bool
Prelude.Eq, ReadPrec [AlarmRule]
ReadPrec AlarmRule
Int -> ReadS AlarmRule
ReadS [AlarmRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AlarmRule]
$creadListPrec :: ReadPrec [AlarmRule]
readPrec :: ReadPrec AlarmRule
$creadPrec :: ReadPrec AlarmRule
readList :: ReadS [AlarmRule]
$creadList :: ReadS [AlarmRule]
readsPrec :: Int -> ReadS AlarmRule
$creadsPrec :: Int -> ReadS AlarmRule
Prelude.Read, Int -> AlarmRule -> ShowS
[AlarmRule] -> ShowS
AlarmRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AlarmRule] -> ShowS
$cshowList :: [AlarmRule] -> ShowS
show :: AlarmRule -> String
$cshow :: AlarmRule -> String
showsPrec :: Int -> AlarmRule -> ShowS
$cshowsPrec :: Int -> AlarmRule -> ShowS
Prelude.Show, forall x. Rep AlarmRule x -> AlarmRule
forall x. AlarmRule -> Rep AlarmRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AlarmRule x -> AlarmRule
$cfrom :: forall x. AlarmRule -> Rep AlarmRule x
Prelude.Generic)

-- |
-- Create a value of 'AlarmRule' 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:
--
-- 'simpleRule', 'alarmRule_simpleRule' - A rule that compares an input property value to a threshold value with a
-- comparison operator.
newAlarmRule ::
  AlarmRule
newAlarmRule :: AlarmRule
newAlarmRule =
  AlarmRule' {$sel:simpleRule:AlarmRule' :: Maybe SimpleRule
simpleRule = forall a. Maybe a
Prelude.Nothing}

-- | A rule that compares an input property value to a threshold value with a
-- comparison operator.
alarmRule_simpleRule :: Lens.Lens' AlarmRule (Prelude.Maybe SimpleRule)
alarmRule_simpleRule :: Lens' AlarmRule (Maybe SimpleRule)
alarmRule_simpleRule = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AlarmRule' {Maybe SimpleRule
simpleRule :: Maybe SimpleRule
$sel:simpleRule:AlarmRule' :: AlarmRule -> Maybe SimpleRule
simpleRule} -> Maybe SimpleRule
simpleRule) (\s :: AlarmRule
s@AlarmRule' {} Maybe SimpleRule
a -> AlarmRule
s {$sel:simpleRule:AlarmRule' :: Maybe SimpleRule
simpleRule = Maybe SimpleRule
a} :: AlarmRule)

instance Data.FromJSON AlarmRule where
  parseJSON :: Value -> Parser AlarmRule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AlarmRule"
      ( \Object
x ->
          Maybe SimpleRule -> AlarmRule
AlarmRule' 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
"simpleRule")
      )

instance Prelude.Hashable AlarmRule where
  hashWithSalt :: Int -> AlarmRule -> Int
hashWithSalt Int
_salt AlarmRule' {Maybe SimpleRule
simpleRule :: Maybe SimpleRule
$sel:simpleRule:AlarmRule' :: AlarmRule -> Maybe SimpleRule
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe SimpleRule
simpleRule

instance Prelude.NFData AlarmRule where
  rnf :: AlarmRule -> ()
rnf AlarmRule' {Maybe SimpleRule
simpleRule :: Maybe SimpleRule
$sel:simpleRule:AlarmRule' :: AlarmRule -> Maybe SimpleRule
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe SimpleRule
simpleRule

instance Data.ToJSON AlarmRule where
  toJSON :: AlarmRule -> Value
toJSON AlarmRule' {Maybe SimpleRule
simpleRule :: Maybe SimpleRule
$sel:simpleRule:AlarmRule' :: AlarmRule -> Maybe SimpleRule
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"simpleRule" 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 SimpleRule
simpleRule]
      )