{-# 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-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.AlarmRule where

import qualified Amazonka.Core as Core
import Amazonka.IoTEvents.Types.SimpleRule
import qualified Amazonka.Lens as Lens
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
(AlarmRule -> AlarmRule -> Bool)
-> (AlarmRule -> AlarmRule -> Bool) -> Eq AlarmRule
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]
(Int -> ReadS AlarmRule)
-> ReadS [AlarmRule]
-> ReadPrec AlarmRule
-> ReadPrec [AlarmRule]
-> Read 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
(Int -> AlarmRule -> ShowS)
-> (AlarmRule -> String)
-> ([AlarmRule] -> ShowS)
-> Show AlarmRule
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. AlarmRule -> Rep AlarmRule x)
-> (forall x. Rep AlarmRule x -> AlarmRule) -> Generic AlarmRule
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' :: Maybe SimpleRule -> AlarmRule
AlarmRule' {$sel:simpleRule:AlarmRule' :: Maybe SimpleRule
simpleRule = Maybe 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 :: (Maybe SimpleRule -> f (Maybe SimpleRule))
-> AlarmRule -> f AlarmRule
alarmRule_simpleRule = (AlarmRule -> Maybe SimpleRule)
-> (AlarmRule -> Maybe SimpleRule -> AlarmRule)
-> Lens AlarmRule AlarmRule (Maybe SimpleRule) (Maybe 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 Core.FromJSON AlarmRule where
  parseJSON :: Value -> Parser AlarmRule
parseJSON =
    String -> (Object -> Parser AlarmRule) -> Value -> Parser AlarmRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AlarmRule"
      ( \Object
x ->
          Maybe SimpleRule -> AlarmRule
AlarmRule' (Maybe SimpleRule -> AlarmRule)
-> Parser (Maybe SimpleRule) -> Parser AlarmRule
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe SimpleRule)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"simpleRule")
      )

instance Prelude.Hashable AlarmRule

instance Prelude.NFData AlarmRule

instance Core.ToJSON AlarmRule where
  toJSON :: AlarmRule -> Value
toJSON AlarmRule' {Maybe SimpleRule
simpleRule :: Maybe SimpleRule
$sel:simpleRule:AlarmRule' :: AlarmRule -> Maybe SimpleRule
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"simpleRule" Text -> SimpleRule -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SimpleRule -> Pair) -> Maybe SimpleRule -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SimpleRule
simpleRule]
      )