{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CostExplorer.Types.DateInterval 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 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
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]
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
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. 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' {$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 :: Lens' DateInterval Text
dateInterval_start = 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 :: Lens' DateInterval Text
dateInterval_end = 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 Data.FromJSON DateInterval where
  parseJSON :: Value -> Parser DateInterval
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DateInterval"
      ( \Object
x ->
          Text -> Text -> DateInterval
DateInterval'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Start")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"End")
      )

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

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

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Start" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
start),
            forall a. a -> Maybe a
Prelude.Just (Key
"End" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
end)
          ]
      )