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

import qualified Amazonka.Core as Core
import Amazonka.CostExplorer.Types.Coverage
import Amazonka.CostExplorer.Types.DateInterval
import Amazonka.CostExplorer.Types.ReservationCoverageGroup
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Reservation coverage for a specified period, in hours.
--
-- /See:/ 'newCoverageByTime' smart constructor.
data CoverageByTime = CoverageByTime'
  { -- | The groups of instances that the reservation covered.
    CoverageByTime -> Maybe [ReservationCoverageGroup]
groups :: Prelude.Maybe [ReservationCoverageGroup],
    -- | The period that this coverage was used over.
    CoverageByTime -> Maybe DateInterval
timePeriod :: Prelude.Maybe DateInterval,
    -- | The total reservation coverage, in hours.
    CoverageByTime -> Maybe Coverage
total :: Prelude.Maybe Coverage
  }
  deriving (CoverageByTime -> CoverageByTime -> Bool
(CoverageByTime -> CoverageByTime -> Bool)
-> (CoverageByTime -> CoverageByTime -> Bool) -> Eq CoverageByTime
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoverageByTime -> CoverageByTime -> Bool
$c/= :: CoverageByTime -> CoverageByTime -> Bool
== :: CoverageByTime -> CoverageByTime -> Bool
$c== :: CoverageByTime -> CoverageByTime -> Bool
Prelude.Eq, ReadPrec [CoverageByTime]
ReadPrec CoverageByTime
Int -> ReadS CoverageByTime
ReadS [CoverageByTime]
(Int -> ReadS CoverageByTime)
-> ReadS [CoverageByTime]
-> ReadPrec CoverageByTime
-> ReadPrec [CoverageByTime]
-> Read CoverageByTime
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CoverageByTime]
$creadListPrec :: ReadPrec [CoverageByTime]
readPrec :: ReadPrec CoverageByTime
$creadPrec :: ReadPrec CoverageByTime
readList :: ReadS [CoverageByTime]
$creadList :: ReadS [CoverageByTime]
readsPrec :: Int -> ReadS CoverageByTime
$creadsPrec :: Int -> ReadS CoverageByTime
Prelude.Read, Int -> CoverageByTime -> ShowS
[CoverageByTime] -> ShowS
CoverageByTime -> String
(Int -> CoverageByTime -> ShowS)
-> (CoverageByTime -> String)
-> ([CoverageByTime] -> ShowS)
-> Show CoverageByTime
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoverageByTime] -> ShowS
$cshowList :: [CoverageByTime] -> ShowS
show :: CoverageByTime -> String
$cshow :: CoverageByTime -> String
showsPrec :: Int -> CoverageByTime -> ShowS
$cshowsPrec :: Int -> CoverageByTime -> ShowS
Prelude.Show, (forall x. CoverageByTime -> Rep CoverageByTime x)
-> (forall x. Rep CoverageByTime x -> CoverageByTime)
-> Generic CoverageByTime
forall x. Rep CoverageByTime x -> CoverageByTime
forall x. CoverageByTime -> Rep CoverageByTime x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CoverageByTime x -> CoverageByTime
$cfrom :: forall x. CoverageByTime -> Rep CoverageByTime x
Prelude.Generic)

-- |
-- Create a value of 'CoverageByTime' 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', 'coverageByTime_groups' - The groups of instances that the reservation covered.
--
-- 'timePeriod', 'coverageByTime_timePeriod' - The period that this coverage was used over.
--
-- 'total', 'coverageByTime_total' - The total reservation coverage, in hours.
newCoverageByTime ::
  CoverageByTime
newCoverageByTime :: CoverageByTime
newCoverageByTime =
  CoverageByTime' :: Maybe [ReservationCoverageGroup]
-> Maybe DateInterval -> Maybe Coverage -> CoverageByTime
CoverageByTime'
    { $sel:groups:CoverageByTime' :: Maybe [ReservationCoverageGroup]
groups = Maybe [ReservationCoverageGroup]
forall a. Maybe a
Prelude.Nothing,
      $sel:timePeriod:CoverageByTime' :: Maybe DateInterval
timePeriod = Maybe DateInterval
forall a. Maybe a
Prelude.Nothing,
      $sel:total:CoverageByTime' :: Maybe Coverage
total = Maybe Coverage
forall a. Maybe a
Prelude.Nothing
    }

-- | The groups of instances that the reservation covered.
coverageByTime_groups :: Lens.Lens' CoverageByTime (Prelude.Maybe [ReservationCoverageGroup])
coverageByTime_groups :: (Maybe [ReservationCoverageGroup]
 -> f (Maybe [ReservationCoverageGroup]))
-> CoverageByTime -> f CoverageByTime
coverageByTime_groups = (CoverageByTime -> Maybe [ReservationCoverageGroup])
-> (CoverageByTime
    -> Maybe [ReservationCoverageGroup] -> CoverageByTime)
-> Lens
     CoverageByTime
     CoverageByTime
     (Maybe [ReservationCoverageGroup])
     (Maybe [ReservationCoverageGroup])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CoverageByTime' {Maybe [ReservationCoverageGroup]
