{-# 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.AWSHealth.Types.DateTimeRange
-- 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.AWSHealth.Types.DateTimeRange 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

-- | A range of dates and times that is used by the
-- <https://docs.aws.amazon.com/health/latest/APIReference/API_EventFilter.html EventFilter>
-- and
-- <https://docs.aws.amazon.com/health/latest/APIReference/API_EntityFilter.html EntityFilter>
-- objects. If @from@ is set and @to@ is set: match items where the
-- timestamp (@startTime@, @endTime@, or @lastUpdatedTime@) is between
-- @from@ and @to@ inclusive. If @from@ is set and @to@ is not set: match
-- items where the timestamp value is equal to or after @from@. If @from@
-- is not set and @to@ is set: match items where the timestamp value is
-- equal to or before @to@.
--
-- /See:/ 'newDateTimeRange' smart constructor.
data DateTimeRange = DateTimeRange'
  { -- | The starting date and time of a time range.
    DateTimeRange -> Maybe POSIX
from :: Prelude.Maybe Data.POSIX,
    -- | The ending date and time of a time range.
    DateTimeRange -> Maybe POSIX
to :: Prelude.Maybe Data.POSIX
  }
  deriving (DateTimeRange -> DateTimeRange -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DateTimeRange -> DateTimeRange -> Bool
$c/= :: DateTimeRange -> DateTimeRange -> Bool
== :: DateTimeRange -> DateTimeRange -> Bool
$c== :: DateTimeRange -> DateTimeRange -> Bool
Prelude.Eq, ReadPrec [DateTimeRange]
ReadPrec DateTimeRange
Int -> ReadS DateTimeRange
ReadS [DateTimeRange]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DateTimeRange]
$creadListPrec :: ReadPrec [DateTimeRange]
readPrec :: ReadPrec DateTimeRange
$creadPrec :: ReadPrec DateTimeRange
readList :: ReadS [DateTimeRange]
$creadList :: ReadS [DateTimeRange]
readsPrec :: Int -> ReadS DateTimeRange
$creadsPrec :: Int -> ReadS DateTimeRange
Prelude.Read, Int -> DateTimeRange -> ShowS
[DateTimeRange] -> ShowS
DateTimeRange -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DateTimeRange] -> ShowS
$cshowList :: [DateTimeRange] -> ShowS
show :: DateTimeRange -> String
$cshow :: DateTimeRange -> String
showsPrec :: Int -> DateTimeRange -> ShowS
$cshowsPrec :: Int -> DateTimeRange -> ShowS
Prelude.Show, forall x. Rep DateTimeRange x -> DateTimeRange
forall x. DateTimeRange -> Rep DateTimeRange x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DateTimeRange x -> DateTimeRange
$cfrom :: forall x. DateTimeRange -> Rep DateTimeRange x
Prelude.Generic)

-- |
-- Create a value of 'DateTimeRange' 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:
--
-- 'from', 'dateTimeRange_from' - The starting date and time of a time range.
--
-- 'to', 'dateTimeRange_to' - The ending date and time of a time range.
newDateTimeRange ::
  DateTimeRange
newDateTimeRange :: DateTimeRange
newDateTimeRange =
  DateTimeRange'
    { $sel:from:DateTimeRange' :: Maybe POSIX
from = forall a. Maybe a
Prelude.Nothing,
      $sel:to:DateTimeRange' :: Maybe POSIX
to = forall a. Maybe a
Prelude.Nothing
    }

-- | The starting date and time of a time range.
dateTimeRange_from :: Lens.Lens' DateTimeRange (Prelude.Maybe Prelude.UTCTime)
dateTimeRange_from :: Lens' DateTimeRange (Maybe UTCTime)
dateTimeRange_from = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DateTimeRange' {Maybe POSIX
from :: Maybe POSIX
$sel:from:DateTimeRange' :: DateTimeRange -> Maybe POSIX
from} -> Maybe POSIX
from) (\s :: DateTimeRange
s@DateTimeRange' {} Maybe POSIX
a -> DateTimeRange
s {$sel:from:DateTimeRange' :: Maybe POSIX
from = Maybe POSIX
a} :: DateTimeRange) 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 ending date and time of a time range.
dateTimeRange_to :: Lens.Lens' DateTimeRange (Prelude.Maybe Prelude.UTCTime)
dateTimeRange_to :: Lens' DateTimeRange (Maybe UTCTime)
dateTimeRange_to = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DateTimeRange' {Maybe POSIX
to :: Maybe POSIX
$sel:to:DateTimeRange' :: DateTimeRange -> Maybe POSIX
to} -> Maybe POSIX
to) (\s :: DateTimeRange
s@DateTimeRange' {} Maybe POSIX
a -> DateTimeRange
s {$sel:to:DateTimeRange' :: Maybe POSIX
to = Maybe POSIX
a} :: DateTimeRange) 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 Prelude.Hashable DateTimeRange where
  hashWithSalt :: Int -> DateTimeRange -> Int
hashWithSalt Int
_salt DateTimeRange' {Maybe POSIX
to :: Maybe POSIX
from :: Maybe POSIX
$sel:to:DateTimeRange' :: DateTimeRange -> Maybe POSIX
$sel:from:DateTimeRange' :: DateTimeRange -> Maybe POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
from
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
to

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

instance Data.ToJSON DateTimeRange where
  toJSON :: DateTimeRange -> Value
toJSON DateTimeRange' {Maybe POSIX
to :: Maybe POSIX
from :: Maybe POSIX
$sel:to:DateTimeRange' :: DateTimeRange -> Maybe POSIX
$sel:from:DateTimeRange' :: DateTimeRange -> Maybe POSIX
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"from" 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
from,
            (Key
"to" 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
to
          ]
      )