{-# 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.WAF.Types.TimeWindow
-- 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.WAF.Types.TimeWindow where

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

-- | This is __AWS WAF Classic__ documentation. For more information, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html AWS WAF Classic>
-- in the developer guide.
--
-- __For the latest version of AWS WAF__, use the AWS WAFV2 API and see the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html AWS WAF Developer Guide>.
-- With the latest version, AWS WAF has a single set of endpoints for
-- regional and global use.
--
-- In a GetSampledRequests request, the @StartTime@ and @EndTime@ objects
-- specify the time range for which you want AWS WAF to return a sample of
-- web requests.
--
-- You must specify the times in Coordinated Universal Time (UTC) format.
-- UTC format includes the special designator, @Z@. For example,
-- @\"2016-09-27T14:50Z\"@.
--
-- In a GetSampledRequests response, the @StartTime@ and @EndTime@ objects
-- specify the time range for which AWS WAF actually returned a sample of
-- web requests. AWS WAF gets the specified number of requests from among
-- the first 5,000 requests that your AWS resource receives during the
-- specified time period. If your resource receives more than 5,000
-- requests during that period, AWS WAF stops sampling after the 5,000th
-- request. In that case, @EndTime@ is the time that AWS WAF received the
-- 5,000th request.
--
-- /See:/ 'newTimeWindow' smart constructor.
data TimeWindow = TimeWindow'
  { -- | The beginning of the time range from which you want @GetSampledRequests@
    -- to return a sample of the requests that your AWS resource received. You
    -- must specify the date and time in Coordinated Universal Time (UTC)
    -- format. UTC format includes the special designator, @Z@. For example,
    -- @\"2016-09-27T14:50Z\"@. You can specify any time range in the previous
    -- three hours.
    TimeWindow -> POSIX
startTime :: Core.POSIX,
    -- | The end of the time range from which you want @GetSampledRequests@ to
    -- return a sample of the requests that your AWS resource received. You
    -- must specify the date and time in Coordinated Universal Time (UTC)
    -- format. UTC format includes the special designator, @Z@. For example,
    -- @\"2016-09-27T14:50Z\"@. You can specify any time range in the previous
    -- three hours.
    TimeWindow -> POSIX
endTime :: Core.POSIX
  }
  deriving (TimeWindow -> TimeWindow -> Bool
(TimeWindow -> TimeWindow -> Bool)
-> (TimeWindow -> TimeWindow -> Bool) -> Eq TimeWindow
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TimeWindow -> TimeWindow -> Bool
$c/= :: TimeWindow -> TimeWindow -> Bool
== :: TimeWindow -> TimeWindow -> Bool
$c== :: TimeWindow -> TimeWindow -> Bool
Prelude.Eq, ReadPrec [TimeWindow]
ReadPrec TimeWindow
Int -> ReadS TimeWindow
ReadS [TimeWindow]
(Int -> ReadS TimeWindow)
-> ReadS [TimeWindow]
-> ReadPrec TimeWindow
-> ReadPrec [TimeWindow]
-> Read TimeWindow
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TimeWindow]
$creadListPrec :: ReadPrec [TimeWindow]
readPrec :: ReadPrec TimeWindow
$creadPrec :: ReadPrec TimeWindow
readList :: ReadS [TimeWindow]
$creadList :: ReadS [TimeWindow]
readsPrec :: Int -> ReadS TimeWindow
$creadsPrec :: Int -> ReadS TimeWindow
Prelude.Read, Int -> TimeWindow -> ShowS
[TimeWindow] -> ShowS
TimeWindow -> String
(Int -> TimeWindow -> ShowS)
-> (TimeWindow -> String)
-> ([TimeWindow] -> ShowS)
-> Show TimeWindow
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TimeWindow] -> ShowS
$cshowList :: [TimeWindow] -> ShowS
show :: TimeWindow -> String
$cshow :: TimeWindow -> String
showsPrec :: Int -> TimeWindow -> ShowS
$cshowsPrec :: Int -> TimeWindow -> ShowS
Prelude.Show, (forall x. TimeWindow -> Rep TimeWindow x)
-> (forall x. Rep TimeWindow x -> TimeWindow) -> Generic TimeWindow
forall x. Rep TimeWindow x -> TimeWindow
forall x. TimeWindow -> Rep TimeWindow x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TimeWindow x -> TimeWindow
$cfrom :: forall x. TimeWindow -> Rep TimeWindow x
Prelude.Generic)

-- |
-- Create a value of 'TimeWindow' 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', 'timeWindow_startTime' - The beginning of the time range from which you want @GetSampledRequests@
-- to return a sample of the requests that your AWS resource received. You
-- must specify the date and time in Coordinated Universal Time (UTC)
-- format. UTC format includes the special designator, @Z@. For example,
-- @\"2016-09-27T14:50Z\"@. You can specify any time range in the previous
-- three hours.
--
-- 'endTime', 'timeWindow_endTime' - The end of the time range from which you want @GetSampledRequests@ to
-- return a sample of the requests that your AWS resource received. You
-- must specify the date and time in Coordinated Universal Time (UTC)
-- format. UTC format includes the special designator, @Z@. For example,
-- @\"2016-09-27T14:50Z\"@. You can specify any time range in the previous
-- three hours.
newTimeWindow ::
  -- | 'startTime'
  Prelude.UTCTime ->
  -- | 'endTime'
  Prelude.UTCTime ->
  TimeWindow
