{-# 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.ApplicationAutoScaling.Types.StepAdjustment
-- 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.ApplicationAutoScaling.Types.StepAdjustment where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a step adjustment for a
-- <https://docs.aws.amazon.com/autoscaling/application/APIReference/API_StepScalingPolicyConfiguration.html StepScalingPolicyConfiguration>.
-- Describes an adjustment based on the difference between the value of the
-- aggregated CloudWatch metric and the breach threshold that you\'ve
-- defined for the alarm.
--
-- For the following examples, suppose that you have an alarm with a breach
-- threshold of 50:
--
-- -   To trigger the adjustment when the metric is greater than or equal
--     to 50 and less than 60, specify a lower bound of 0 and an upper
--     bound of 10.
--
-- -   To trigger the adjustment when the metric is greater than 40 and
--     less than or equal to 50, specify a lower bound of -10 and an upper
--     bound of 0.
--
-- There are a few rules for the step adjustments for your step policy:
--
-- -   The ranges of your step adjustments can\'t overlap or have a gap.
--
-- -   At most one step adjustment can have a null lower bound. If one step
--     adjustment has a negative lower bound, then there must be a step
--     adjustment with a null lower bound.
--
-- -   At most one step adjustment can have a null upper bound. If one step
--     adjustment has a positive upper bound, then there must be a step
--     adjustment with a null upper bound.
--
-- -   The upper and lower bound can\'t be null in the same step
--     adjustment.
--
-- /See:/ 'newStepAdjustment' smart constructor.
data StepAdjustment = StepAdjustment'
  { -- | The lower bound for the difference between the alarm threshold and the
    -- CloudWatch metric. If the metric value is above the breach threshold,
    -- the lower bound is inclusive (the metric must be greater than or equal
    -- to the threshold plus the lower bound). Otherwise, it is exclusive (the
    -- metric must be greater than the threshold plus the lower bound). A null
    -- value indicates negative infinity.
    StepAdjustment -> Maybe Double
metricIntervalLowerBound :: Prelude.Maybe Prelude.Double,
    -- | The upper bound for the difference between the alarm threshold and the
    -- CloudWatch metric. If the metric value is above the breach threshold,
    -- the upper bound is exclusive (the metric must be less than the threshold
    -- plus the upper bound). Otherwise, it is inclusive (the metric must be
    -- less than or equal to the threshold plus the upper bound). A null value
    -- indicates positive infinity.
    --
    -- The upper bound must be greater than the lower bound.
    StepAdjustment -> Maybe Double
metricIntervalUpperBound :: Prelude.Maybe Prelude.Double,
    -- | The amount by which to scale, based on the specified adjustment type. A
    -- positive value adds to the current capacity while a negative number
    -- removes from the current capacity. For exact capacity, you must specify
    -- a positive value.
    StepAdjustment -> Int
scalingAdjustment :: Prelude.Int
  }
  deriving (StepAdjustment -> StepAdjustment -> Bool
(StepAdjustment -> StepAdjustment -> Bool)
-> (StepAdjustment -> StepAdjustment -> Bool) -> Eq StepAdjustment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StepAdjustment -> StepAdjustment -> Bool
$c/= :: StepAdjustment -> StepAdjustment -> Bool
== :: StepAdjustment -> StepAdjustment -> Bool
$c== :: StepAdjustment -> StepAdjustment -> Bool
Prelude.Eq, ReadPrec [StepAdjustment]
ReadPrec StepAdjustment
Int -> ReadS StepAdjustment
ReadS [StepAdjustment]
(Int -> ReadS StepAdjustment)
-> ReadS [StepAdjustment]
-> ReadPrec StepAdjustment
-> ReadPrec [StepAdjustment]
-> Read StepAdjustment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StepAdjustment]
$creadListPrec :: ReadPrec [StepAdjustment]
readPrec :: ReadPrec StepAdjustment
$creadPrec :: ReadPrec StepAdjustment
readList :: ReadS [StepAdjustment]
$creadList :: ReadS [StepAdjustment]
readsPrec :: Int -> ReadS StepAdjustment
$creadsPrec :: Int -> ReadS StepAdjustment
Prelude.Read, Int -> StepAdjustment -> ShowS
[StepAdjustment] -> ShowS
StepAdjustment -> String
(Int -> StepAdjustment -> ShowS)
-> (StepAdjustment -> String)
-> ([StepAdjustment] -> ShowS)
-> Show StepAdjustment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StepAdjustment] -> ShowS
$cshowList :: [StepAdjustment] -> ShowS
show :: StepAdjustment -> String
$cshow :: StepAdjustment -> String
showsPrec :: Int -> StepAdjustment -> ShowS
$cshowsPrec :: Int -> StepAdjustment -> ShowS
Prelude.Show, (forall x. StepAdjustment -> Rep StepAdjustment x)
-> (forall x. Rep StepAdjustment x -> StepAdjustment)
-> Generic StepAdjustment
forall x. Rep StepAdjustment x -> StepAdjustment
forall x. StepAdjustment -> Rep StepAdjustment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StepAdjustment x -> StepAdjustment
$cfrom :: forall x. StepAdjustment -> Rep StepAdjustment x
Prelude.Generic)

