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

import Amazonka.Budgets.Types.ThresholdType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The trigger threshold of the action.
--
-- /See:/ 'newActionThreshold' smart constructor.
data ActionThreshold = ActionThreshold'
  { ActionThreshold -> Double
actionThresholdValue :: Prelude.Double,
    ActionThreshold -> ThresholdType
actionThresholdType :: ThresholdType
  }
  deriving (ActionThreshold -> ActionThreshold -> Bool
(ActionThreshold -> ActionThreshold -> Bool)
-> (ActionThreshold -> ActionThreshold -> Bool)
-> Eq ActionThreshold
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ActionThreshold -> ActionThreshold -> Bool
$c/= :: ActionThreshold -> ActionThreshold -> Bool
== :: ActionThreshold -> ActionThreshold -> Bool
$c== :: ActionThreshold -> ActionThreshold -> Bool
Prelude.Eq, ReadPrec [ActionThreshold]
ReadPrec ActionThreshold
Int -> ReadS ActionThreshold
ReadS [ActionThreshold]
(Int -> ReadS ActionThreshold)
-> ReadS [ActionThreshold]
-> ReadPrec ActionThreshold
-> ReadPrec [ActionThreshold]
-> Read ActionThreshold
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ActionThreshold]
$creadListPrec :: ReadPrec [ActionThreshold]
readPrec :: ReadPrec ActionThreshold
$creadPrec :: ReadPrec ActionThreshold
readList :: ReadS [ActionThreshold]
$creadList :: ReadS [ActionThreshold]
readsPrec :: Int -> ReadS ActionThreshold
$creadsPrec :: Int -> ReadS ActionThreshold
Prelude.Read, Int -> ActionThreshold -> ShowS
[ActionThreshold] -> ShowS
ActionThreshold -> String
(Int -> ActionThreshold -> ShowS)
-> (ActionThreshold -> String)
-> ([ActionThreshold] -> ShowS)
-> Show ActionThreshold
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ActionThreshold] -> ShowS
$cshowList :: [ActionThreshold] -> ShowS
show :: ActionThreshold -> String
$cshow :: ActionThreshold -> String
showsPrec :: Int -> ActionThreshold -> ShowS
$cshowsPrec :: Int -> ActionThreshold -> ShowS
Prelude.Show, (forall x. ActionThreshold -> Rep ActionThreshold x)
-> (forall x. Rep ActionThreshold x -> ActionThreshold)
-> Generic ActionThreshold
forall x. Rep ActionThreshold x -> ActionThreshold
forall x. ActionThreshold -> Rep ActionThreshold x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ActionThreshold x -> ActionThreshold
$cfrom :: forall x. ActionThreshold -> Rep ActionThreshold x
Prelude.Generic)

-- |
-- Create a value of 'ActionThreshold' 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:
--
-- 'actionThresholdValue', 'actionThreshold_actionThresholdValue' - Undocumented member.
--
-- 'actionThresholdType', 'actionThreshold_actionThresholdType' - Undocumented member.
newActionThreshold ::
  -- | 'actionThresholdValue'
  Prelude.Double ->
  -- | 'actionThresholdType'
  ThresholdType ->
  ActionThreshold
newActionThreshold :: Double -> ThresholdType -> ActionThreshold
newActionThreshold
  Double
pActionThresholdValue_
  ThresholdType
pActionThresholdType_ =
    ActionThreshold' :: Double -> ThresholdType -> ActionThreshold
ActionThreshold'
      { $sel:actionThresholdValue:ActionThreshold' :: Double
actionThresholdValue =
          Double
pActionThresholdValue_,
        $sel:actionThresholdType:ActionThreshold' :: ThresholdType
actionThresholdType = ThresholdType
pActionThresholdType_
      }

-- | Undocumented member.
actionThreshold_actionThresholdValue :: Lens.Lens' ActionThreshold Prelude.Double
actionThreshold_actionThresholdValue :: (Double -> f Double) -> ActionThreshold -> f ActionThreshold
actionThreshold_actionThresholdValue = (ActionThreshold -> Double)
-> (ActionThreshold -> Double -> ActionThreshold)
-> Lens ActionThreshold ActionThreshold Double Double
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ActionThreshold' {Double
actionThresholdValue :: Double
$sel:actionThresholdValue:ActionThreshold' :: ActionThreshold -> Double
actionThresholdValue} -> Double
actionThresholdValue) (\s :: ActionThreshold
s@ActionThreshold' {} Double
a -> ActionThreshold
s {$sel:actionThresholdValue:ActionThreshold' :: Double
actionThresholdValue = Double
a} :: ActionThreshold)

-- | Undocumented member.
actionThreshold_actionThresholdType :: Lens.Lens' ActionThreshold ThresholdType
actionThreshold_actionThresholdType :: (ThresholdType -> f ThresholdType)
-> ActionThreshold -> f ActionThreshold
actionThreshold_actionThresholdType = (ActionThreshold -> ThresholdType)
-> (ActionThreshold -> ThresholdType -> ActionThreshold)
-> Lens ActionThreshold ActionThreshold ThresholdType ThresholdType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ActionThreshold' {ThresholdType
actionThresholdType :: ThresholdType
$sel:actionThresholdType:ActionThreshold' :: ActionThreshold -> ThresholdType
actionThresholdType} -> ThresholdType
actionThresholdType) (\s :: ActionThreshold
s@ActionThreshold' {} ThresholdType
a -> ActionThreshold
s {$sel:actionThresholdType:ActionThreshold' :: ThresholdType
actionThresholdType = ThresholdType
a} :: ActionThreshold)

instance Core.FromJSON ActionThreshold where
  parseJSON :: Value -> Parser ActionThreshold
parseJSON =
    String
-> (Object -> Parser ActionThreshold)
-> Value
-> Parser ActionThreshold
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ActionThreshold"
      ( \Object
x ->
          Double -> ThresholdType -> ActionThreshold
ActionThreshold'
            (Double -> ThresholdType -> ActionThreshold)
-> Parser Double -> Parser (ThresholdType -> ActionThreshold)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Double
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ActionThresholdValue")
            Parser (ThresholdType -> ActionThreshold)
-> Parser ThresholdType -> Parser ActionThreshold
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ThresholdType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ActionThresholdType")
      )

instance Prelude.Hashable ActionThreshold

instance Prelude.NFData ActionThreshold

instance Core.ToJSON ActionThreshold where
  toJSON :: ActionThreshold -> Value
toJSON ActionThreshold' {Double
ThresholdType
actionThresholdType :: ThresholdType
actionThresholdValue :: Double
$sel:actionThresholdType:ActionThreshold' :: ActionThreshold -> ThresholdType
$sel:actionThresholdValue:ActionThreshold' :: ActionThreshold -> Double
..} =
    [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
"ActionThresholdValue"
                  Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Double
actionThresholdValue
              ),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ActionThresholdType" Text -> ThresholdType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ThresholdType
actionThresholdType)
          ]
      )