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

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

-- | The spend objects that are associated with this budget. The
-- @actualSpend@ tracks how much you\'ve used, cost, usage, RI units, or
-- Savings Plans units and the @forecastedSpend@ tracks how much you are
-- predicted to spend based on your historical usage profile.
--
-- For example, if it is the 20th of the month and you have spent @50@
-- dollars on Amazon EC2, your @actualSpend@ is @50 USD@, and your
-- @forecastedSpend@ is @75 USD@.
--
-- /See:/ 'newCalculatedSpend' smart constructor.
data CalculatedSpend = CalculatedSpend'
  { -- | The amount of cost, usage, RI units, or Savings Plans units that you are
    -- forecasted to use.
    CalculatedSpend -> Maybe Spend
forecastedSpend :: Prelude.Maybe Spend,
    -- | The amount of cost, usage, RI units, or Savings Plans units that you
    -- have used.
    CalculatedSpend -> Spend
actualSpend :: Spend
  }
  deriving (CalculatedSpend -> CalculatedSpend -> Bool
(CalculatedSpend -> CalculatedSpend -> Bool)
-> (CalculatedSpend -> CalculatedSpend -> Bool)
-> Eq CalculatedSpend
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CalculatedSpend -> CalculatedSpend -> Bool
$c/= :: CalculatedSpend -> CalculatedSpend -> Bool
== :: CalculatedSpend -> CalculatedSpend -> Bool
$c== :: CalculatedSpend -> CalculatedSpend -> Bool
Prelude.Eq, ReadPrec [CalculatedSpend]
ReadPrec CalculatedSpend
Int -> ReadS CalculatedSpend
ReadS [CalculatedSpend]
(Int -> ReadS CalculatedSpend)
-> ReadS [CalculatedSpend]
-> ReadPrec CalculatedSpend
-> ReadPrec [CalculatedSpend]
-> Read CalculatedSpend
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CalculatedSpend]
$creadListPrec :: ReadPrec [CalculatedSpend]
readPrec :: ReadPrec CalculatedSpend
$creadPrec :: ReadPrec CalculatedSpend
readList :: ReadS [CalculatedSpend]
$creadList :: ReadS [CalculatedSpend]
readsPrec :: Int -> ReadS CalculatedSpend
$creadsPrec :: Int -> ReadS CalculatedSpend
Prelude.Read, Int -> CalculatedSpend -> ShowS
[CalculatedSpend] -> ShowS
CalculatedSpend -> String
(Int -> CalculatedSpend -> ShowS)
-> (CalculatedSpend -> String)
-> ([CalculatedSpend] -> ShowS)
-> Show CalculatedSpend
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CalculatedSpend] -> ShowS
$cshowList :: [CalculatedSpend] -> ShowS
show :: CalculatedSpend -> String
$cshow :: CalculatedSpend -> String
showsPrec :: Int -> CalculatedSpend -> ShowS
$cshowsPrec :: Int -> CalculatedSpend -> ShowS
Prelude.Show, (forall x. CalculatedSpend -> Rep CalculatedSpend x)
-> (forall x. Rep CalculatedSpend x -> CalculatedSpend)
-> Generic CalculatedSpend
forall x. Rep CalculatedSpend x -> CalculatedSpend
forall x. CalculatedSpend -> Rep CalculatedSpend x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CalculatedSpend x -> CalculatedSpend
$cfrom :: forall x. CalculatedSpend -> Rep CalculatedSpend x
Prelude.Generic)

-- |
-- Create a value of 'CalculatedSpend' 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:
--
-- 'forecastedSpend', 'calculatedSpend_forecastedSpend' - The amount of cost, usage, RI units, or Savings Plans units that you are
-- forecasted to use.
--
-- 'actualSpend', 'calculatedSpend_actualSpend' - The amount of cost, usage, RI units, or Savings Plans units that you
-- have used.
newCalculatedSpend ::
  -- | 'actualSpend'
  Spend ->
  CalculatedSpend
