{-# 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.TimePeriod
-- 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.Budgets.Types.TimePeriod 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 period of time that\'s covered by a budget. The period has a start
-- date and an end date. The start date must come before the end date.
-- There are no restrictions on the end date.
--
-- /See:/ 'newTimePeriod' smart constructor.
data TimePeriod = TimePeriod'
  { -- | The end date for a budget. If you didn\'t specify an end date, Amazon
    -- Web Services set your end date to @06\/15\/87 00:00 UTC@. The defaults
    -- are the same for the Billing and Cost Management console and the API.
    --
    -- After the end date, Amazon Web Services deletes the budget and all the
    -- associated notifications and subscribers. You can change your end date
    -- with the @UpdateBudget@ operation.
    TimePeriod -> Maybe POSIX
end :: Prelude.Maybe Data.POSIX,
    -- | The start date for a budget. If you created your budget and didn\'t
    -- specify a start date, Amazon Web Services defaults to the start of your
    -- chosen time period (DAILY, MONTHLY, QUARTERLY, or ANNUALLY). For
    -- example, if you created your budget on January 24, 2018, chose @DAILY@,
    -- and didn\'t set a start date, Amazon Web Services set your start date to
    -- @01\/24\/18 00:00 UTC@. If you chose @MONTHLY@, Amazon Web Services set
    -- your start date to @01\/01\/18 00:00 UTC@. The defaults are the same for
    -- the Billing and Cost Management console and the API.
    --
    -- You can change your start date with the @UpdateBudget@ operation.
    TimePeriod -> Maybe POSIX
start :: Prelude.Maybe Data.POSIX
  }
  deriving (TimePeriod -> TimePeriod -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TimePeriod -> TimePeriod -> Bool
$c/= :: TimePeriod -> TimePeriod -> Bool
== :: TimePeriod -> TimePeriod -> Bool
$c== :: TimePeriod -> TimePeriod -> Bool
Prelude.Eq, ReadPrec [TimePeriod]
ReadPrec TimePeriod
Int -> ReadS TimePeriod
ReadS [TimePeriod]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TimePeriod]
$creadListPrec :: ReadPrec [TimePeriod]
readPrec :: ReadPrec TimePeriod
$creadPrec :: ReadPrec TimePeriod
readList :: ReadS [TimePeriod]
$creadList :: ReadS [TimePeriod]
readsPrec :: Int -> ReadS TimePeriod
$creadsPrec :: Int -> ReadS TimePeriod
Prelude.Read, Int -> TimePeriod -> ShowS
[TimePeriod] -> ShowS
TimePeriod -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TimePeriod] -> ShowS
$cshowList :: [TimePeriod] -> ShowS
show :: TimePeriod -> String
$cshow :: TimePeriod -> String
showsPrec :: Int -> TimePeriod -> ShowS
$cshowsPrec :: Int -> TimePeriod -> ShowS
Prelude.Show, forall x. Rep TimePeriod x -> TimePeriod
forall x. TimePeriod -> Rep TimePeriod x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TimePeriod x -> TimePeriod
$cfrom :: forall x. TimePeriod -> Rep TimePeriod x
Prelude.Generic)

-- |
-- Create a value of 'TimePeriod' 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:
--
-- 'end', 'timePeriod_end' - The end date for a budget. If you didn\'t specify an end date, Amazon
-- Web Services set your end date to @06\/15\/87 00:00 UTC@. The defaults
-- are the same for the Billing and Cost Management console and the API.
--
-- After the end date, Amazon Web Services deletes the budget and all the
-- associated notifications and subscribers. You can change your end date
-- with the @UpdateBudget@ operation.
--
-- 'start', 'timePeriod_start' - The start date for a budget. If you created your budget and didn\'t
-- specify a start date, Amazon Web Services defaults to the start of your
-- chosen time period (DAILY, MONTHLY, QUARTERLY, or ANNUALLY). For
-- example, if you created your budget on January 24, 2018, chose @DAILY@,
-- and didn\'t set a start date, Amazon Web Services set your start date to
-- @01\/24\/18 00:00 UTC@. If you chose @MONTHLY@, Amazon Web Services set
-- your start date to @01\/01\/18 00:00 UTC@. The defaults are the same for
-- the Billing and Cost Management console and the API.
--
-- You can change your start date with the @UpdateBudget@ operation.
newTimePeriod ::
  TimePeriod
