{-# 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.SSMContacts.Types.TimeRange
-- 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.SSMContacts.Types.TimeRange where

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

-- | A range of between two set times
--
-- /See:/ 'newTimeRange' smart constructor.
data TimeRange = TimeRange'
  { -- | The start of the time range.
    TimeRange -> Maybe POSIX
startTime :: Prelude.Maybe Core.POSIX,
    -- | The end of the time range.
    TimeRange -> Maybe POSIX
endTime :: Prelude.Maybe Core.POSIX
  }
  deriving (TimeRange -> TimeRange -> Bool
(TimeRange -> TimeRange -> Bool)
-> (TimeRange -> TimeRange -> Bool) -> Eq TimeRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TimeRange -> TimeRange -> Bool
$c/= :: TimeRange -> TimeRange -> Bool
== :: TimeRange -> TimeRange -> Bool
$c== :: TimeRange -> TimeRange -> Bool
Prelude.Eq, ReadPrec [TimeRange]
ReadPrec TimeRange
Int -> ReadS TimeRange
ReadS [TimeRange]
(Int -> ReadS TimeRange)
-> ReadS [TimeRange]
-> ReadPrec TimeRange
-> ReadPrec [TimeRange]
-> Read TimeRange
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TimeRange]
$creadListPrec :: ReadPrec [TimeRange]
readPrec :: ReadPrec TimeRange
$creadPrec :: ReadPrec TimeRange
readList :: ReadS [TimeRange]
$creadList :: ReadS [TimeRange]
readsPrec :: Int -> ReadS TimeRange
$creadsPrec :: Int -> ReadS TimeRange
Prelude.Read, Int -> TimeRange -> ShowS
[TimeRange] -> ShowS
TimeRange -> String
(Int -> TimeRange -> ShowS)
-> (TimeRange -> String)
-> ([TimeRange] -> ShowS)
-> Show TimeRange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TimeRange] -> ShowS
$cshowList :: [TimeRange] -> ShowS
show :: TimeRange -> String
$cshow :: TimeRange -> String
showsPrec :: Int -> TimeRange -> ShowS
$cshowsPrec :: Int -> TimeRange -> ShowS
Prelude.Show, (forall x. TimeRange -> Rep TimeRange x)
-> (forall x. Rep TimeRange x -> TimeRange) -> Generic TimeRange
forall x. Rep TimeRange x -> TimeRange
forall x. TimeRange -> Rep TimeRange x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TimeRange x -> TimeRange
$cfrom :: forall x. TimeRange -> Rep TimeRange x
Prelude.Generic)

-- |
-- Create a value of 'TimeRange' 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:
--
-- 'startTime', 'timeRange_startTime' - The start of the time range.
--
-- 'endTime', 'timeRange_endTime' - The end of the time range.
newTimeRange ::
  TimeRange
newTimeRange :: TimeRange
newTimeRange =
  TimeRange' :: Maybe POSIX -> Maybe POSIX -> TimeRange
TimeRange'
    { $sel:startTime:TimeRange' :: Maybe POSIX
startTime = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:endTime:TimeRange' :: Maybe POSIX
endTime = Maybe POSIX
forall a. Maybe a
Prelude.Nothing
    }

-- | The start of the time range.
timeRange_startTime :: Lens.Lens' TimeRange (Prelude.Maybe Prelude.UTCTime)
timeRange_startTime :: (Maybe UTCTime -> f (Maybe UTCTime)) -> TimeRange -> f TimeRange
timeRange_startTime = (TimeRange -> Maybe POSIX)
-> (TimeRange -> Maybe POSIX -> TimeRange)
-> Lens TimeRange TimeRange (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimeRange' {Maybe POSIX
startTime :: Maybe POSIX
$sel:startTime:TimeRange' :: TimeRange -> Maybe POSIX
startTime} -> Maybe POSIX
startTime) (\s :: TimeRange
s@TimeRange' {} Maybe POSIX
a -> TimeRange
s {$sel:startTime:TimeRange' :: Maybe POSIX
startTime = Maybe POSIX
a} :: TimeRange) ((Maybe POSIX -> f (Maybe POSIX)) -> TimeRange -> f TimeRange)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> TimeRange
-> f TimeRange
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 of the time range.
timeRange_endTime :: Lens.Lens' TimeRange (Prelude.Maybe Prelude.UTCTime)
timeRange_endTime :: (Maybe UTCTime -> f (Maybe UTCTime)) -> TimeRange -> f TimeRange
timeRange_endTime = (TimeRange -> Maybe POSIX)
-> (TimeRange -> Maybe POSIX -> TimeRange)
-> Lens TimeRange TimeRange (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimeRange' {Maybe POSIX
endTime :: Maybe POSIX
$sel:endTime:TimeRange' :: TimeRange -> Maybe POSIX
endTime} -> Maybe POSIX
endTime) (\s :: TimeRange
s@TimeRange' {} Maybe POSIX
a -> TimeRange
s {$sel:endTime:TimeRange' :: Maybe POSIX
endTime = Maybe POSIX
a} :: TimeRange) ((Maybe POSIX -> f (Maybe POSIX)) -> TimeRange -> f TimeRange)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> TimeRange
-> f TimeRange
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 TimeRange

instance Prelude.NFData TimeRange

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