{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.WAF.Types.TimeWindow 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

-- | 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 :: Data.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 :: Data.POSIX
  }
  deriving (TimeWindow -> TimeWindow -> Bool
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]
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
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. 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'
    { $sel:startTime:TimeWindow' :: POSIX
startTime =
        forall (a :: Format). Iso' (Time a) UTCTime
Data._Time forall t b. AReview t b -> b -> t
Lens.# UTCTime
pStartTime_,
      $sel:endTime:TimeWindow' :: POSIX
endTime = forall (a :: Format). Iso' (Time a) UTCTime
Data._Time 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 :: Lens' TimeWindow UTCTime
timeWindow_startTime = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._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 :: Lens' TimeWindow UTCTime
timeWindow_endTime = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

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

instance Prelude.Hashable TimeWindow where
  hashWithSalt :: Int -> TimeWindow -> Int
hashWithSalt Int
_salt TimeWindow' {POSIX
endTime :: POSIX
startTime :: POSIX
$sel:endTime:TimeWindow' :: TimeWindow -> POSIX
$sel:startTime:TimeWindow' :: TimeWindow -> POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` POSIX
startTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` POSIX
endTime

instance Prelude.NFData TimeWindow where
  rnf :: TimeWindow -> ()
rnf TimeWindow' {POSIX
endTime :: POSIX
startTime :: POSIX
$sel:endTime:TimeWindow' :: TimeWindow -> POSIX
$sel:startTime:TimeWindow' :: TimeWindow -> POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf POSIX
startTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf POSIX
endTime

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"StartTime" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= POSIX
startTime),
            forall a. a -> Maybe a
Prelude.Just (Key
"EndTime" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= POSIX
endTime)
          ]
      )