{-# 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.DevOpsGuru.Types.EventTimeRange
-- 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.DevOpsGuru.Types.EventTimeRange where

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

-- | The time range during which an AWS event occurred. AWS resource events
-- and metrics are analyzed by DevOps Guru to find anomalous behavior and
-- provide recommendations to improve your operational solutions.
--
-- /See:/ 'newEventTimeRange' smart constructor.
data EventTimeRange = EventTimeRange'
  { -- | The time when the event started.
    EventTimeRange -> POSIX
fromTime :: Core.POSIX,
    -- | The time when the event ended.
    EventTimeRange -> POSIX
toTime :: Core.POSIX
  }
  deriving (EventTimeRange -> EventTimeRange -> Bool
(EventTimeRange -> EventTimeRange -> Bool)
-> (EventTimeRange -> EventTimeRange -> Bool) -> Eq EventTimeRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EventTimeRange -> EventTimeRange -> Bool
$c/= :: EventTimeRange -> EventTimeRange -> Bool
== :: EventTimeRange -> EventTimeRange -> Bool
$c== :: EventTimeRange -> EventTimeRange -> Bool
Prelude.Eq, ReadPrec [EventTimeRange]
ReadPrec EventTimeRange
Int -> ReadS EventTimeRange
ReadS [EventTimeRange]
(Int -> ReadS EventTimeRange)
-> ReadS [EventTimeRange]
-> ReadPrec EventTimeRange
-> ReadPrec [EventTimeRange]
-> Read EventTimeRange
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EventTimeRange]
$creadListPrec :: ReadPrec [EventTimeRange]
readPrec :: ReadPrec EventTimeRange
$creadPrec :: ReadPrec EventTimeRange
readList :: ReadS [EventTimeRange]
$creadList :: ReadS [EventTimeRange]
readsPrec :: Int -> ReadS EventTimeRange
$creadsPrec :: Int -> ReadS EventTimeRange
Prelude.Read, Int -> EventTimeRange -> ShowS
[EventTimeRange] -> ShowS
EventTimeRange -> String
(Int -> EventTimeRange -> ShowS)
-> (EventTimeRange -> String)
-> ([EventTimeRange] -> ShowS)
-> Show EventTimeRange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EventTimeRange] -> ShowS
$cshowList :: [EventTimeRange] -> ShowS
show :: EventTimeRange -> String
$cshow :: EventTimeRange -> String
showsPrec :: Int -> EventTimeRange -> ShowS
$cshowsPrec :: Int -> EventTimeRange -> ShowS
Prelude.Show, (forall x. EventTimeRange -> Rep EventTimeRange x)
-> (forall x. Rep EventTimeRange x -> EventTimeRange)
-> Generic EventTimeRange
forall x. Rep EventTimeRange x -> EventTimeRange
forall x. EventTimeRange -> Rep EventTimeRange x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EventTimeRange x -> EventTimeRange
$cfrom :: forall x. EventTimeRange -> Rep EventTimeRange x
Prelude.Generic)

-- |
-- Create a value of 'EventTimeRange' 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:
--
-- 'fromTime', 'eventTimeRange_fromTime' - The time when the event started.
--
-- 'toTime', 'eventTimeRange_toTime' - The time when the event ended.
newEventTimeRange ::
  -- | 'fromTime'
  Prelude.UTCTime ->
  -- | 'toTime'
  Prelude.UTCTime ->
  EventTimeRange
newEventTimeRange :: UTCTime -> UTCTime -> EventTimeRange
newEventTimeRange UTCTime
pFromTime_ UTCTime
pToTime_ =
  EventTimeRange' :: POSIX -> POSIX -> EventTimeRange
EventTimeRange'
    { $sel:fromTime:EventTimeRange' :: POSIX
fromTime =
        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
pFromTime_,
      $sel:toTime:EventTimeRange' :: POSIX
toTime = 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
pToTime_
    }

-- | The time when the event started.
eventTimeRange_fromTime :: Lens.Lens' EventTimeRange Prelude.UTCTime
eventTimeRange_fromTime :: (UTCTime -> f UTCTime) -> EventTimeRange -> f EventTimeRange
eventTimeRange_fromTime = (EventTimeRange -> POSIX)
-> (EventTimeRange -> POSIX -> EventTimeRange)
-> Lens EventTimeRange EventTimeRange POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventTimeRange' {POSIX
fromTime :: POSIX
$sel:fromTime:EventTimeRange' :: EventTimeRange -> POSIX
fromTime} -> POSIX
fromTime) (\s :: EventTimeRange
s@EventTimeRange' {} POSIX
a -> EventTimeRange
s {$sel:fromTime:EventTimeRange' :: POSIX
fromTime = POSIX
a} :: EventTimeRange) ((POSIX -> f POSIX) -> EventTimeRange -> f EventTimeRange)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> EventTimeRange
-> f EventTimeRange
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 time when the event ended.
eventTimeRange_toTime :: Lens.Lens' EventTimeRange Prelude.UTCTime
eventTimeRange_toTime :: (UTCTime -> f UTCTime) -> EventTimeRange -> f EventTimeRange
eventTimeRange_toTime = (EventTimeRange -> POSIX)
-> (EventTimeRange -> POSIX -> EventTimeRange)
-> Lens EventTimeRange EventTimeRange POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventTimeRange' {POSIX
toTime :: POSIX
$sel:toTime:EventTimeRange' :: EventTimeRange -> POSIX
toTime} -> POSIX
toTime) (\s :: EventTimeRange
s@EventTimeRange' {} POSIX
a -> EventTimeRange
s {$sel:toTime:EventTimeRange' :: POSIX
toTime = POSIX
a} :: EventTimeRange) ((POSIX -> f POSIX) -> EventTimeRange -> f EventTimeRange)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> EventTimeRange
-> f EventTimeRange
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 Prelude.Hashable EventTimeRange

instance Prelude.NFData EventTimeRange

instance Core.ToJSON EventTimeRange where
  toJSON :: EventTimeRange -> Value
toJSON EventTimeRange' {POSIX
toTime :: POSIX
fromTime :: POSIX
$sel:toTime:EventTimeRange' :: EventTimeRange -> POSIX
$sel:fromTime:EventTimeRange' :: EventTimeRange -> 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
"FromTime" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= POSIX
fromTime),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ToTime" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= POSIX
toTime)
          ]
      )