{-# 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.IoTAnalytics.Types.DeltaTime
-- 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.IoTAnalytics.Types.DeltaTime where

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

-- | Used to limit data to that which has arrived since the last execution of
-- the action.
--
-- /See:/ 'newDeltaTime' smart constructor.
data DeltaTime = DeltaTime'
  { -- | The number of seconds of estimated in-flight lag time of message data.
    -- When you create dataset contents using message data from a specified
    -- timeframe, some message data might still be in flight when processing
    -- begins, and so do not arrive in time to be processed. Use this field to
    -- make allowances for the in flight time of your message data, so that
    -- data not processed from a previous timeframe is included with the next
    -- timeframe. Otherwise, missed message data would be excluded from
    -- processing during the next timeframe too, because its timestamp places
    -- it within the previous timeframe.
    DeltaTime -> Int
offsetSeconds :: Prelude.Int,
    -- | An expression by which the time of the message data might be determined.
    -- This can be the name of a timestamp field or a SQL expression that is
    -- used to derive the time the message data was generated.
    DeltaTime -> Text
timeExpression :: Prelude.Text
  }
  deriving (DeltaTime -> DeltaTime -> Bool
(DeltaTime -> DeltaTime -> Bool)
-> (DeltaTime -> DeltaTime -> Bool) -> Eq DeltaTime
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeltaTime -> DeltaTime -> Bool
$c/= :: DeltaTime -> DeltaTime -> Bool
== :: DeltaTime -> DeltaTime -> Bool
$c== :: DeltaTime -> DeltaTime -> Bool
Prelude.Eq, ReadPrec [DeltaTime]
ReadPrec DeltaTime
Int -> ReadS DeltaTime
ReadS [DeltaTime]
(Int -> ReadS DeltaTime)
-> ReadS [DeltaTime]
-> ReadPrec DeltaTime
-> ReadPrec [DeltaTime]
-> Read DeltaTime
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeltaTime]
$creadListPrec :: ReadPrec [DeltaTime]
readPrec :: ReadPrec DeltaTime
$creadPrec :: ReadPrec DeltaTime
readList :: ReadS [DeltaTime]
$creadList :: ReadS [DeltaTime]
readsPrec :: Int -> ReadS DeltaTime
$creadsPrec :: Int -> ReadS DeltaTime
Prelude.Read, Int -> DeltaTime -> ShowS
[DeltaTime] -> ShowS
DeltaTime -> String
(Int -> DeltaTime -> ShowS)
-> (DeltaTime -> String)
-> ([DeltaTime] -> ShowS)
-> Show DeltaTime
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeltaTime] -> ShowS
$cshowList :: [DeltaTime] -> ShowS
show :: DeltaTime -> String
$cshow :: DeltaTime -> String
showsPrec :: Int -> DeltaTime -> ShowS
$cshowsPrec :: Int -> DeltaTime -> ShowS
Prelude.Show, (forall x. DeltaTime -> Rep DeltaTime x)
-> (forall x. Rep DeltaTime x -> DeltaTime) -> Generic DeltaTime
forall x. Rep DeltaTime x -> DeltaTime
forall x. DeltaTime -> Rep DeltaTime x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeltaTime x -> DeltaTime
$cfrom :: forall x. DeltaTime -> Rep DeltaTime x
Prelude.Generic)

-- |
-- Create a value of 'DeltaTime' 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:
--
-- 'offsetSeconds', 'deltaTime_offsetSeconds' - The number of seconds of estimated in-flight lag time of message data.
-- When you create dataset contents using message data from a specified
-- timeframe, some message data might still be in flight when processing
-- begins, and so do not arrive in time to be processed. Use this field to
-- make allowances for the in flight time of your message data, so that
-- data not processed from a previous timeframe is included with the next
-- timeframe. Otherwise, missed message data would be excluded from
-- processing during the next timeframe too, because its timestamp places
-- it within the previous timeframe.
--
-- 'timeExpression', 'deltaTime_timeExpression' - An expression by which the time of the message data might be determined.
-- This can be the name of a timestamp field or a SQL expression that is
-- used to derive the time the message data was generated.
newDeltaTime ::
  -- | 'offsetSeconds'
  Prelude.Int ->
  -- | 'timeExpression'
  Prelude.Text ->
  DeltaTime
newDeltaTime :: Int -> Text -> DeltaTime
newDeltaTime Int
pOffsetSeconds_ Text
pTimeExpression_ =
  DeltaTime' :: Int -> Text -> DeltaTime
DeltaTime'
    { $sel:offsetSeconds:DeltaTime' :: Int
offsetSeconds = Int
pOffsetSeconds_,
      $sel:timeExpression:DeltaTime' :: Text
timeExpression = Text
pTimeExpression_
    }

-- | The number of seconds of estimated in-flight lag time of message data.
-- When you create dataset contents using message data from a specified
-- timeframe, some message data might still be in flight when processing
-- begins, and so do not arrive in time to be processed. Use this field to
-- make allowances for the in flight time of your message data, so that
-- data not processed from a previous timeframe is included with the next
-- timeframe. Otherwise, missed message data would be excluded from
-- processing during the next timeframe too, because its timestamp places
-- it within the previous timeframe.
deltaTime_offsetSeconds :: Lens.Lens' DeltaTime Prelude.Int
deltaTime_offsetSeconds :: (Int -> f Int) -> DeltaTime -> f DeltaTime
deltaTime_offsetSeconds = (DeltaTime -> Int)
-> (DeltaTime -> Int -> DeltaTime)
-> Lens DeltaTime DeltaTime Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeltaTime' {Int
offsetSeconds :: Int
$sel:offsetSeconds:DeltaTime' :: DeltaTime -> Int
offsetSeconds} -> Int
offsetSeconds) (\s :: DeltaTime
s@DeltaTime' {} Int
a -> DeltaTime
s {$sel:offsetSeconds:DeltaTime' :: Int
offsetSeconds = Int
a} :: DeltaTime)

-- | An expression by which the time of the message data might be determined.
-- This can be the name of a timestamp field or a SQL expression that is
-- used to derive the time the message data was generated.
deltaTime_timeExpression :: Lens.Lens' DeltaTime Prelude.Text
deltaTime_timeExpression :: (Text -> f Text) -> DeltaTime -> f DeltaTime
deltaTime_timeExpression = (DeltaTime -> Text)
-> (DeltaTime -> Text -> DeltaTime)
-> Lens DeltaTime DeltaTime Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeltaTime' {Text
timeExpression :: Text
$sel:timeExpression:DeltaTime' :: DeltaTime -> Text
timeExpression} -> Text
timeExpression) (\s :: DeltaTime
s@DeltaTime' {} Text
a -> DeltaTime
s {$sel:timeExpression:DeltaTime' :: Text
timeExpression = Text
a} :: DeltaTime)

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

instance Prelude.Hashable DeltaTime

instance Prelude.NFData DeltaTime

instance Core.ToJSON DeltaTime where
  toJSON :: DeltaTime -> Value
toJSON DeltaTime' {Int
Text
timeExpression :: Text
offsetSeconds :: Int
$sel:timeExpression:DeltaTime' :: DeltaTime -> Text
$sel:offsetSeconds:DeltaTime' :: DeltaTime -> Int
..} =
    [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
"offsetSeconds" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
offsetSeconds),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"timeExpression" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
timeExpression)
          ]
      )