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

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

-- | The parameters that define or describe the historical data that your
-- auto-adjusting budget is based on.
--
-- /See:/ 'newHistoricalOptions' smart constructor.
data HistoricalOptions = HistoricalOptions'
  { -- | The integer that describes how many budget periods in your
    -- @BudgetAdjustmentPeriod@ are included in the calculation of your current
    -- @BudgetLimit@. If the first budget period in your
    -- @BudgetAdjustmentPeriod@ has no cost data, then that budget period isn’t
    -- included in the average that determines your budget limit.
    --
    -- For example, if you set @BudgetAdjustmentPeriod@ as @4@ quarters, but
    -- your account had no cost data in the first quarter, then only the last
    -- three quarters are included in the calculation. In this scenario,
    -- @LookBackAvailablePeriods@ returns @3@.
    --
    -- You can’t set your own @LookBackAvailablePeriods@. The value is
    -- automatically calculated from the @BudgetAdjustmentPeriod@ and your
    -- historical cost data.
    HistoricalOptions -> Maybe Natural
lookBackAvailablePeriods :: Prelude.Maybe Prelude.Natural,
    -- | The number of budget periods included in the moving-average calculation
    -- that determines your auto-adjusted budget amount. The maximum value
    -- depends on the @TimeUnit@ granularity of the budget:
    --
    -- -   For the @DAILY@ granularity, the maximum value is @60@.
    --
    -- -   For the @MONTHLY@ granularity, the maximum value is @12@.
    --
    -- -   For the @QUARTERLY@ granularity, the maximum value is @4@.
    --
    -- -   For the @ANNUALLY@ granularity, the maximum value is @1@.
    HistoricalOptions -> Natural
budgetAdjustmentPeriod :: Prelude.Natural
  }
  deriving (HistoricalOptions -> HistoricalOptions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HistoricalOptions -> HistoricalOptions -> Bool
$c/= :: HistoricalOptions -> HistoricalOptions -> Bool
== :: HistoricalOptions -> HistoricalOptions -> Bool
$c== :: HistoricalOptions -> HistoricalOptions -> Bool
Prelude.Eq, ReadPrec [HistoricalOptions]
ReadPrec HistoricalOptions
Int -> ReadS HistoricalOptions
ReadS [HistoricalOptions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HistoricalOptions]
$creadListPrec :: ReadPrec [HistoricalOptions]
readPrec :: ReadPrec HistoricalOptions
$creadPrec :: ReadPrec HistoricalOptions
readList :: ReadS [HistoricalOptions]
$creadList :: ReadS [HistoricalOptions]
readsPrec :: Int -> ReadS HistoricalOptions
$creadsPrec :: Int -> ReadS HistoricalOptions
Prelude.Read, Int -> HistoricalOptions -> ShowS
[HistoricalOptions] -> ShowS
HistoricalOptions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HistoricalOptions] -> ShowS
$cshowList :: [HistoricalOptions] -> ShowS
show :: HistoricalOptions -> String
$cshow :: HistoricalOptions -> String
showsPrec :: Int -> HistoricalOptions -> ShowS
$cshowsPrec :: Int -> HistoricalOptions -> ShowS
Prelude.Show, forall x. Rep HistoricalOptions x -> HistoricalOptions
forall x. HistoricalOptions -> Rep HistoricalOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HistoricalOptions x -> HistoricalOptions
$cfrom :: forall x. HistoricalOptions -> Rep HistoricalOptions x
Prelude.Generic)

-- |
-- Create a value of 'HistoricalOptions' 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:
--
-- 'lookBackAvailablePeriods', 'historicalOptions_lookBackAvailablePeriods' - The integer that describes how many budget periods in your
-- @BudgetAdjustmentPeriod@ are included in the calculation of your current
-- @BudgetLimit@. If the first budget period in your
-- @BudgetAdjustmentPeriod@ has no cost data, then that budget period isn’t
-- included in the average that determines your budget limit.
--
-- For example, if you set @BudgetAdjustmentPeriod@ as @4@ quarters, but
-- your account had no cost data in the first quarter, then only the last
-- three quarters are included in the calculation. In this scenario,
-- @LookBackAvailablePeriods@ returns @3@.
--
-- You can’t set your own @LookBackAvailablePeriods@. The value is
-- automatically calculated from the @BudgetAdjustmentPeriod@ and your
-- historical cost data.
--
-- 'budgetAdjustmentPeriod', 'historicalOptions_budgetAdjustmentPeriod' - The number of budget periods included in the moving-average calculation
-- that determines your auto-adjusted budget amount. The maximum value
-- depends on the @TimeUnit@ granularity of the budget:
--
-- -   For the @DAILY@ granularity, the maximum value is @60@.
--
-- -   For the @MONTHLY@ granularity, the maximum value is @12@.
--
-- -   For the @QUARTERLY@ granularity, the maximum value is @4@.
--
-- -   For the @ANNUALLY@ granularity, the maximum value is @1@.
newHistoricalOptions ::
  -- | 'budgetAdjustmentPeriod'
  Prelude.Natural ->
  HistoricalOptions
newHistoricalOptions :: Natural -> HistoricalOptions
newHistoricalOptions Natural
pBudgetAdjustmentPeriod_ =
  HistoricalOptions'
    { $sel:lookBackAvailablePeriods:HistoricalOptions' :: Maybe Natural
lookBackAvailablePeriods =
        forall a. Maybe a
Prelude.Nothing,
      $sel:budgetAdjustmentPeriod:HistoricalOptions' :: Natural
budgetAdjustmentPeriod = Natural
pBudgetAdjustmentPeriod_
    }

