{-# 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-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.Budgets.Types.TimePeriod where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The period of time that is 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 start date for a budget. If you created your budget and didn\'t
    -- specify a start date, AWS 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, AWS set your start date to @01\/24\/18 00:00 UTC@. If you
    -- chose @MONTHLY@, AWS set your start date to @01\/01\/18 00:00 UTC@. The
    -- defaults are the same for the AWS Billing and Cost Management console
    -- and the API.
    --
    -- You can change your start date with the @UpdateBudget@ operation.
    TimePeriod -> Maybe POSIX
start :: Prelude.Maybe Core.POSIX,
    -- | The end date for a budget. If you didn\'t specify an end date, AWS set
    -- your end date to @06\/15\/87 00:00 UTC@. The defaults are the same for
    -- the AWS Billing and Cost Management console and the API.
    --
    -- After the end date, AWS deletes the budget and all associated
    -- notifications and subscribers. You can change your end date with the
    -- @UpdateBudget@ operation.
    TimePeriod -> Maybe POSIX
end :: Prelude.Maybe Core.POSIX
  }
  deriving (TimePeriod -> TimePeriod -> Bool
(TimePeriod -> TimePeriod -> Bool)
-> (TimePeriod -> TimePeriod -> Bool) -> Eq TimePeriod
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]
(Int -> ReadS TimePeriod)
-> ReadS [TimePeriod]
-> ReadPrec TimePeriod
-> ReadPrec [TimePeriod]
-> Read 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
(Int -> TimePeriod -> ShowS)
-> (TimePeriod -> String)
-> ([TimePeriod] -> ShowS)
-> Show TimePeriod
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. TimePeriod -> Rep TimePeriod x)
-> (forall x. Rep TimePeriod x -> TimePeriod) -> Generic TimePeriod
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:
--
-- 'start', 'timePeriod_start' - The start date for a budget. If you created your budget and didn\'t
-- specify a start date, AWS 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, AWS set your start date to @01\/24\/18 00:00 UTC@. If you
-- chose @MONTHLY@, AWS set your start date to @01\/01\/18 00:00 UTC@. The
-- defaults are the same for the AWS Billing and Cost Management console
-- and the API.
--
-- You can change your start date with the @UpdateBudget@ operation.
--
-- 'end', 'timePeriod_end' - The end date for a budget. If you didn\'t specify an end date, AWS set
-- your end date to @06\/15\/87 00:00 UTC@. The defaults are the same for
-- the AWS Billing and Cost Management console and the API.
--
-- After the end date, AWS deletes the budget and all associated
-- notifications and subscribers. You can change your end date with the
-- @UpdateBudget@ operation.
newTimePeriod ::
  TimePeriod
newTimePeriod :: TimePeriod
newTimePeriod =
  TimePeriod' :: Maybe POSIX -> Maybe POSIX -> TimePeriod
TimePeriod'
    { $sel:start:TimePeriod' :: Maybe POSIX
start = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:end:TimePeriod' :: Maybe POSIX
end = Maybe POSIX
forall a. Maybe a
Prelude.Nothing
    }

-- | The start date for a budget. If you created your budget and didn\'t
-- specify a start date, AWS 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, AWS set your start date to @01\/24\/18 00:00 UTC@. If you
-- chose @MONTHLY@, AWS set your start date to @01\/01\/18 00:00 UTC@. The
-- defaults are the same for the AWS 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 :: (Maybe UTCTime -> f (Maybe UTCTime)) -> TimePeriod -> f TimePeriod
timePeriod_start = (TimePeriod -> Maybe POSIX)
-> (TimePeriod -> Maybe POSIX -> TimePeriod)
-> Lens TimePeriod TimePeriod (Maybe POSIX) (Maybe POSIX)
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) ((Maybe POSIX -> f (Maybe POSIX)) -> TimePeriod -> f TimePeriod)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> TimePeriod
-> f TimePeriod
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The end date for a budget. If you didn\'t specify an end date, AWS set
-- your end date to @06\/15\/87 00:00 UTC@. The defaults are the same for
-- the AWS Billing and Cost Management console and the API.
--
-- After the end date, AWS deletes the budget and all 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 :: (Maybe UTCTime -> f (Maybe UTCTime)) -> TimePeriod -> f TimePeriod
timePeriod_end = (TimePeriod -> Maybe POSIX)
-> (TimePeriod -> Maybe POSIX -> TimePeriod)
-> Lens TimePeriod TimePeriod (Maybe POSIX) (Maybe POSIX)
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) ((Maybe POSIX -> f (Maybe POSIX)) -> TimePeriod -> f TimePeriod)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> TimePeriod
-> f TimePeriod
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

instance Core.FromJSON TimePeriod where
  parseJSON :: Value -> Parser TimePeriod
parseJSON =
    String
-> (Object -> Parser TimePeriod) -> Value -> Parser TimePeriod
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TimePeriod"
      ( \Object
x ->
          Maybe POSIX -> Maybe POSIX -> TimePeriod
TimePeriod'
            (Maybe POSIX -> Maybe POSIX -> TimePeriod)
-> Parser (Maybe POSIX) -> Parser (Maybe POSIX -> TimePeriod)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Start") Parser (Maybe POSIX -> TimePeriod)
-> Parser (Maybe POSIX) -> Parser TimePeriod
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"End")
      )

instance Prelude.Hashable TimePeriod

instance Prelude.NFData TimePeriod

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