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

import qualified Amazonka.Core as Core
import Amazonka.CostExplorer.Types.DateInterval
import Amazonka.CostExplorer.Types.Group
import Amazonka.CostExplorer.Types.MetricValue
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The result that\'s associated with a time period.
--
-- /See:/ 'newResultByTime' smart constructor.
data ResultByTime = ResultByTime'
  { -- | The groups that this time period includes.
    ResultByTime -> Maybe [Group]
groups :: Prelude.Maybe [Group],
    -- | The time period that the result covers.
    ResultByTime -> Maybe DateInterval
timePeriod :: Prelude.Maybe DateInterval,
    -- | The total amount of cost or usage accrued during the time period.
    ResultByTime -> Maybe (HashMap Text MetricValue)
total :: Prelude.Maybe (Prelude.HashMap Prelude.Text MetricValue),
    -- | Determines whether the result is estimated.
    ResultByTime -> Maybe Bool
estimated :: Prelude.Maybe Prelude.Bool
  }
  deriving (ResultByTime -> ResultByTime -> Bool
(ResultByTime -> ResultByTime -> Bool)
-> (ResultByTime -> ResultByTime -> Bool) -> Eq ResultByTime
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResultByTime -> ResultByTime -> Bool
$c/= :: ResultByTime -> ResultByTime -> Bool
== :: ResultByTime -> ResultByTime -> Bool
$c== :: ResultByTime -> ResultByTime -> Bool
Prelude.Eq, ReadPrec [ResultByTime]
ReadPrec ResultByTime
Int -> ReadS ResultByTime
ReadS [ResultByTime]
(Int -> ReadS ResultByTime)
-> ReadS [ResultByTime]
-> ReadPrec ResultByTime
-> ReadPrec [ResultByTime]
-> Read ResultByTime
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResultByTime]
$creadListPrec :: ReadPrec [ResultByTime]
readPrec :: ReadPrec ResultByTime
$creadPrec :: ReadPrec ResultByTime
readList :: ReadS [ResultByTime]
$creadList :: ReadS [ResultByTime]
readsPrec :: Int -> ReadS ResultByTime
$creadsPrec :: Int -> ReadS ResultByTime
Prelude.Read, Int -> ResultByTime -> ShowS
[ResultByTime] -> ShowS
ResultByTime -> String
(Int -> ResultByTime -> ShowS)
-> (ResultByTime -> String)
-> ([ResultByTime] -> ShowS)
-> Show ResultByTime
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResultByTime] -> ShowS
$cshowList :: [ResultByTime] -> ShowS
show :: ResultByTime -> String
$cshow :: ResultByTime -> String
showsPrec :: Int -> ResultByTime -> ShowS
$cshowsPrec :: Int -> ResultByTime -> ShowS
Prelude.Show, (forall x. ResultByTime -> Rep ResultByTime x)
-> (forall x. Rep ResultByTime x -> ResultByTime)
-> Generic ResultByTime
forall x. Rep ResultByTime x -> ResultByTime
forall x. ResultByTime -> Rep ResultByTime x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResultByTime x -> ResultByTime
$cfrom :: forall x. ResultByTime -> Rep ResultByTime x
Prelude.Generic)

-- |
-- Create a value of 'ResultByTime' 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', 'resultByTime_groups' - The groups that this time period includes.
--
-- 'timePeriod', 'resultByTime_timePeriod' - The time period that the result covers.
--
-- 'total', 'resultByTime_total' - The total amount of cost or usage accrued during the time period.
--
-- 'estimated', 'resultByTime_estimated' - Determines whether the result is estimated.
newResultByTime ::
  ResultByTime
newResultByTime :: ResultByTime
newResultByTime =
  ResultByTime' :: Maybe [Group]
-> Maybe DateInterval
-> Maybe (HashMap Text MetricValue)
-> Maybe Bool
-> ResultByTime
ResultByTime'
    { $sel:groups:ResultByTime' :: Maybe [Group]
groups = Maybe [Group]
forall a. Maybe a
Prelude.Nothing,
      $sel:timePeriod:ResultByTime' :: Maybe DateInterval
timePeriod = Maybe DateInterval
forall a. Maybe a
Prelude.Nothing,
      $sel:total:ResultByTime' :: Maybe (HashMap Text MetricValue)
total = Maybe (HashMap Text MetricValue)
forall a. Maybe a
Prelude.Nothing,
      $sel:estimated:ResultByTime' :: Maybe Bool
estimated = Maybe Bool
forall a. Maybe a
Prelude.Nothing
    }

-- | The groups that this time period includes.
resultByTime_groups :: Lens.Lens' ResultByTime (Prelude.Maybe [Group])
resultByTime_groups :: (Maybe [Group] -> f (Maybe [Group]))
-> ResultByTime -> f ResultByTime
resultByTime_groups = (ResultByTime -> Maybe [Group])
-> (ResultByTime -> Maybe [Group] -> ResultByTime)
-> Lens ResultByTime ResultByTime (Maybe [Group]) (Maybe [Group])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResultByTime' {Maybe [Group]
groups :: Maybe [Group]
$sel:groups:ResultByTime' :: ResultByTime -> Maybe [Group]
groups} -> Maybe [Group]
groups) (\s :: ResultByTime
s@ResultByTime' {} Maybe [Group]
a -> ResultByTime
s {$sel:groups:ResultByTime' :: Maybe [Group]
groups = Maybe [Group]
a} :: ResultByTime) ((Maybe [Group] -> f (Maybe [Group]))
 -> ResultByTime -> f ResultByTime)
