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

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

-- | The time period of the request.
--
-- /See:/ 'newDateInterval' smart constructor.
data DateInterval = DateInterval'
  { -- | The beginning of the time period. The start date is inclusive. For
    -- example, if @start@ is @2017-01-01@, Amazon Web Services retrieves cost
    -- and usage data starting at @2017-01-01@ up to the end date. The start
    -- date must be equal to or no later than the current date to avoid a
    -- validation error.
    DateInterval -> Text
start :: Prelude.Text,
    -- | The end of the time period. The end date is exclusive. For example, if
    -- @end@ is @2017-05-01@, Amazon Web Services retrieves cost and usage data
    -- from the start date up to, but not including, @2017-05-01@.
    DateInterval -> Text
end :: Prelude.Text
  }
  deriving (DateInterval -> DateInterval -> Bool
(DateInterval -> DateInterval -> Bool)
-> (DateInterval -> DateInterval -> Bool) -> Eq DateInterval
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DateInterval -> DateInterval -> Bool
$c/= :: DateInterval -> DateInterval -> Bool
== :: DateInterval -> DateInterval -> Bool
$c== :: DateInterval -> DateInterval -> Bool
Prelude.Eq, ReadPrec [DateInterval]
ReadPrec DateInterval
Int -> ReadS DateInterval
ReadS [DateInterval]
(Int -> ReadS DateInterval)
-> ReadS [DateInterval]
-> ReadPrec DateInterval
-> ReadPrec [DateInterval]
-> Read DateInterval
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DateInterval]
$creadListPrec :: ReadPrec [DateInterval]
readPrec :: ReadPrec DateInterval
$creadPrec :: ReadPrec DateInterval
readList :: ReadS [DateInterval]
$creadList :: ReadS [DateInterval]
readsPrec :: Int -> ReadS DateInterval
$creadsPrec :: Int -> ReadS DateInterval
Prelude.Read, Int -> DateInterval -> ShowS
[DateInterval] -> ShowS
DateInterval -> String
(Int -> DateInterval -> ShowS)
-> (DateInterval -> String)
-> ([DateInterval] -> ShowS)
-> Show DateInterval
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DateInterval] -> ShowS
$cshowList :: [DateInterval] -> ShowS
show :: DateInterval -> String
$cshow :: DateInterval -> String
showsPrec :: Int -> DateInterval -> ShowS
$cshowsPrec :: Int -> DateInterval -> ShowS
Prelude.Show, (forall x. DateInterval -> Rep DateInterval x)
-> (forall x. Rep DateInterval x -> DateInterval)
-> Generic DateInterval
forall x. Rep DateInterval x -> DateInterval
forall x. DateInterval -> Rep DateInterval x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DateInterval x -> DateInterval
$cfrom :: forall x. DateInterval -> Rep DateInterval x
Prelude.Generic)

-- |
-- Create a value of 'DateInterval' 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', 'dateInterval_start' - The beginning of the time period. The start date is inclusive. For
-- example, if @start@ is @2017-01-01@, Amazon Web Services retrieves cost
-- and usage data starting at @2017-01-01@ up to the end date. The start
-- date must be equal to or no later than the current date to avoid a
-- validation error.
--
-- 'end', 'dateInterval_end' - The end of the time period. The end date is exclusive. For example, if
-- @end@ is @2017-05-01@, Amazon Web Services retrieves cost and usage data
-- from the start date up to, but not including, @2017-05-01@.
newDateInterval ::
  -- | 'start'
  Prelude.Text ->
  -- | 'end'
  Prelude.Text ->
  DateInterval
newDateInterval :: Text -> Text -> DateInterval
newDateInterval Text
pStart_ Text
pEnd_ =
  DateInterval' :: Text -> Text -> DateInterval
DateInterval' {$sel:start:DateInterval' :: Text
start = Text
pStart_, $sel:end:DateInterval' :: Text
end = Text
pEnd_}

-- | The beginning of the time period. The start date is inclusive. For
-- example, if @start@ is @2017-01-01@, Amazon Web Services retrieves cost
-- and usage data starting at @2017-01-01@ up to the end date. The start
-- date must be equal to or no later than the current date to avoid a
-- validation error.
dateInterval_start :: Lens.Lens' DateInterval Prelude.Text
dateInterval_start :: (Text -> f Text) -> DateInterval -> f DateInterval
dateInterval_start = (DateInterval -> Text)
-> (DateInterval -> Text -> DateInterval)
-> Lens DateInterval DateInterval Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DateInterval' {Text
start :: Text
$sel:start:DateInterval' :: DateInterval -> Text
start} -> Text
start) (\s :: DateInterval
s@DateInterval' {} Text
a -> DateInterval
s {$sel:start:DateInterval' :: Text
start = Text
a} :: DateInterval)

-- | The end of the time period. The end date is exclusive. For example, if
-- @end@ is @2017-05-01@, Amazon Web Services retrieves cost and usage data
-- from the start date up to, but not including, @2017-05-01@.
dateInterval_end :: Lens.Lens' DateInterval Prelude.Text
dateInterval_end :: (Text -> f Text) -> DateInterval -> f DateInterval
dateInterval_end = (DateInterval -> Text)
-> (DateInterval -> Text -> DateInterval)
-> Lens DateInterval DateInterval Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DateInterval' {Text
end :: Text
$sel:end:DateInterval' :: DateInterval -> Text
end} -> Text
end) (\s :: DateInterval
s@DateInterval' {} Text
a -> DateInterval
s {$sel:end:DateInterval' :: Text
end = Text
a} :: DateInterval)

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

instance Prelude.Hashable DateInterval

instance Prelude.NFData DateInterval

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