{-# 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.UtilizationByTime
-- 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.CostExplorer.Types.UtilizationByTime where

import qualified Amazonka.Core as Core
import Amazonka.CostExplorer.Types.DateInterval
import Amazonka.CostExplorer.Types.ReservationAggregates
import Amazonka.CostExplorer.Types.ReservationUtilizationGroup
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The amount of utilization, in hours.
--
-- /See:/ 'newUtilizationByTime' smart constructor.
data UtilizationByTime = UtilizationByTime'
  { -- | The groups that this utilization result uses.
    UtilizationByTime -> Maybe [ReservationUtilizationGroup]
groups :: Prelude.Maybe [ReservationUtilizationGroup],
    -- | The period of time that this utilization was used for.
    UtilizationByTime -> Maybe DateInterval
timePeriod :: Prelude.Maybe DateInterval,
    -- | The total number of reservation hours that were used.
    UtilizationByTime -> Maybe ReservationAggregates
total :: Prelude.Maybe ReservationAggregates
  }
  deriving (UtilizationByTime -> UtilizationByTime -> Bool
(UtilizationByTime -> UtilizationByTime -> Bool)
-> (UtilizationByTime -> UtilizationByTime -> Bool)
-> Eq UtilizationByTime
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UtilizationByTime -> UtilizationByTime -> Bool
$c/= :: UtilizationByTime -> UtilizationByTime -> Bool
== :: UtilizationByTime -> UtilizationByTime -> Bool
$c== :: UtilizationByTime -> UtilizationByTime -> Bool
Prelude.Eq, ReadPrec [UtilizationByTime]
ReadPrec UtilizationByTime
Int -> ReadS UtilizationByTime
ReadS [UtilizationByTime]
(Int -> ReadS UtilizationByTime)
-> ReadS [UtilizationByTime]
-> ReadPrec UtilizationByTime
-> ReadPrec [UtilizationByTime]
-> Read UtilizationByTime
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UtilizationByTime]
$creadListPrec :: ReadPrec [UtilizationByTime]
readPrec :: ReadPrec UtilizationByTime
$creadPrec :: ReadPrec UtilizationByTime
readList :: ReadS [UtilizationByTime]
$creadList :: ReadS [UtilizationByTime]
readsPrec :: Int -> ReadS UtilizationByTime
$creadsPrec :: Int -> ReadS UtilizationByTime
Prelude.Read, Int -> UtilizationByTime -> ShowS
[UtilizationByTime] -> ShowS
UtilizationByTime -> String
(Int -> UtilizationByTime -> ShowS)
-> (UtilizationByTime -> String)
-> ([UtilizationByTime] -> ShowS)
-> Show UtilizationByTime
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UtilizationByTime] -> ShowS
$cshowList :: [UtilizationByTime] -> ShowS
show :: UtilizationByTime -> String
$cshow :: UtilizationByTime -> String
showsPrec :: Int -> UtilizationByTime -> ShowS
$cshowsPrec :: Int -> UtilizationByTime -> ShowS
Prelude.Show, (forall x. UtilizationByTime -> Rep UtilizationByTime x)
-> (forall x. Rep UtilizationByTime x -> UtilizationByTime)
-> Generic UtilizationByTime
forall x. Rep UtilizationByTime x -> UtilizationByTime
forall x. UtilizationByTime -> Rep UtilizationByTime x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UtilizationByTime x -> UtilizationByTime
$cfrom :: forall x. UtilizationByTime -> Rep UtilizationByTime x
Prelude.Generic)

-- |
-- Create a value of 'UtilizationByTime' 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:
--
-- 'groups', 'utilizationByTime_groups' - The groups that this utilization result uses.
--
-- 'timePeriod', 'utilizationByTime_timePeriod' - The period of time that this utilization was used for.
--
-- 'total', 'utilizationByTime_total' - The total number of reservation hours that were used.
newUtilizationByTime ::
  UtilizationByTime
newUtilizationByTime :: UtilizationByTime
newUtilizationByTime =
  UtilizationByTime' :: Maybe [ReservationUtilizationGroup]
-> Maybe DateInterval
-> Maybe ReservationAggregates
-> UtilizationByTime
UtilizationByTime'
    { $sel:groups:UtilizationByTime' :: Maybe [ReservationUtilizationGroup]
groups = Maybe [ReservationUtilizationGroup]
forall a. Maybe a
Prelude.Nothing,
      $sel:timePeriod:UtilizationByTime' :: Maybe DateInterval
timePeriod = Maybe DateInterval
forall a. Maybe a
Prelude.Nothing,
      $sel:total:UtilizationByTime' :: Maybe ReservationAggregates
total = Maybe ReservationAggregates
forall a. Maybe a
Prelude.Nothing
    }

-- | The groups that this utilization result uses.
utilizationByTime_groups :: Lens.Lens' UtilizationByTime (Prelude.Maybe [ReservationUtilizationGroup])
utilizationByTime_groups :: (Maybe [ReservationUtilizationGroup]
 -> f (Maybe [ReservationUtilizationGroup]))
-> UtilizationByTime -> f UtilizationByTime
utilizationByTime_groups = (UtilizationByTime -> Maybe [ReservationUtilizationGroup])
-> (UtilizationByTime
    -> Maybe [ReservationUtilizationGroup] -> UtilizationByTime)
-> Lens
     UtilizationByTime
     UtilizationByTime
     (Maybe [ReservationUtilizationGroup])
     (Maybe [ReservationUtilizationGroup])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UtilizationByTime' {Maybe [ReservationUtilizationGroup]
