{-# 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.CostExplorer.Types.MetricValue
-- 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.CostExplorer.Types.MetricValue 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 aggregated value for a metric.
--
-- /See:/ 'newMetricValue' smart constructor.
data MetricValue = MetricValue'
  { -- | The actual number that represents the metric.
    MetricValue -> Maybe Text
amount :: Prelude.Maybe Prelude.Text,
    -- | The unit that the metric is given in.
    MetricValue -> Maybe Text
unit :: Prelude.Maybe Prelude.Text
  }
  deriving (MetricValue -> MetricValue -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricValue -> MetricValue -> Bool
$c/= :: MetricValue -> MetricValue -> Bool
== :: MetricValue -> MetricValue -> Bool
$c== :: MetricValue -> MetricValue -> Bool
Prelude.Eq, ReadPrec [MetricValue]
ReadPrec MetricValue
Int -> ReadS MetricValue
ReadS [MetricValue]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricValue]
$creadListPrec :: ReadPrec [MetricValue]
readPrec :: ReadPrec MetricValue
$creadPrec :: ReadPrec MetricValue
readList :: ReadS [MetricValue]
$creadList :: ReadS [MetricValue]
readsPrec :: Int -> ReadS MetricValue
$creadsPrec :: Int -> ReadS MetricValue
Prelude.Read, Int -> MetricValue -> ShowS
[MetricValue] -> ShowS
MetricValue -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricValue] -> ShowS
$cshowList :: [MetricValue] -> ShowS
show :: MetricValue -> String
$cshow :: MetricValue -> String
showsPrec :: Int -> MetricValue -> ShowS
$cshowsPrec :: Int -> MetricValue -> ShowS
Prelude.Show, forall x. Rep MetricValue x -> MetricValue
forall x. MetricValue -> Rep MetricValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricValue x -> MetricValue
$cfrom :: forall x. MetricValue -> Rep MetricValue x
Prelude.Generic)

-- |
-- Create a value of 'MetricValue' 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', 'metricValue_amount' - The actual number that represents the metric.
--
-- 'unit', 'metricValue_unit' - The unit that the metric is given in.
newMetricValue ::
  MetricValue
newMetricValue :: MetricValue
newMetricValue =
  MetricValue'
    { $sel:amount:MetricValue' :: Maybe Text
amount = forall a. Maybe a
Prelude.Nothing,
      $sel:unit:MetricValue' :: Maybe Text
unit = forall a. Maybe a
Prelude.Nothing
    }

-- | The actual number that represents the metric.
metricValue_amount :: Lens.Lens' MetricValue (Prelude.Maybe Prelude.Text)
metricValue_amount :: Lens' MetricValue (Maybe Text)
metricValue_amount = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricValue' {Maybe Text
amount :: Maybe Text
$sel:amount:MetricValue' :: MetricValue -> Maybe Text
amount} -> Maybe Text
amount) (\s :: MetricValue
s@MetricValue' {} Maybe Text
a -> MetricValue
s {$sel:amount:MetricValue' :: Maybe Text
amount = Maybe Text
a} :: MetricValue)

-- | The unit that the metric is given in.
metricValue_unit :: Lens.Lens' MetricValue (Prelude.Maybe Prelude.Text)
metricValue_unit :: Lens' MetricValue (Maybe Text)
metricValue_unit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricValue' {Maybe Text
unit :: Maybe Text
$sel:unit:MetricValue' :: MetricValue -> Maybe Text
unit} -> Maybe Text
unit) (\s :: MetricValue
s@MetricValue' {} Maybe Text
a -> MetricValue
s {$sel:unit:MetricValue' :: Maybe Text
unit = Maybe Text
a} :: MetricValue)

instance Data.FromJSON MetricValue where
  parseJSON :: Value -> Parser MetricValue
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MetricValue"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> MetricValue
MetricValue'
            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
"Amount")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Unit")
      )

instance Prelude.Hashable MetricValue where
  hashWithSalt :: Int -> MetricValue -> Int
hashWithSalt Int
_salt MetricValue' {Maybe Text
unit :: Maybe Text
amount :: Maybe Text
$sel:unit:MetricValue' :: MetricValue -> Maybe Text
$sel:amount:MetricValue' :: MetricValue -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
amount
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
unit

instance Prelude.NFData MetricValue where
  rnf :: MetricValue -> ()
rnf MetricValue' {Maybe Text
unit :: Maybe Text
amount :: Maybe Text
$sel:unit:MetricValue' :: MetricValue -> Maybe Text
$sel:amount:MetricValue' :: MetricValue -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
amount seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
unit