newTimePeriod :: TimePeriod
newTimePeriod =
  TimePeriod'
    { $sel:end:TimePeriod' :: Maybe POSIX
end = forall a. Maybe a
Prelude.Nothing,
      $sel:start:TimePeriod' :: Maybe POSIX
start = forall a. Maybe a
Prelude.Nothing
    }

-- | The end date for a budget. If you didn\'t specify an end date, Amazon
-- Web Services set your end date to @06\/15\/87 00:00 UTC@. The defaults
-- are the same for the Billing and Cost Management console and the API.
--
-- After the end date, Amazon Web Services deletes the budget and all the
-- associated notifications and subscribers. You can change your end date
-- with the @UpdateBudget@ operation.
timePeriod_end :: Lens.Lens' TimePeriod (Prelude.Maybe Prelude.UTCTime)
timePeriod_end :: Lens' TimePeriod (Maybe UTCTime)
timePeriod_end = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimePeriod' {Maybe POSIX
end :: Maybe POSIX
$sel:end:TimePeriod' :: TimePeriod -> Maybe POSIX
end} -> Maybe POSIX
end) (\s :: TimePeriod
s@TimePeriod' {} Maybe POSIX
a -> TimePeriod
s {$sel:end:TimePeriod' :: Maybe POSIX
end = Maybe POSIX
a} :: TimePeriod) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The start date for a budget. If you created your budget and didn\'t
-- specify a start date, Amazon Web Services defaults to the start of your
-- chosen time period (DAILY, MONTHLY, QUARTERLY, or ANNUALLY). For
-- example, if you created your budget on January 24, 2018, chose @DAILY@,
-- and didn\'t set a start date, Amazon Web Services set your start date to
-- @01\/24\/18 00:00 UTC@. If you chose @MONTHLY@, Amazon Web Services set
-- your start date to @01\/01\/18 00:00 UTC@. The defaults are the same for
-- the Billing and Cost Management console and the API.
--
-- You can change your start date with the @UpdateBudget@ operation.
timePeriod_start :: Lens.Lens' TimePeriod (Prelude.Maybe Prelude.UTCTime)
timePeriod_start :: Lens' TimePeriod (Maybe UTCTime)
timePeriod_start = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimePeriod' {Maybe POSIX
start :: Maybe POSIX
$sel:start:TimePeriod' :: TimePeriod -> Maybe POSIX
start} -> Maybe POSIX
start) (\s :: TimePeriod
s@TimePeriod' {} Maybe POSIX
a -> TimePeriod
s {$sel:start:TimePeriod' :: Maybe POSIX
start = Maybe POSIX
a} :: TimePeriod) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

instance Data.FromJSON TimePeriod where
  parseJSON :: Value -> Parser TimePeriod
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"TimePeriod"
      ( \Object
x ->
          Maybe POSIX -> Maybe POSIX -> TimePeriod
TimePeriod'
            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
"End")
            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
"Start")
      )

instance Prelude.Hashable TimePeriod where
  hashWithSalt :: Int -> TimePeriod -> Int
hashWithSalt Int
_salt TimePeriod' {Maybe POSIX
start :: Maybe POSIX
end :: Maybe POSIX
$sel:start:TimePeriod' :: TimePeriod -> Maybe POSIX
$sel:end:TimePeriod' :: TimePeriod -> Maybe POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
end
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
start

instance Prelude.NFData TimePeriod where
  rnf :: TimePeriod -> ()
rnf TimePeriod' {Maybe POSIX
start :: Maybe POSIX
end :: Maybe POSIX
$sel:start:TimePeriod' :: TimePeriod -> Maybe POSIX
$sel:end:TimePeriod' :: TimePeriod -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
end seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
start

instance Data.ToJSON TimePeriod where
  toJSON :: TimePeriod -> Value
toJSON TimePeriod' {Maybe POSIX
start :: Maybe POSIX
end :: Maybe POSIX
$sel:start:TimePeriod' :: TimePeriod -> Maybe POSIX
$sel:end:TimePeriod' :: TimePeriod -> Maybe POSIX
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"End" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe POSIX
end,
            (Key
"Start" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe POSIX
start
          ]
      )