groups :: Maybe [ReservationCoverageGroup]
$sel:groups:CoverageByTime' :: CoverageByTime -> Maybe [ReservationCoverageGroup]
groups} -> Maybe [ReservationCoverageGroup]
groups) (\s :: CoverageByTime
s@CoverageByTime' {} Maybe [ReservationCoverageGroup]
a -> CoverageByTime
s {$sel:groups:CoverageByTime' :: Maybe [ReservationCoverageGroup]
groups = Maybe [ReservationCoverageGroup]
a} :: CoverageByTime) ((Maybe [ReservationCoverageGroup]
  -> f (Maybe [ReservationCoverageGroup]))
 -> CoverageByTime -> f CoverageByTime)
-> ((Maybe [ReservationCoverageGroup]
     -> f (Maybe [ReservationCoverageGroup]))
    -> Maybe [ReservationCoverageGroup]
    -> f (Maybe [ReservationCoverageGroup]))
-> (Maybe [ReservationCoverageGroup]
    -> f (Maybe [ReservationCoverageGroup]))
-> CoverageByTime
-> f CoverageByTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [ReservationCoverageGroup]
  [ReservationCoverageGroup]
  [ReservationCoverageGroup]
  [ReservationCoverageGroup]
-> Iso
     (Maybe [ReservationCoverageGroup])
     (Maybe [ReservationCoverageGroup])
     (Maybe [ReservationCoverageGroup])
     (Maybe [ReservationCoverageGroup])
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
  [ReservationCoverageGroup]
  [ReservationCoverageGroup]
  [ReservationCoverageGroup]
  [ReservationCoverageGroup]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The period that this coverage was used over.
coverageByTime_timePeriod :: Lens.Lens' CoverageByTime (Prelude.Maybe DateInterval)
coverageByTime_timePeriod :: (Maybe DateInterval -> f (Maybe DateInterval))
-> CoverageByTime -> f CoverageByTime
coverageByTime_timePeriod = (CoverageByTime -> Maybe DateInterval)
-> (CoverageByTime -> Maybe DateInterval -> CoverageByTime)
-> Lens
     CoverageByTime
     CoverageByTime
     (Maybe DateInterval)
     (Maybe DateInterval)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CoverageByTime' {Maybe DateInterval
timePeriod :: Maybe DateInterval
$sel:timePeriod:CoverageByTime' :: CoverageByTime -> Maybe DateInterval
timePeriod} -> Maybe DateInterval
timePeriod) (\s :: CoverageByTime
s@CoverageByTime' {} Maybe DateInterval
a -> CoverageByTime
s {$sel:timePeriod:CoverageByTime' :: Maybe DateInterval
timePeriod = Maybe DateInterval
a} :: CoverageByTime)

-- | The total reservation coverage, in hours.
coverageByTime_total :: Lens.Lens' CoverageByTime (Prelude.Maybe Coverage)
coverageByTime_total :: (Maybe Coverage -> f (Maybe Coverage))
-> CoverageByTime -> f CoverageByTime
coverageByTime_total = (CoverageByTime -> Maybe Coverage)
-> (CoverageByTime -> Maybe Coverage -> CoverageByTime)
-> Lens
     CoverageByTime CoverageByTime (Maybe Coverage) (Maybe Coverage)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CoverageByTime' {Maybe Coverage
total :: Maybe Coverage
$sel:total:CoverageByTime' :: CoverageByTime -> Maybe Coverage
total} -> Maybe Coverage
total) (\s :: CoverageByTime
s@CoverageByTime' {} Maybe Coverage
a -> CoverageByTime
s {$sel:total:CoverageByTime' :: Maybe Coverage
total = Maybe Coverage
a} :: CoverageByTime)

instance Core.FromJSON CoverageByTime where
  parseJSON :: Value -> Parser CoverageByTime
parseJSON =
    String
-> (Object -> Parser CoverageByTime)
-> Value
-> Parser CoverageByTime
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CoverageByTime"
      ( \Object
x ->
          Maybe [ReservationCoverageGroup]
-> Maybe DateInterval -> Maybe Coverage -> CoverageByTime
CoverageByTime'
            (Maybe [ReservationCoverageGroup]
 -> Maybe DateInterval -> Maybe Coverage -> CoverageByTime)
-> Parser (Maybe [ReservationCoverageGroup])
-> Parser (Maybe DateInterval -> Maybe Coverage -> CoverageByTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [ReservationCoverageGroup]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Groups" Parser (Maybe (Maybe [ReservationCoverageGroup]))
-> Maybe [ReservationCoverageGroup]
-> Parser (Maybe [ReservationCoverageGroup])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [ReservationCoverageGroup]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe DateInterval -> Maybe Coverage -> CoverageByTime)
-> Parser (Maybe DateInterval)
-> Parser (Maybe Coverage -> CoverageByTime)
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 Coverage -> CoverageByTime)
-> Parser (Maybe Coverage) -> Parser CoverageByTime
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Coverage)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Total")
      )

instance Prelude.Hashable CoverageByTime

instance Prelude.NFData CoverageByTime