{-# 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.Budgets.Types.Notification
-- 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.Budgets.Types.Notification where

import Amazonka.Budgets.Types.ComparisonOperator
import Amazonka.Budgets.Types.NotificationState
import Amazonka.Budgets.Types.NotificationType
import Amazonka.Budgets.Types.ThresholdType
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

-- | A notification that\'s associated with a budget. A budget can have up to
-- ten notifications.
--
-- Each notification must have at least one subscriber. A notification can
-- have one SNS subscriber and up to 10 email subscribers, for a total of
-- 11 subscribers.
--
-- For example, if you have a budget for 200 dollars and you want to be
-- notified when you go over 160 dollars, create a notification with the
-- following parameters:
--
-- -   A notificationType of @ACTUAL@
--
-- -   A @thresholdType@ of @PERCENTAGE@
--
-- -   A @comparisonOperator@ of @GREATER_THAN@
--
-- -   A notification @threshold@ of @80@
--
-- /See:/ 'newNotification' smart constructor.
data Notification = Notification'
  { -- | Specifies whether this notification is in alarm. If a budget
    -- notification is in the @ALARM@ state, you passed the set threshold for
    -- the budget.
    Notification -> Maybe NotificationState
notificationState :: Prelude.Maybe NotificationState,
    -- | The type of threshold for a notification. For @ABSOLUTE_VALUE@
    -- thresholds, Amazon Web Services notifies you when you go over or are
    -- forecasted to go over your total cost threshold. For @PERCENTAGE@
    -- thresholds, Amazon Web Services notifies you when you go over or are
    -- forecasted to go over a certain percentage of your forecasted spend. For
    -- example, if you have a budget for 200 dollars and you have a
    -- @PERCENTAGE@ threshold of 80%, Amazon Web Services notifies you when you
    -- go over 160 dollars.
    Notification -> Maybe ThresholdType
thresholdType :: Prelude.Maybe ThresholdType,
    -- | Specifies whether the notification is for how much you have spent
    -- (@ACTUAL@) or for how much that you\'re forecasted to spend
    -- (@FORECASTED@).
    Notification -> NotificationType
notificationType :: NotificationType,
    -- | The comparison that\'s used for this notification.
    Notification -> ComparisonOperator
comparisonOperator :: ComparisonOperator,
    -- | The threshold that\'s associated with a notification. Thresholds are
    -- always a percentage, and many customers find value being alerted between
    -- 50% - 200% of the budgeted amount. The maximum limit for your threshold
    -- is 1,000,000% above the budgeted amount.
    Notification -> Double
threshold :: Prelude.Double
  }
  deriving (Notification -> Notification -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Notification -> Notification -> Bool
$c/= :: Notification -> Notification -> Bool
== :: Notification -> Notification -> Bool
$c== :: Notification -> Notification -> Bool
Prelude.Eq, ReadPrec [Notification]
ReadPrec Notification
Int -> ReadS Notification
ReadS [Notification]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Notification]
$creadListPrec :: ReadPrec [Notification]
readPrec :: ReadPrec Notification
$creadPrec :: ReadPrec Notification
readList :: ReadS [Notification]
$creadList :: ReadS [Notification]
readsPrec :: Int -> ReadS Notification
$creadsPrec :: Int -> ReadS Notification
Prelude.Read, Int -> Notification -> ShowS
[Notification] -> ShowS
Notification -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Notification] -> ShowS
$cshowList :: [Notification] -> ShowS
show :: Notification -> String
$cshow :: Notification -> String
showsPrec :: Int -> Notification -> ShowS
$cshowsPrec :: Int -> Notification -> ShowS
Prelude.Show, forall x. Rep Notification x -> Notification
forall x. Notification -> Rep Notification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Notification x -> Notification
$cfrom :: forall x. Notification -> Rep Notification x
Prelude.Generic)