newCalculatedSpend :: Spend -> CalculatedSpend
newCalculatedSpend Spend
pActualSpend_ =
  CalculatedSpend' :: Maybe Spend -> Spend -> CalculatedSpend
CalculatedSpend'
    { $sel:forecastedSpend:CalculatedSpend' :: Maybe Spend
forecastedSpend = Maybe Spend
forall a. Maybe a
Prelude.Nothing,
      $sel:actualSpend:CalculatedSpend' :: Spend
actualSpend = Spend
pActualSpend_
    }

-- | The amount of cost, usage, RI units, or Savings Plans units that you are
-- forecasted to use.
calculatedSpend_forecastedSpend :: Lens.Lens' CalculatedSpend (Prelude.Maybe Spend)
calculatedSpend_forecastedSpend :: (Maybe Spend -> f (Maybe Spend))
-> CalculatedSpend -> f CalculatedSpend
calculatedSpend_forecastedSpend = (CalculatedSpend -> Maybe Spend)
-> (CalculatedSpend -> Maybe Spend -> CalculatedSpend)
-> Lens CalculatedSpend CalculatedSpend (Maybe Spend) (Maybe Spend)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CalculatedSpend' {Maybe Spend
forecastedSpend :: Maybe Spend
$sel:forecastedSpend:CalculatedSpend' :: CalculatedSpend -> Maybe Spend
forecastedSpend} -> Maybe Spend
forecastedSpend) (\s :: CalculatedSpend
s@CalculatedSpend' {} Maybe Spend
a -> CalculatedSpend
s {$sel:forecastedSpend:CalculatedSpend' :: Maybe Spend
forecastedSpend = Maybe Spend
a} :: CalculatedSpend)

-- | The amount of cost, usage, RI units, or Savings Plans units that you
-- have used.
calculatedSpend_actualSpend :: Lens.Lens' CalculatedSpend Spend
calculatedSpend_actualSpend :: (Spend -> f Spend) -> CalculatedSpend -> f CalculatedSpend
calculatedSpend_actualSpend = (CalculatedSpend -> Spend)
-> (CalculatedSpend -> Spend -> CalculatedSpend)
-> Lens CalculatedSpend CalculatedSpend Spend Spend
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CalculatedSpend' {Spend
actualSpend :: Spend
$sel:actualSpend:CalculatedSpend' :: CalculatedSpend -> Spend
actualSpend} -> Spend
actualSpend) (\s :: CalculatedSpend
s@CalculatedSpend' {} Spend
a -> CalculatedSpend
s {$sel:actualSpend:CalculatedSpend' :: Spend
actualSpend = Spend
a} :: CalculatedSpend)

instance Core.FromJSON CalculatedSpend where
  parseJSON :: Value -> Parser CalculatedSpend
parseJSON =
    String
-> (Object -> Parser CalculatedSpend)
-> Value
-> Parser CalculatedSpend
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CalculatedSpend"
      ( \Object
x ->
          Maybe Spend -> Spend -> CalculatedSpend
CalculatedSpend'
            (Maybe Spend -> Spend -> CalculatedSpend)
-> Parser (Maybe Spend) -> Parser (Spend -> CalculatedSpend)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Spend)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ForecastedSpend")
            Parser (Spend -> CalculatedSpend)
-> Parser Spend -> Parser CalculatedSpend
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Spend
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ActualSpend")
      )

instance Prelude.Hashable CalculatedSpend

instance Prelude.NFData CalculatedSpend

instance Core.ToJSON CalculatedSpend where
  toJSON :: CalculatedSpend -> Value
toJSON CalculatedSpend' {Maybe Spend
Spend
actualSpend :: Spend
forecastedSpend :: Maybe Spend
$sel:actualSpend:CalculatedSpend' :: CalculatedSpend -> Spend
$sel:forecastedSpend:CalculatedSpend' :: CalculatedSpend -> Maybe Spend
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ForecastedSpend" Text -> Spend -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Spend -> Pair) -> Maybe Spend -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Spend
forecastedSpend,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ActualSpend" Text -> Spend -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Spend
actualSpend)
          ]
      )