-> ((Maybe [Group] -> f (Maybe [Group]))
    -> Maybe [Group] -> f (Maybe [Group]))
-> (Maybe [Group] -> f (Maybe [Group]))
-> ResultByTime
-> f ResultByTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Group] [Group] [Group] [Group]
-> Iso
     (Maybe [Group]) (Maybe [Group]) (Maybe [Group]) (Maybe [Group])
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 [Group] [Group] [Group] [Group]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The time period that the result covers.
resultByTime_timePeriod :: Lens.Lens' ResultByTime (Prelude.Maybe DateInterval)
resultByTime_timePeriod :: (Maybe DateInterval -> f (Maybe DateInterval))
-> ResultByTime -> f ResultByTime
resultByTime_timePeriod = (ResultByTime -> Maybe DateInterval)
-> (ResultByTime -> Maybe DateInterval -> ResultByTime)
-> Lens
     ResultByTime ResultByTime (Maybe DateInterval) (Maybe DateInterval)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResultByTime' {Maybe DateInterval
timePeriod :: Maybe DateInterval
$sel:timePeriod:ResultByTime' :: ResultByTime -> Maybe DateInterval
timePeriod} -> Maybe DateInterval
timePeriod) (\s :: ResultByTime
s@ResultByTime' {} Maybe DateInterval
a -> ResultByTime
s {$sel:timePeriod:ResultByTime' :: Maybe DateInterval
timePeriod = Maybe DateInterval
a} :: ResultByTime)

-- | The total amount of cost or usage accrued during the time period.
resultByTime_total :: Lens.Lens' ResultByTime (Prelude.Maybe (Prelude.HashMap Prelude.Text MetricValue))
resultByTime_total :: (Maybe (HashMap Text MetricValue)
 -> f (Maybe (HashMap Text MetricValue)))
-> ResultByTime -> f ResultByTime
resultByTime_total = (ResultByTime -> Maybe (HashMap Text MetricValue))
-> (ResultByTime
    -> Maybe (HashMap Text MetricValue) -> ResultByTime)
-> Lens
     ResultByTime
     ResultByTime
     (Maybe (HashMap Text MetricValue))
     (Maybe (HashMap Text MetricValue))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResultByTime' {Maybe (HashMap Text MetricValue)
total :: Maybe (HashMap Text MetricValue)
$sel:total:ResultByTime' :: ResultByTime -> Maybe (HashMap Text MetricValue)
total} -> Maybe (HashMap Text MetricValue)
total) (\s :: ResultByTime
s@ResultByTime' {} Maybe (HashMap Text MetricValue)
a -> ResultByTime
s {$sel:total:ResultByTime' :: Maybe (HashMap Text MetricValue)
total = Maybe (HashMap Text MetricValue)
a} :: ResultByTime) ((Maybe (HashMap Text MetricValue)
  -> f (Maybe (HashMap Text MetricValue)))
 -> ResultByTime -> f ResultByTime)
-> ((Maybe (HashMap Text MetricValue)
     -> f (Maybe (HashMap Text MetricValue)))
    -> Maybe (HashMap Text MetricValue)
    -> f (Maybe (HashMap Text MetricValue)))
-> (Maybe (HashMap Text MetricValue)
    -> f (Maybe (HashMap Text MetricValue)))
-> ResultByTime
-> f ResultByTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text MetricValue)
  (HashMap Text MetricValue)
  (HashMap Text MetricValue)
  (HashMap Text MetricValue)
-> Iso
     (Maybe (HashMap Text MetricValue))
     (Maybe (HashMap Text MetricValue))
     (Maybe (HashMap Text MetricValue))
     (Maybe (HashMap Text MetricValue))
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
  (HashMap Text MetricValue)
  (HashMap Text MetricValue)
  (HashMap Text MetricValue)
  (HashMap Text MetricValue)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Determines whether the result is estimated.
resultByTime_estimated :: Lens.Lens' ResultByTime (Prelude.Maybe Prelude.Bool)
resultByTime_estimated :: (Maybe Bool -> f (Maybe Bool)) -> ResultByTime -> f ResultByTime
resultByTime_estimated = (ResultByTime -> Maybe Bool)
-> (ResultByTime -> Maybe Bool -> ResultByTime)
-> Lens ResultByTime ResultByTime (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResultByTime' {Maybe Bool
estimated :: Maybe Bool
$sel:estimated:ResultByTime' :: ResultByTime -> Maybe Bool
estimated} -> Maybe Bool
estimated) (\s :: ResultByTime
s@ResultByTime' {} Maybe Bool
a -> ResultByTime
s {$sel:estimated:ResultByTime' :: Maybe Bool
estimated = Maybe Bool
a} :: ResultByTime)

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

instance Prelude.Hashable ResultByTime

instance Prelude.NFData ResultByTime