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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 ending date and time of a time range.
    DateTimeRange -> Maybe POSIX
to :: Prelude.Maybe Core.POSIX,
    -- | The starting date and time of a time range.
    DateTimeRange -> Maybe POSIX
from :: Prelude.Maybe Core.POSIX
  }
  deriving (DateTimeRange -> DateTimeRange -> Bool
(DateTimeRange -> DateTimeRange -> Bool)
-> (DateTimeRange -> DateTimeRange -> Bool) -> Eq DateTimeRange
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]
(Int -> ReadS DateTimeRange)
-> ReadS [DateTimeRange]
-> ReadPrec DateTimeRange
-> ReadPrec [DateTimeRange]
-> Read 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
(Int -> DateTimeRange -> ShowS)
-> (DateTimeRange -> String)
-> ([DateTimeRange] -> ShowS)
-> Show DateTimeRange
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. DateTimeRange -> Rep DateTimeRange x)
-> (forall x. Rep DateTimeRange x -> DateTimeRange)
-> Generic DateTimeRange
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:
--
-- 'to', 'dateTimeRange_to' - The ending date and time of a time range.
--
-- 'from', 'dateTimeRange_from' - The starting date and time of a time range.
newDateTimeRange ::
  DateTimeRange
newDateTimeRange :: DateTimeRange
newDateTimeRange =
  DateTimeRange' :: Maybe POSIX -> Maybe POSIX -> DateTimeRange
DateTimeRange'
    { $sel:to:DateTimeRange' :: Maybe POSIX
to = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:from:DateTimeRange' :: Maybe POSIX
from = Maybe POSIX
forall a. Maybe a
Prelude.Nothing
    }

-- | The ending date and time of a time range.
dateTimeRange_to :: Lens.Lens' DateTimeRange (Prelude.Maybe Prelude.UTCTime)
dateTimeRange_to :: (Maybe UTCTime -> f (Maybe UTCTime))
-> DateTimeRange -> f DateTimeRange
dateTimeRange_to = (DateTimeRange -> Maybe POSIX)
-> (DateTimeRange -> Maybe POSIX -> DateTimeRange)
-> Lens DateTimeRange DateTimeRange (Maybe POSIX) (Maybe POSIX)
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) ((Maybe POSIX -> f (Maybe POSIX))
 -> DateTimeRange -> f DateTimeRange)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> DateTimeRange
-> f DateTimeRange
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 starting date and time of a time range.
dateTimeRange_from :: Lens.Lens' DateTimeRange (Prelude.Maybe Prelude.UTCTime)
dateTimeRange_from :: (Maybe UTCTime -> f (Maybe UTCTime))
-> DateTimeRange -> f DateTimeRange
dateTimeRange_from = (DateTimeRange -> Maybe POSIX)
-> (DateTimeRange -> Maybe POSIX -> DateTimeRange)
-> Lens DateTimeRange DateTimeRange (Maybe POSIX) (Maybe POSIX)
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) ((Maybe POSIX -> f (Maybe POSIX))
 -> DateTimeRange -> f DateTimeRange)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> DateTimeRange
-> f DateTimeRange
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 Prelude.Hashable DateTimeRange

instance Prelude.NFData DateTimeRange

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