-- | The integer that describes how many budget periods in your
-- @BudgetAdjustmentPeriod@ are included in the calculation of your current
-- @BudgetLimit@. If the first budget period in your
-- @BudgetAdjustmentPeriod@ has no cost data, then that budget period isn’t
-- included in the average that determines your budget limit.
--
-- For example, if you set @BudgetAdjustmentPeriod@ as @4@ quarters, but
-- your account had no cost data in the first quarter, then only the last
-- three quarters are included in the calculation. In this scenario,
-- @LookBackAvailablePeriods@ returns @3@.
--
-- You can’t set your own @LookBackAvailablePeriods@. The value is
-- automatically calculated from the @BudgetAdjustmentPeriod@ and your
-- historical cost data.
historicalOptions_lookBackAvailablePeriods :: Lens.Lens' HistoricalOptions (Prelude.Maybe Prelude.Natural)
historicalOptions_lookBackAvailablePeriods :: Lens' HistoricalOptions (Maybe Natural)
historicalOptions_lookBackAvailablePeriods = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HistoricalOptions' {Maybe Natural
lookBackAvailablePeriods :: Maybe Natural
$sel:lookBackAvailablePeriods:HistoricalOptions' :: HistoricalOptions -> Maybe Natural
lookBackAvailablePeriods} -> Maybe Natural
lookBackAvailablePeriods) (\s :: HistoricalOptions
s@HistoricalOptions' {} Maybe Natural
a -> HistoricalOptions
s {$sel:lookBackAvailablePeriods:HistoricalOptions' :: Maybe Natural
lookBackAvailablePeriods = Maybe Natural
a} :: HistoricalOptions)

-- | The number of budget periods included in the moving-average calculation
-- that determines your auto-adjusted budget amount. The maximum value
-- depends on the @TimeUnit@ granularity of the budget:
--
-- -   For the @DAILY@ granularity, the maximum value is @60@.
--
-- -   For the @MONTHLY@ granularity, the maximum value is @12@.
--
-- -   For the @QUARTERLY@ granularity, the maximum value is @4@.
--
-- -   For the @ANNUALLY@ granularity, the maximum value is @1@.
historicalOptions_budgetAdjustmentPeriod :: Lens.Lens' HistoricalOptions Prelude.Natural
historicalOptions_budgetAdjustmentPeriod :: Lens' HistoricalOptions Natural
historicalOptions_budgetAdjustmentPeriod = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HistoricalOptions' {Natural
budgetAdjustmentPeriod :: Natural
$sel:budgetAdjustmentPeriod:HistoricalOptions' :: HistoricalOptions -> Natural
budgetAdjustmentPeriod} -> Natural
budgetAdjustmentPeriod) (\s :: HistoricalOptions
s@HistoricalOptions' {} Natural
a -> HistoricalOptions
s {$sel:budgetAdjustmentPeriod:HistoricalOptions' :: Natural
budgetAdjustmentPeriod = Natural
a} :: HistoricalOptions)

instance Data.FromJSON HistoricalOptions where
  parseJSON :: Value -> Parser HistoricalOptions
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"HistoricalOptions"
      ( \Object
x ->
          Maybe Natural -> Natural -> HistoricalOptions
HistoricalOptions'
            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
"LookBackAvailablePeriods")
            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
"BudgetAdjustmentPeriod")
      )

instance Prelude.Hashable HistoricalOptions where
  hashWithSalt :: Int -> HistoricalOptions -> Int
hashWithSalt Int
_salt HistoricalOptions' {Natural
Maybe Natural
budgetAdjustmentPeriod :: Natural
lookBackAvailablePeriods :: Maybe Natural
$sel:budgetAdjustmentPeriod:HistoricalOptions' :: HistoricalOptions -> Natural
$sel:lookBackAvailablePeriods:HistoricalOptions' :: HistoricalOptions -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
lookBackAvailablePeriods
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
budgetAdjustmentPeriod

instance Prelude.NFData HistoricalOptions where
  rnf :: HistoricalOptions -> ()
rnf HistoricalOptions' {Natural
Maybe Natural
budgetAdjustmentPeriod :: Natural
lookBackAvailablePeriods :: Maybe Natural
$sel:budgetAdjustmentPeriod:HistoricalOptions' :: HistoricalOptions -> Natural
$sel:lookBackAvailablePeriods:HistoricalOptions' :: HistoricalOptions -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
lookBackAvailablePeriods
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
budgetAdjustmentPeriod

instance Data.ToJSON HistoricalOptions where
  toJSON :: HistoricalOptions -> Value
toJSON HistoricalOptions' {Natural
Maybe Natural
budgetAdjustmentPeriod :: Natural
lookBackAvailablePeriods :: Maybe Natural
$sel:budgetAdjustmentPeriod:HistoricalOptions' :: HistoricalOptions -> Natural
$sel:lookBackAvailablePeriods:HistoricalOptions' :: HistoricalOptions -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"LookBackAvailablePeriods" 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 Natural
lookBackAvailablePeriods,
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"BudgetAdjustmentPeriod"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
budgetAdjustmentPeriod
              )
          ]
      )