-- |
-- Create a value of 'StepAdjustment' 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:
--
-- 'metricIntervalLowerBound', 'stepAdjustment_metricIntervalLowerBound' - The lower bound for the difference between the alarm threshold and the
-- CloudWatch metric. If the metric value is above the breach threshold,
-- the lower bound is inclusive (the metric must be greater than or equal
-- to the threshold plus the lower bound). Otherwise, it is exclusive (the
-- metric must be greater than the threshold plus the lower bound). A null
-- value indicates negative infinity.
--
-- 'metricIntervalUpperBound', 'stepAdjustment_metricIntervalUpperBound' - The upper bound for the difference between the alarm threshold and the
-- CloudWatch metric. If the metric value is above the breach threshold,
-- the upper bound is exclusive (the metric must be less than the threshold
-- plus the upper bound). Otherwise, it is inclusive (the metric must be
-- less than or equal to the threshold plus the upper bound). A null value
-- indicates positive infinity.
--
-- The upper bound must be greater than the lower bound.
--
-- 'scalingAdjustment', 'stepAdjustment_scalingAdjustment' - The amount by which to scale, based on the specified adjustment type. A
-- positive value adds to the current capacity while a negative number
-- removes from the current capacity. For exact capacity, you must specify
-- a positive value.
newStepAdjustment ::
  -- | 'scalingAdjustment'
  Prelude.Int ->
  StepAdjustment
newStepAdjustment :: Int -> StepAdjustment
newStepAdjustment Int
pScalingAdjustment_ =
  StepAdjustment' :: Maybe Double -> Maybe Double -> Int -> StepAdjustment
StepAdjustment'
    { $sel:metricIntervalLowerBound:StepAdjustment' :: Maybe Double
metricIntervalLowerBound =
        Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:metricIntervalUpperBound:StepAdjustment' :: Maybe Double
metricIntervalUpperBound = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:scalingAdjustment:StepAdjustment' :: Int
scalingAdjustment = Int
pScalingAdjustment_
    }

-- | The lower bound for the difference between the alarm threshold and the
-- CloudWatch metric. If the metric value is above the breach threshold,
-- the lower bound is inclusive (the metric must be greater than or equal
-- to the threshold plus the lower bound). Otherwise, it is exclusive (the
-- metric must be greater than the threshold plus the lower bound). A null
-- value indicates negative infinity.
stepAdjustment_metricIntervalLowerBound :: Lens.Lens' StepAdjustment (Prelude.Maybe Prelude.Double)
stepAdjustment_metricIntervalLowerBound :: (Maybe Double -> f (Maybe Double))
-> StepAdjustment -> f StepAdjustment
stepAdjustment_metricIntervalLowerBound = (StepAdjustment -> Maybe Double)
-> (StepAdjustment -> Maybe Double -> StepAdjustment)
-> Lens StepAdjustment StepAdjustment (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StepAdjustment' {Maybe Double
metricIntervalLowerBound :: Maybe Double
$sel:metricIntervalLowerBound:StepAdjustment' :: StepAdjustment -> Maybe Double
metricIntervalLowerBound} -> Maybe Double
metricIntervalLowerBound) (\s :: StepAdjustment
s@StepAdjustment' {} Maybe Double
a -> StepAdjustment
s {$sel:metricIntervalLowerBound:StepAdjustment' :: Maybe Double
metricIntervalLowerBound = Maybe Double
a} :: StepAdjustment)

