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

-- | A notification that is 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'
  { -- | The type of threshold for a notification. For @ABSOLUTE_VALUE@
    -- thresholds, AWS notifies you when you go over or are forecasted to go
    -- over your total cost threshold. For @PERCENTAGE@ thresholds, AWS
    -- 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%, AWS
    -- notifies you when you go over 160 dollars.
    Notification -> Maybe ThresholdType
thresholdType :: Prelude.Maybe ThresholdType,
    -- | Whether this notification is in alarm. If a budget notification is in
    -- the @ALARM@ state, you have passed the set threshold for the budget.
    Notification -> Maybe NotificationState
notificationState :: Prelude.Maybe NotificationState,
    -- | Whether the notification is for how much you have spent (@ACTUAL@) or
    -- for how much you\'re forecasted to spend (@FORECASTED@).
    Notification -> NotificationType
notificationType :: NotificationType,
    -- | The comparison that is used for this notification.
    Notification -> ComparisonOperator
comparisonOperator :: ComparisonOperator,
    -- | The threshold that is 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
(Notification -> Notification -> Bool)
-> (Notification -> Notification -> Bool) -> Eq Notification
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]
(Int -> ReadS Notification)
-> ReadS [Notification]
-> ReadPrec Notification
-> ReadPrec [Notification]
-> Read 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
(Int -> Notification -> ShowS)
-> (Notification -> String)
-> ([Notification] -> ShowS)
-> Show Notification
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. Notification -> Rep Notification x)
-> (forall x. Rep Notification x -> Notification)
-> Generic Notification
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:
--
-- 'thresholdType', 'notification_thresholdType' - The type of threshold for a notification. For @ABSOLUTE_VALUE@
-- thresholds, AWS notifies you when you go over or are forecasted to go
-- over your total cost threshold. For @PERCENTAGE@ thresholds, AWS
-- 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%, AWS
-- notifies you when you go over 160 dollars.
--
-- 'notificationState', 'notification_notificationState' - Whether this notification is in alarm. If a budget notification is in
-- the @ALARM@ state, you have passed the set threshold for the budget.
--
-- 'notificationType', 'notification_notificationType' - Whether the notification is for how much you have spent (@ACTUAL@) or
-- for how much you\'re forecasted to spend (@FORECASTED@).
--
-- 'comparisonOperator', 'notification_comparisonOperator' - The comparison that is used for this notification.
--
-- 'threshold', 'notification_threshold' - The threshold that is 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' :: Maybe ThresholdType
-> Maybe NotificationState
-> NotificationType
-> ComparisonOperator
-> Double
-> Notification
Notification'
      { $sel:thresholdType:Notification' :: Maybe ThresholdType
thresholdType = Maybe ThresholdType
forall a. Maybe a
Prelude.Nothing,
        $sel:notificationState:Notification' :: Maybe NotificationState
notificationState = Maybe NotificationState
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_
      }

-- | The type of threshold for a notification. For @ABSOLUTE_VALUE@
-- thresholds, AWS notifies you when you go over or are forecasted to go
-- over your total cost threshold. For @PERCENTAGE@ thresholds, AWS
-- 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%, AWS
-- notifies you when you go over 160 dollars.
notification_thresholdType :: Lens.Lens' Notification (Prelude.Maybe ThresholdType)
notification_thresholdType :: (Maybe ThresholdType -> f (Maybe ThresholdType))
-> Notification -> f Notification
notification_thresholdType = (Notification -> Maybe ThresholdType)
-> (Notification -> Maybe ThresholdType -> Notification)
-> Lens
     Notification
     Notification
     (Maybe ThresholdType)
     (Maybe 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)

-- | Whether this notification is in alarm. If a budget notification is in
-- the @ALARM@ state, you have passed the set threshold for the budget.
notification_notificationState :: Lens.Lens' Notification (Prelude.Maybe NotificationState)
notification_notificationState :: (Maybe NotificationState -> f (Maybe NotificationState))
-> Notification -> f Notification
notification_notificationState = (Notification -> Maybe NotificationState)
-> (Notification -> Maybe NotificationState -> Notification)
-> Lens
     Notification
     Notification
     (Maybe NotificationState)
     (Maybe 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)

-- | Whether the notification is for how much you have spent (@ACTUAL@) or
-- for how much you\'re forecasted to spend (@FORECASTED@).
notification_notificationType :: Lens.Lens' Notification NotificationType
notification_notificationType :: (NotificationType -> f NotificationType)
-> Notification -> f Notification
notification_notificationType = (Notification -> NotificationType)
-> (Notification -> NotificationType -> Notification)
-> Lens Notification Notification NotificationType 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 is used for this notification.
notification_comparisonOperator :: Lens.Lens' Notification ComparisonOperator
notification_comparisonOperator :: (ComparisonOperator -> f ComparisonOperator)
-> Notification -> f Notification
notification_comparisonOperator = (Notification -> ComparisonOperator)
-> (Notification -> ComparisonOperator -> Notification)
-> Lens
     Notification Notification ComparisonOperator 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 is 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 :: (Double -> f Double) -> Notification -> f Notification
notification_threshold = (Notification -> Double)
-> (Notification -> Double -> Notification)
-> Lens Notification Notification Double Double
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 Core.FromJSON Notification where
  parseJSON :: Value -> Parser Notification
parseJSON =
    String
-> (Object -> Parser Notification) -> Value -> Parser Notification
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Notification"
      ( \Object
x ->
          Maybe ThresholdType
-> Maybe NotificationState
-> NotificationType
-> ComparisonOperator
-> Double
-> Notification
Notification'
            (Maybe ThresholdType
 -> Maybe NotificationState
 -> NotificationType
 -> ComparisonOperator
 -> Double
 -> Notification)
-> Parser (Maybe ThresholdType)
-> Parser
     (Maybe NotificationState
      -> NotificationType
      -> ComparisonOperator
      -> Double
      -> Notification)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ThresholdType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ThresholdType")
            Parser
  (Maybe NotificationState
   -> NotificationType
   -> ComparisonOperator
   -> Double
   -> Notification)
-> Parser (Maybe NotificationState)
-> Parser
     (NotificationType -> ComparisonOperator -> Double -> Notification)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe NotificationState)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"NotificationState")
            Parser
  (NotificationType -> ComparisonOperator -> Double -> Notification)
-> Parser NotificationType
-> Parser (ComparisonOperator -> Double -> Notification)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser NotificationType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"NotificationType")
            Parser (ComparisonOperator -> Double -> Notification)
-> Parser ComparisonOperator -> Parser (Double -> Notification)
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 (Double -> Notification)
-> Parser Double -> Parser Notification
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Double
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Threshold")
      )

instance Prelude.Hashable Notification

instance Prelude.NFData Notification

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