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

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

-- | The amount of cost or usage that is measured for a budget.
--
-- For example, a @Spend@ for @3 GB@ of S3 usage would have the following
-- parameters:
--
-- -   An @Amount@ of @3@
--
-- -   A @unit@ of @GB@
--
-- /See:/ 'newSpend' smart constructor.
data Spend = Spend'
  { -- | The cost or usage amount that is associated with a budget forecast,
    -- actual spend, or budget threshold.
    Spend -> Text
amount :: Prelude.Text,
    -- | The unit of measurement that is used for the budget forecast, actual
    -- spend, or budget threshold, such as dollars or GB.
    Spend -> Text
unit :: Prelude.Text
  }
  deriving (Spend -> Spend -> Bool
(Spend -> Spend -> Bool) -> (Spend -> Spend -> Bool) -> Eq Spend
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Spend -> Spend -> Bool
$c/= :: Spend -> Spend -> Bool
== :: Spend -> Spend -> Bool
$c== :: Spend -> Spend -> Bool
Prelude.Eq, ReadPrec [Spend]
ReadPrec Spend
Int -> ReadS Spend
ReadS [Spend]
(Int -> ReadS Spend)
-> ReadS [Spend]
-> ReadPrec Spend
-> ReadPrec [Spend]
-> Read Spend
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Spend]
$creadListPrec :: ReadPrec [Spend]
readPrec :: ReadPrec Spend
$creadPrec :: ReadPrec Spend
readList :: ReadS [Spend]
$creadList :: ReadS [Spend]
readsPrec :: Int -> ReadS Spend
$creadsPrec :: Int -> ReadS Spend
Prelude.Read, Int -> Spend -> ShowS
[Spend] -> ShowS
Spend -> String
(Int -> Spend -> ShowS)
-> (Spend -> String) -> ([Spend] -> ShowS) -> Show Spend
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Spend] -> ShowS
$cshowList :: [Spend] -> ShowS
show :: Spend -> String
$cshow :: Spend -> String
showsPrec :: Int -> Spend -> ShowS
$cshowsPrec :: Int -> Spend -> ShowS
Prelude.Show, (forall x. Spend -> Rep Spend x)
-> (forall x. Rep Spend x -> Spend) -> Generic Spend
forall x. Rep Spend x -> Spend
forall x. Spend -> Rep Spend x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Spend x -> Spend
$cfrom :: forall x. Spend -> Rep Spend x
Prelude.Generic)

-- |
-- Create a value of 'Spend' 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:
--
-- 'amount', 'spend_amount' - The cost or usage amount that is associated with a budget forecast,
-- actual spend, or budget threshold.
--
-- 'unit', 'spend_unit' - The unit of measurement that is used for the budget forecast, actual
-- spend, or budget threshold, such as dollars or GB.
newSpend ::
  -- | 'amount'
  Prelude.Text ->
  -- | 'unit'
  Prelude.Text ->
  Spend
newSpend :: Text -> Text -> Spend
newSpend Text
pAmount_ Text
pUnit_ =
  Spend' :: Text -> Text -> Spend
Spend' {$sel:amount:Spend' :: Text
amount = Text
pAmount_, $sel:unit:Spend' :: Text
unit = Text
pUnit_}

-- | The cost or usage amount that is associated with a budget forecast,
-- actual spend, or budget threshold.
spend_amount :: Lens.Lens' Spend Prelude.Text
spend_amount :: (Text -> f Text) -> Spend -> f Spend
spend_amount = (Spend -> Text)
-> (Spend -> Text -> Spend) -> Lens Spend Spend Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Spend' {Text
amount :: Text
$sel:amount:Spend' :: Spend -> Text
amount} -> Text
amount) (\s :: Spend
s@Spend' {} Text
a -> Spend
s {$sel:amount:Spend' :: Text
amount = Text
a} :: Spend)

-- | The unit of measurement that is used for the budget forecast, actual
-- spend, or budget threshold, such as dollars or GB.
spend_unit :: Lens.Lens' Spend Prelude.Text
spend_unit :: (Text -> f Text) -> Spend -> f Spend
spend_unit = (Spend -> Text)
-> (Spend -> Text -> Spend) -> Lens Spend Spend Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Spend' {Text
unit :: Text
$sel:unit:Spend' :: Spend -> Text
unit} -> Text
unit) (\s :: Spend
s@Spend' {} Text
a -> Spend
s {$sel:unit:Spend' :: Text
unit = Text
a} :: Spend)

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

instance Prelude.Hashable Spend

instance Prelude.NFData Spend

instance Core.ToJSON Spend where
  toJSON :: Spend -> Value
toJSON Spend' {Text
unit :: Text
amount :: Text
$sel:unit:Spend' :: Spend -> Text
$sel:amount:Spend' :: Spend -> Text
..} =
    [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
"Amount" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
amount),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Unit" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
unit)
          ]
      )