-- |
-- Create a value of 'Notification' 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:
--
-- 'notificationState', 'notification_notificationState' - Specifies whether this notification is in alarm. If a budget
-- notification is in the @ALARM@ state, you passed the set threshold for
-- the budget.
--
-- 'thresholdType', 'notification_thresholdType' - The type of threshold for a notification. For @ABSOLUTE_VALUE@
-- thresholds, Amazon Web Services notifies you when you go over or are
-- forecasted to go over your total cost threshold. For @PERCENTAGE@
-- thresholds, Amazon Web Services notifies you when you go over or are
-- forecasted to go over a certain percentage of your forecasted spend. For
-- example, if you have a budget for 200 dollars and you have a
-- @PERCENTAGE@ threshold of 80%, Amazon Web Services notifies you when you
-- go over 160 dollars.
--
-- 'notificationType', 'notification_notificationType' - Specifies whether the notification is for how much you have spent
-- (@ACTUAL@) or for how much that you\'re forecasted to spend
-- (@FORECASTED@).
--
-- 'comparisonOperator', 'notification_comparisonOperator' - The comparison that\'s used for this notification.
--
-- 'threshold', 'notification_threshold' - The threshold that\'s associated with a notification. Thresholds are
-- always a percentage, and many customers find value being alerted between
-- 50% - 200% of the budgeted amount. The maximum limit for your threshold
-- is 1,000,000% above the budgeted amount.
newNotification ::
  -- | 'notificationType'
  NotificationType ->
  -- | 'comparisonOperator'
  ComparisonOperator ->
  -- | 'threshold'
  Prelude.Double ->
  Notification
newNotification :: NotificationType -> ComparisonOperator -> Double -> Notification
newNotification
  NotificationType
pNotificationType_
  ComparisonOperator
pComparisonOperator_
  Double
pThreshold_ =
    Notification'
      { $sel:notificationState:Notification' :: Maybe NotificationState
notificationState = forall a. Maybe a
Prelude.Nothing,
        $sel:thresholdType:Notification' :: Maybe ThresholdType
thresholdType = forall a. Maybe a
Prelude.Nothing,
        $sel:notificationType:Notification' :: NotificationType
notificationType = NotificationType
pNotificationType_,
        $sel:comparisonOperator:Notification' :: ComparisonOperator
comparisonOperator = ComparisonOperator
pComparisonOperator_,
        $sel:threshold:Notification' :: Double
threshold = Double
pThreshold_
      }

-- | Specifies whether this notification is in alarm. If a budget
-- notification is in the @ALARM@ state, you passed the set threshold for
-- the budget.
notification_notificationState :: Lens.Lens' Notification (Prelude.Maybe NotificationState)
notification_notificationState :: Lens' Notification (Maybe NotificationState)
notification_notificationState = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Notification' {Maybe NotificationState
notificationState :: Maybe NotificationState
$sel:notificationState:Notification' :: Notification -> Maybe NotificationState
notificationState} -> Maybe NotificationState
notificationState) (\s :: Notification
s@Notification' {} Maybe NotificationState
a -> Notification
s {$sel:notificationState:Notification' :: Maybe NotificationState
notificationState = Maybe NotificationState
a} :: Notification)

-- | The type of threshold for a notification. For @ABSOLUTE_VALUE@
-- thresholds, Amazon Web Services notifies you when you go over or are
-- forecasted to go over your total cost threshold. For @PERCENTAGE@
-- thresholds, Amazon Web Services notifies you when you go over or are
-- forecasted to go over a certain percentage of your forecasted spend. For
-- example, if you have a budget for 200 dollars and you have a
-- @PERCENTAGE@ threshold of 80%, Amazon Web Services notifies you when you
-- go over 160 dollars.
notification_thresholdType :: Lens.Lens' Notification (Prelude.Maybe ThresholdType)
notification_thresholdType :: Lens' Notification (Maybe ThresholdType)
notification_thresholdType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Notification' {Maybe ThresholdType
thresholdType :: Maybe ThresholdType
$sel:thresholdType:Notification' :: Notification -> Maybe ThresholdType
thresholdType} -> Maybe ThresholdType
thresholdType) (\s :: Notification
s@Notification' {} Maybe ThresholdType
a -> Notification
s {$sel:thresholdType:Notification' :: Maybe ThresholdType
thresholdType = Maybe ThresholdType
a} :: Notification)

-- | Specifies whether the notification is for how much you have spent
-- (@ACTUAL@) or for how much that you\'re forecasted to spend
-- (@FORECASTED@).
notification_notificationType :: Lens.Lens' Notification NotificationType
notification_notificationType :: Lens' Notification NotificationType
notification_notificationType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Notification' {NotificationType
notificationType :: NotificationType
$sel:notificationType:Notification' :: Notification -> NotificationType
notificationType} -> NotificationType
notificationType) (\s :: Notification
s@Notification' {} NotificationType
a -> Notification
s {$sel:notificationType:Notification' :: NotificationType
notificationType = NotificationType
a} :: Notification)