-- | The upper bound for the difference between the alarm threshold and the
-- CloudWatch metric. If the metric value is above the breach threshold,
-- the upper bound is exclusive (the metric must be less than the threshold
-- plus the upper bound). Otherwise, it is inclusive (the metric must be
-- less than or equal to the threshold plus the upper bound). A null value
-- indicates positive infinity.
--
-- The upper bound must be greater than the lower bound.
stepAdjustment_metricIntervalUpperBound :: Lens.Lens' StepAdjustment (Prelude.Maybe Prelude.Double)
stepAdjustment_metricIntervalUpperBound :: (Maybe Double -> f (Maybe Double))
-> StepAdjustment -> f StepAdjustment
stepAdjustment_metricIntervalUpperBound = (StepAdjustment -> Maybe Double)
-> (StepAdjustment -> Maybe Double -> StepAdjustment)
-> Lens StepAdjustment StepAdjustment (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StepAdjustment' {Maybe Double
metricIntervalUpperBound :: Maybe Double
$sel:metricIntervalUpperBound:StepAdjustment' :: StepAdjustment -> Maybe Double
metricIntervalUpperBound} -> Maybe Double
metricIntervalUpperBound) (\s :: StepAdjustment
s@StepAdjustment' {} Maybe Double
a -> StepAdjustment
s {$sel:metricIntervalUpperBound:StepAdjustment' :: Maybe Double
metricIntervalUpperBound = Maybe Double
a} :: StepAdjustment)

-- | The amount by which to scale, based on the specified adjustment type. A
-- positive value adds to the current capacity while a negative number
-- removes from the current capacity. For exact capacity, you must specify
-- a positive value.
stepAdjustment_scalingAdjustment :: Lens.Lens' StepAdjustment Prelude.Int
stepAdjustment_scalingAdjustment :: (Int -> f Int) -> StepAdjustment -> f StepAdjustment
stepAdjustment_scalingAdjustment = (StepAdjustment -> Int)
-> (StepAdjustment -> Int -> StepAdjustment)
-> Lens StepAdjustment StepAdjustment Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StepAdjustment' {Int
scalingAdjustment :: Int
$sel:scalingAdjustment:StepAdjustment' :: StepAdjustment -> Int
scalingAdjustment} -> Int
scalingAdjustment) (\s :: StepAdjustment
s@StepAdjustment' {} Int
a -> StepAdjustment
s {$sel:scalingAdjustment:StepAdjustment' :: Int
scalingAdjustment = Int
a} :: StepAdjustment)

instance Core.FromJSON StepAdjustment where
  parseJSON :: Value -> Parser StepAdjustment
parseJSON =
    String
-> (Object -> Parser StepAdjustment)
-> Value
-> Parser StepAdjustment
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"StepAdjustment"
      ( \Object
x ->
          Maybe Double -> Maybe Double -> Int -> StepAdjustment
StepAdjustment'
            (Maybe Double -> Maybe Double -> Int -> StepAdjustment)
-> Parser (Maybe Double)
-> Parser (Maybe Double -> Int -> StepAdjustment)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MetricIntervalLowerBound")
            Parser (Maybe Double -> Int -> StepAdjustment)
-> Parser (Maybe Double) -> Parser (Int -> StepAdjustment)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MetricIntervalUpperBound")
            Parser (Int -> StepAdjustment)
-> Parser Int -> Parser StepAdjustment
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ScalingAdjustment")
      )

instance Prelude.Hashable StepAdjustment

instance Prelude.NFData StepAdjustment

instance Core.ToJSON StepAdjustment where
  toJSON :: StepAdjustment -> Value
toJSON StepAdjustment' {Int
Maybe Double
scalingAdjustment :: Int
metricIntervalUpperBound :: Maybe Double
metricIntervalLowerBound :: Maybe Double
$sel:scalingAdjustment:StepAdjustment' :: StepAdjustment -> Int
$sel:metricIntervalUpperBound:StepAdjustment' :: StepAdjustment -> Maybe Double
$sel:metricIntervalLowerBound:StepAdjustment' :: StepAdjustment -> Maybe Double
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"MetricIntervalLowerBound" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
metricIntervalLowerBound,
            (Text
"MetricIntervalUpperBound" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
metricIntervalUpperBound,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ScalingAdjustment" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
scalingAdjustment)
          ]
      )