groups :: Maybe [ReservationUtilizationGroup]
$sel:groups:UtilizationByTime' :: UtilizationByTime -> Maybe [ReservationUtilizationGroup]
groups} -> Maybe [ReservationUtilizationGroup]
groups) (\s :: UtilizationByTime
s@UtilizationByTime' {} Maybe [ReservationUtilizationGroup]
a -> UtilizationByTime
s {$sel:groups:UtilizationByTime' :: Maybe [ReservationUtilizationGroup]
groups = Maybe [ReservationUtilizationGroup]
a} :: UtilizationByTime) ((Maybe [ReservationUtilizationGroup]
  -> f (Maybe [ReservationUtilizationGroup]))
 -> UtilizationByTime -> f UtilizationByTime)
-> ((Maybe [ReservationUtilizationGroup]
     -> f (Maybe [ReservationUtilizationGroup]))
    -> Maybe [ReservationUtilizationGroup]
    -> f (Maybe [ReservationUtilizationGroup]))
-> (Maybe [ReservationUtilizationGroup]
    -> f (Maybe [ReservationUtilizationGroup]))
-> UtilizationByTime
-> f UtilizationByTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [ReservationUtilizationGroup]
  [ReservationUtilizationGroup]
  [ReservationUtilizationGroup]
  [ReservationUtilizationGroup]
-> Iso
     (Maybe [ReservationUtilizationGroup])
     (Maybe [ReservationUtilizationGroup])
     (Maybe [ReservationUtilizationGroup])
     (Maybe [ReservationUtilizationGroup])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [ReservationUtilizationGroup]
  [ReservationUtilizationGroup]
  [ReservationUtilizationGroup]
  [ReservationUtilizationGroup]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The period of time that this utilization was used for.
utilizationByTime_timePeriod :: Lens.Lens' UtilizationByTime (Prelude.Maybe DateInterval)
utilizationByTime_timePeriod :: (Maybe DateInterval -> f (Maybe DateInterval))
-> UtilizationByTime -> f UtilizationByTime
utilizationByTime_timePeriod = (UtilizationByTime -> Maybe DateInterval)
-> (UtilizationByTime -> Maybe DateInterval -> UtilizationByTime)
-> Lens
     UtilizationByTime
     UtilizationByTime
     (Maybe DateInterval)
     (Maybe DateInterval)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UtilizationByTime' {Maybe DateInterval
timePeriod :: Maybe DateInterval
$sel:timePeriod:UtilizationByTime' :: UtilizationByTime -> Maybe DateInterval
timePeriod} -> Maybe DateInterval
timePeriod) (\s :: UtilizationByTime
s@UtilizationByTime' {} Maybe DateInterval
a -> UtilizationByTime
s {$sel:timePeriod:UtilizationByTime' :: Maybe DateInterval
timePeriod = Maybe DateInterval
a} :: UtilizationByTime)

-- | The total number of reservation hours that were used.
utilizationByTime_total :: Lens.Lens' UtilizationByTime (Prelude.Maybe ReservationAggregates)
utilizationByTime_total :: (Maybe ReservationAggregates -> f (Maybe ReservationAggregates))
-> UtilizationByTime -> f UtilizationByTime
utilizationByTime_total = (UtilizationByTime -> Maybe ReservationAggregates)
-> (UtilizationByTime
    -> Maybe ReservationAggregates -> UtilizationByTime)
-> Lens
     UtilizationByTime
     UtilizationByTime
     (Maybe ReservationAggregates)
     (Maybe ReservationAggregates)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UtilizationByTime' {Maybe ReservationAggregates
total :: Maybe ReservationAggregates
$sel:total:UtilizationByTime' :: UtilizationByTime -> Maybe ReservationAggregates
total} -> Maybe ReservationAggregates
total) (\s :: UtilizationByTime
s@UtilizationByTime' {} Maybe ReservationAggregates
a -> UtilizationByTime
s {$sel:total:UtilizationByTime' :: Maybe ReservationAggregates
total = Maybe ReservationAggregates
a} :: UtilizationByTime)

instance Core.FromJSON UtilizationByTime where
  parseJSON :: Value -> Parser UtilizationByTime
parseJSON =
    String
-> (Object -> Parser UtilizationByTime)
-> Value
-> Parser UtilizationByTime
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"UtilizationByTime"
      ( \Object
x ->
          Maybe [ReservationUtilizationGroup]
-> Maybe DateInterval
-> Maybe ReservationAggregates
-> UtilizationByTime
UtilizationByTime'
            (Maybe [ReservationUtilizationGroup]
 -> Maybe DateInterval
 -> Maybe ReservationAggregates
 -> UtilizationByTime)
-> Parser (Maybe [ReservationUtilizationGroup])
-> Parser
     (Maybe DateInterval
      -> Maybe ReservationAggregates -> UtilizationByTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object
-> Text -> Parser (Maybe (Maybe [ReservationUtilizationGroup]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Groups" Parser (Maybe (Maybe [ReservationUtilizationGroup]))
-> Maybe [ReservationUtilizationGroup]
-> Parser (Maybe [ReservationUtilizationGroup])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [ReservationUtilizationGroup]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe DateInterval
   -> Maybe ReservationAggregates -> UtilizationByTime)
-> Parser (Maybe DateInterval)
-> Parser (Maybe ReservationAggregates -> UtilizationByTime)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe DateInterval)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"TimePeriod")
            Parser (Maybe ReservationAggregates -> UtilizationByTime)
-> Parser (Maybe ReservationAggregates) -> Parser UtilizationByTime
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ReservationAggregates)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Total")
      )

instance Prelude.Hashable UtilizationByTime

instance Prelude.NFData UtilizationByTime