-- | The comparison that\'s used for this notification.
notification_comparisonOperator :: Lens.Lens' Notification ComparisonOperator
notification_comparisonOperator :: Lens' Notification ComparisonOperator
notification_comparisonOperator = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Notification' {ComparisonOperator
comparisonOperator :: ComparisonOperator
$sel:comparisonOperator:Notification' :: Notification -> ComparisonOperator
comparisonOperator} -> ComparisonOperator
comparisonOperator) (\s :: Notification
s@Notification' {} ComparisonOperator
a -> Notification
s {$sel:comparisonOperator:Notification' :: ComparisonOperator
comparisonOperator = ComparisonOperator
a} :: Notification)

-- | The threshold that\'s associated with a notification. Thresholds are
-- always a percentage, and many customers find value being alerted between
-- 50% - 200% of the budgeted amount. The maximum limit for your threshold
-- is 1,000,000% above the budgeted amount.
notification_threshold :: Lens.Lens' Notification Prelude.Double
notification_threshold :: Lens' Notification Double
notification_threshold = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Notification' {Double
threshold :: Double
$sel:threshold:Notification' :: Notification -> Double
threshold} -> Double
threshold) (\s :: Notification
s@Notification' {} Double
a -> Notification
s {$sel:threshold:Notification' :: Double
threshold = Double
a} :: Notification)

instance Data.FromJSON Notification where
  parseJSON :: Value -> Parser Notification
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Notification"
      ( \Object
x ->
          Maybe NotificationState
-> Maybe ThresholdType
-> NotificationType
-> ComparisonOperator
-> Double
-> Notification
Notification'
            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
"NotificationState")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ThresholdType")
            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
"NotificationType")
            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 Notification where
  hashWithSalt :: Int -> Notification -> Int
hashWithSalt Int
_salt Notification' {Double
Maybe NotificationState
Maybe ThresholdType
ComparisonOperator
NotificationType
threshold :: Double
comparisonOperator :: ComparisonOperator
notificationType :: NotificationType
thresholdType :: Maybe ThresholdType
notificationState :: Maybe NotificationState
$sel:threshold:Notification' :: Notification -> Double
$sel:comparisonOperator:Notification' :: Notification -> ComparisonOperator
$sel:notificationType:Notification' :: Notification -> NotificationType
$sel:thresholdType:Notification' :: Notification -> Maybe ThresholdType
$sel:notificationState:Notification' :: Notification -> Maybe NotificationState
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe NotificationState
notificationState
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ThresholdType
thresholdType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NotificationType
notificationType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ComparisonOperator
comparisonOperator
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Double
threshold

instance Prelude.NFData Notification where
  rnf :: Notification -> ()
rnf Notification' {Double
Maybe NotificationState
Maybe ThresholdType
ComparisonOperator
NotificationType
threshold :: Double
comparisonOperator :: ComparisonOperator
notificationType :: NotificationType
thresholdType :: Maybe ThresholdType
notificationState :: Maybe NotificationState
$sel:threshold:Notification' :: Notification -> Double
$sel:comparisonOperator:Notification' :: Notification -> ComparisonOperator
$sel:notificationType:Notification' :: Notification -> NotificationType
$sel:thresholdType:Notification' :: Notification -> Maybe ThresholdType
$sel:notificationState:Notification' :: Notification -> Maybe NotificationState
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe NotificationState
notificationState
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ThresholdType
thresholdType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NotificationType
notificationType
      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 Double
threshold

instance Data.ToJSON Notification where
  toJSON :: Notification -> Value
toJSON Notification' {Double
Maybe NotificationState
Maybe ThresholdType
ComparisonOperator
NotificationType
threshold :: Double
comparisonOperator :: ComparisonOperator
notificationType :: NotificationType
thresholdType :: Maybe ThresholdType
notificationState :: Maybe NotificationState
$sel:threshold:Notification' :: Notification -> Double
$sel:comparisonOperator:Notification' :: Notification -> ComparisonOperator
$sel:notificationType:Notification' :: Notification -> NotificationType
$sel:thresholdType:Notification' :: Notification -> Maybe ThresholdType
$sel:notificationState:Notification' :: Notification -> Maybe NotificationState
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"NotificationState" 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 NotificationState
notificationState,
            (Key
"ThresholdType" 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 ThresholdType
thresholdType,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"NotificationType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NotificationType
notificationType),
            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..= Double
threshold)
          ]
      )