newTimeWindow :: UTCTime -> UTCTime -> TimeWindow
newTimeWindow UTCTime
pStartTime_ UTCTime
pEndTime_ =
  TimeWindow' :: POSIX -> POSIX -> TimeWindow
TimeWindow'
    { $sel:startTime:TimeWindow' :: POSIX
startTime =
        Tagged UTCTime (Identity UTCTime) -> Tagged POSIX (Identity POSIX)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged POSIX (Identity POSIX))
-> UTCTime -> POSIX
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pStartTime_,
      $sel:endTime:TimeWindow' :: POSIX
endTime = Tagged UTCTime (Identity UTCTime) -> Tagged POSIX (Identity POSIX)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged POSIX (Identity POSIX))
-> UTCTime -> POSIX
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pEndTime_
    }

-- | The beginning of the time range from which you want @GetSampledRequests@
-- to return a sample of the requests that your AWS resource received. You
-- must specify the date and time in Coordinated Universal Time (UTC)
-- format. UTC format includes the special designator, @Z@. For example,
-- @\"2016-09-27T14:50Z\"@. You can specify any time range in the previous
-- three hours.
timeWindow_startTime :: Lens.Lens' TimeWindow Prelude.UTCTime
timeWindow_startTime :: (UTCTime -> f UTCTime) -> TimeWindow -> f TimeWindow
timeWindow_startTime = (TimeWindow -> POSIX)
-> (TimeWindow -> POSIX -> TimeWindow)
-> Lens TimeWindow TimeWindow POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimeWindow' {POSIX
startTime :: POSIX
$sel:startTime:TimeWindow' :: TimeWindow -> POSIX
startTime} -> POSIX
startTime) (\s :: TimeWindow
s@TimeWindow' {} POSIX
a -> TimeWindow
s {$sel:startTime:TimeWindow' :: POSIX
startTime = POSIX
a} :: TimeWindow) ((POSIX -> f POSIX) -> TimeWindow -> f TimeWindow)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> TimeWindow
-> f TimeWindow
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> POSIX -> f POSIX
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The end of the time range from which you want @GetSampledRequests@ to
-- return a sample of the requests that your AWS resource received. You
-- must specify the date and time in Coordinated Universal Time (UTC)
-- format. UTC format includes the special designator, @Z@. For example,
-- @\"2016-09-27T14:50Z\"@. You can specify any time range in the previous
-- three hours.
timeWindow_endTime :: Lens.Lens' TimeWindow Prelude.UTCTime
timeWindow_endTime :: (UTCTime -> f UTCTime) -> TimeWindow -> f TimeWindow
timeWindow_endTime = (TimeWindow -> POSIX)
-> (TimeWindow -> POSIX -> TimeWindow)
-> Lens TimeWindow TimeWindow POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimeWindow' {POSIX
endTime :: POSIX
$sel:endTime:TimeWindow' :: TimeWindow -> POSIX
endTime} -> POSIX
endTime) (\s :: TimeWindow
s@TimeWindow' {} POSIX
a -> TimeWindow
s {$sel:endTime:TimeWindow' :: POSIX
endTime = POSIX
a} :: TimeWindow) ((POSIX -> f POSIX) -> TimeWindow -> f TimeWindow)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> TimeWindow
-> f TimeWindow
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> POSIX -> f POSIX
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

instance Core.FromJSON TimeWindow where
  parseJSON :: Value -> Parser TimeWindow
parseJSON =
    String
-> (Object -> Parser TimeWindow) -> Value -> Parser TimeWindow
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TimeWindow"
      ( \Object
x ->
          POSIX -> POSIX -> TimeWindow
TimeWindow'
            (POSIX -> POSIX -> TimeWindow)
-> Parser POSIX -> Parser (POSIX -> TimeWindow)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser POSIX
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"StartTime")
            Parser (POSIX -> TimeWindow) -> Parser POSIX -> Parser TimeWindow
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser POSIX
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"EndTime")
      )

instance Prelude.Hashable TimeWindow

instance Prelude.NFData TimeWindow

instance Core.ToJSON TimeWindow where
  toJSON :: TimeWindow -> Value
toJSON TimeWindow' {POSIX
endTime :: POSIX
startTime :: POSIX
$sel:endTime:TimeWindow' :: TimeWindow -> POSIX
$sel:startTime:TimeWindow' :: TimeWindow -> POSIX
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"StartTime" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= POSIX
startTime),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"EndTime" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= POSIX
endTime)
          ]
      )