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

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

-- | The time range.
--
-- /See:/ 'newTimeRange' smart constructor.
data TimeRange = TimeRange'
  { -- | The start time, in Unix time in seconds. For more information see
    -- <http://docs.aws.amazon.com/cli/latest/userguide/cli-using-param.html#parameter-types timestamp>.
    TimeRange -> Maybe POSIX
fromInclusive :: Prelude.Maybe Core.POSIX,
    -- | The end time, in Unix time in seconds. For more information see
    -- <http://docs.aws.amazon.com/cli/latest/userguide/cli-using-param.html#parameter-types timestamp>.
    TimeRange -> Maybe POSIX
toExclusive :: 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:
--
-- 'fromInclusive', 'timeRange_fromInclusive' - The start time, in Unix time in seconds. For more information see
-- <http://docs.aws.amazon.com/cli/latest/userguide/cli-using-param.html#parameter-types timestamp>.
--
-- 'toExclusive', 'timeRange_toExclusive' - The end time, in Unix time in seconds. For more information see
-- <http://docs.aws.amazon.com/cli/latest/userguide/cli-using-param.html#parameter-types timestamp>.
newTimeRange ::
  TimeRange
newTimeRange :: TimeRange
newTimeRange =
  TimeRange' :: Maybe POSIX -> Maybe POSIX -> TimeRange
TimeRange'
    { $sel:fromInclusive:TimeRange' :: Maybe POSIX
fromInclusive = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:toExclusive:TimeRange' :: Maybe POSIX
toExclusive = Maybe POSIX
forall a. Maybe a
Prelude.Nothing
    }

-- | The start time, in Unix time in seconds. For more information see
-- <http://docs.aws.amazon.com/cli/latest/userguide/cli-using-param.html#parameter-types timestamp>.
timeRange_fromInclusive :: Lens.Lens' TimeRange (Prelude.Maybe Prelude.UTCTime)
timeRange_fromInclusive :: (Maybe UTCTime -> f (Maybe UTCTime)) -> TimeRange -> f TimeRange
timeRange_fromInclusive = (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
fromInclusive :: Maybe POSIX
$sel:fromInclusive:TimeRange' :: TimeRange -> Maybe POSIX
fromInclusive} -> Maybe POSIX
fromInclusive) (\s :: TimeRange
s@TimeRange' {} Maybe POSIX
a -> TimeRange
s {$sel:fromInclusive:TimeRange' :: Maybe POSIX
fromInclusive = 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 time, in Unix time in seconds. For more information see
-- <http://docs.aws.amazon.com/cli/latest/userguide/cli-using-param.html#parameter-types timestamp>.
timeRange_toExclusive :: Lens.Lens' TimeRange (Prelude.Maybe Prelude.UTCTime)
timeRange_toExclusive :: (Maybe UTCTime -> f (Maybe UTCTime)) -> TimeRange -> f TimeRange
timeRange_toExclusive = (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
toExclusive :: Maybe POSIX
$sel:toExclusive:TimeRange' :: TimeRange -> Maybe POSIX
toExclusive} -> Maybe POSIX
toExclusive) (\s :: TimeRange
s@TimeRange' {} Maybe POSIX
a -> TimeRange
s {$sel:toExclusive:TimeRange' :: Maybe POSIX
toExclusive = 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 Core.FromJSON TimeRange where
  parseJSON :: Value -> Parser TimeRange
parseJSON =
    String -> (Object -> Parser TimeRange) -> Value -> Parser TimeRange
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TimeRange"
      ( \Object
x ->
          Maybe POSIX -> Maybe POSIX -> TimeRange
TimeRange'
            (Maybe POSIX -> Maybe POSIX -> TimeRange)
-> Parser (Maybe POSIX) -> Parser (Maybe POSIX -> TimeRange)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"FromInclusive")
            Parser (Maybe POSIX -> TimeRange)
-> Parser (Maybe POSIX) -> Parser TimeRange
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ToExclusive")
      )

instance Prelude.Hashable TimeRange

instance Prelude.NFData TimeRange

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