{-# 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.IoTSiteWise.Types.TumblingWindow
-- 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.IoTSiteWise.Types.TumblingWindow where

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

-- | Contains a tumbling window, which is a repeating fixed-sized,
-- non-overlapping, and contiguous time window. You use this window in
-- metrics to aggregate data from properties and other assets.
--
-- You can use @m@, @h@, @d@, and @w@ when you specify an interval or
-- offset. Note that @m@ represents minutes, and @w@ represents weeks. You
-- can also use @s@ to represent seconds in @offset@.
--
-- The @interval@ and @offset@ parameters support the
-- <https://en.wikipedia.org/wiki/ISO_8601 ISO 8601 format>. For example,
-- @PT5S@ represents five seconds, @PT5M@ represents five minutes, and
-- @PT5H@ represents five hours.
--
-- /See:/ 'newTumblingWindow' smart constructor.
data TumblingWindow = TumblingWindow'
  { -- | The offset for the tumbling window. The @offset@ parameter accepts the
    -- following:
    --
    -- -   The offset time.
    --
    --     For example, if you specify @18h@ for @offset@ and @1d@ for
    --     @interval@, IoT SiteWise aggregates data in one of the following
    --     ways:
    --
    --     -   If you create the metric before or at 6:00 PM (UTC), you get the
    --         first aggregation result at 6 PM (UTC) on the day when you
    --         create the metric.
    --
    --     -   If you create the metric after 6:00 PM (UTC), you get the first
    --         aggregation result at 6 PM (UTC) the next day.
    --
    -- -   The ISO 8601 format.
    --
    --     For example, if you specify @PT18H@ for @offset@ and @1d@ for
    --     @interval@, IoT SiteWise aggregates data in one of the following
    --     ways:
    --
    --     -   If you create the metric before or at 6:00 PM (UTC), you get the
    --         first aggregation result at 6 PM (UTC) on the day when you
    --         create the metric.
    --
    --     -   If you create the metric after 6:00 PM (UTC), you get the first
    --         aggregation result at 6 PM (UTC) the next day.
    --
    -- -   The 24-hour clock.
    --
    --     For example, if you specify @00:03:00@ for @offset@ and @5m@ for
    --     @interval@, and you create the metric at 2 PM (UTC), you get the
    --     first aggregation result at 2:03 PM (UTC). You get the second
    --     aggregation result at 2:08 PM (UTC).
    --
    -- -   The offset time zone.
    --
    --     For example, if you specify @2021-07-23T18:00-08@ for @offset@ and
    --     @1d@ for @interval@, IoT SiteWise aggregates data in one of the
    --     following ways:
    --
    --     -   If you create the metric before or at 6:00 PM (PST), you get the
    --         first aggregation result at 6 PM (PST) on the day when you
    --         create the metric.
    --
    --     -   If you create the metric after 6:00 PM (PST), you get the first
    --         aggregation result at 6 PM (PST) the next day.
    TumblingWindow -> Maybe Text
offset :: Prelude.Maybe Prelude.Text,
    -- | The time interval for the tumbling window. The interval time must be
    -- between 1 minute and 1 week.
    --
    -- IoT SiteWise computes the @1w@ interval the end of Sunday at midnight
    -- each week (UTC), the @1d@ interval at the end of each day at midnight
    -- (UTC), the @1h@ interval at the end of each hour, and so on.
    --
    -- When IoT SiteWise aggregates data points for metric computations, the
    -- start of each interval is exclusive and the end of each interval is
    -- inclusive. IoT SiteWise places the computed data point at the end of the
    -- interval.
    TumblingWindow -> Text
interval :: Prelude.Text
  }
  deriving (TumblingWindow -> TumblingWindow -> Bool
(TumblingWindow -> TumblingWindow -> Bool)
-> (TumblingWindow -> TumblingWindow -> Bool) -> Eq TumblingWindow
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TumblingWindow -> TumblingWindow -> Bool
$c/= :: TumblingWindow -> TumblingWindow -> Bool
== :: TumblingWindow -> TumblingWindow -> Bool
$c== :: TumblingWindow -> TumblingWindow -> Bool
Prelude.Eq, ReadPrec [TumblingWindow]
ReadPrec TumblingWindow
Int -> ReadS TumblingWindow
ReadS [TumblingWindow]
(Int -> ReadS TumblingWindow)
-> ReadS [TumblingWindow]
-> ReadPrec TumblingWindow
-> ReadPrec [TumblingWindow]
-> Read TumblingWindow
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TumblingWindow]
$creadListPrec :: ReadPrec [TumblingWindow]
readPrec :: ReadPrec TumblingWindow
$creadPrec :: ReadPrec TumblingWindow
readList :: ReadS [TumblingWindow]
$creadList :: ReadS [TumblingWindow]
readsPrec :: Int -> ReadS TumblingWindow
$creadsPrec :: Int -> ReadS TumblingWindow
Prelude.Read, Int -> TumblingWindow -> ShowS
[TumblingWindow] -> ShowS
TumblingWindow -> String
(Int -> TumblingWindow -> ShowS)
-> (TumblingWindow -> String)
-> ([TumblingWindow] -> ShowS)
-> Show TumblingWindow
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TumblingWindow] -> ShowS
$cshowList :: [TumblingWindow] -> ShowS
show :: TumblingWindow -> String
$cshow :: TumblingWindow -> String
showsPrec :: Int -> TumblingWindow -> ShowS
$cshowsPrec :: Int -> TumblingWindow -> ShowS
Prelude.Show, (forall x. TumblingWindow -> Rep TumblingWindow x)
-> (forall x. Rep TumblingWindow x -> TumblingWindow)
-> Generic TumblingWindow
forall x. Rep TumblingWindow x -> TumblingWindow
forall x. TumblingWindow -> Rep TumblingWindow x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TumblingWindow x -> TumblingWindow
$cfrom :: forall x. TumblingWindow -> Rep TumblingWindow x
Prelude.Generic)

-- |
-- Create a value of 'TumblingWindow' 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:
--
-- 'offset', 'tumblingWindow_offset' - The offset for the tumbling window. The @offset@ parameter accepts the
-- following:
--
-- -   The offset time.
--
--     For example, if you specify @18h@ for @offset@ and @1d@ for
--     @interval@, IoT SiteWise aggregates data in one of the following
--     ways:
--
--     -   If you create the metric before or at 6:00 PM (UTC), you get the
--         first aggregation result at 6 PM (UTC) on the day when you
--         create the metric.
--
--     -   If you create the metric after 6:00 PM (UTC), you get the first
--         aggregation result at 6 PM (UTC) the next day.
--
-- -   The ISO 8601 format.
--
--     For example, if you specify @PT18H@ for @offset@ and @1d@ for
--     @interval@, IoT SiteWise aggregates data in one of the following
--     ways:
--
--     -   If you create the metric before or at 6:00 PM (UTC), you get the
--         first aggregation result at 6 PM (UTC) on the day when you
--         create the metric.
--
--     -   If you create the metric after 6:00 PM (UTC), you get the first
--         aggregation result at 6 PM (UTC) the next day.
--
-- -   The 24-hour clock.
--
--     For example, if you specify @00:03:00@ for @offset@ and @5m@ for
--     @interval@, and you create the metric at 2 PM (UTC), you get the
--     first aggregation result at 2:03 PM (UTC). You get the second
--     aggregation result at 2:08 PM (UTC).
--
-- -   The offset time zone.
--
--     For example, if you specify @2021-07-23T18:00-08@ for @offset@ and
--     @1d@ for @interval@, IoT SiteWise aggregates data in one of the
--     following ways:
--
--     -   If you create the metric before or at 6:00 PM (PST), you get the
--         first aggregation result at 6 PM (PST) on the day when you
--         create the metric.
--
--     -   If you create the metric after 6:00 PM (PST), you get the first
--         aggregation result at 6 PM (PST) the next day.
--
-- 'interval', 'tumblingWindow_interval' - The time interval for the tumbling window. The interval time must be
-- between 1 minute and 1 week.
--
-- IoT SiteWise computes the @1w@ interval the end of Sunday at midnight
-- each week (UTC), the @1d@ interval at the end of each day at midnight
-- (UTC), the @1h@ interval at the end of each hour, and so on.
--
-- When IoT SiteWise aggregates data points for metric computations, the
-- start of each interval is exclusive and the end of each interval is
-- inclusive. IoT SiteWise places the computed data point at the end of the
-- interval.
newTumblingWindow ::
  -- | 'interval'
  Prelude.Text ->
  TumblingWindow
newTumblingWindow :: Text -> TumblingWindow
newTumblingWindow Text
pInterval_ =
  TumblingWindow' :: Maybe Text -> Text -> TumblingWindow
TumblingWindow'
    { $sel:offset:TumblingWindow' :: Maybe Text
offset = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:interval:TumblingWindow' :: Text
interval = Text
pInterval_
    }

-- | The offset for the tumbling window. The @offset@ parameter accepts the
-- following:
--
-- -   The offset time.
--
--     For example, if you specify @18h@ for @offset@ and @1d@ for
--     @interval@, IoT SiteWise aggregates data in one of the following
--     ways:
--
--     -   If you create the metric before or at 6:00 PM (UTC), you get the
--         first aggregation result at 6 PM (UTC) on the day when you
--         create the metric.
--
--     -   If you create the metric after 6:00 PM (UTC), you get the first
--         aggregation result at 6 PM (UTC) the next day.
--
-- -   The ISO 8601 format.
--
--     For example, if you specify @PT18H@ for @offset@ and @1d@ for
--     @interval@, IoT SiteWise aggregates data in one of the following
--     ways:
--
--     -   If you create the metric before or at 6:00 PM (UTC), you get the
--         first aggregation result at 6 PM (UTC) on the day when you
--         create the metric.
--
--     -   If you create the metric after 6:00 PM (UTC), you get the first
--         aggregation result at 6 PM (UTC) the next day.
--
-- -   The 24-hour clock.
--
--     For example, if you specify @00:03:00@ for @offset@ and @5m@ for
--     @interval@, and you create the metric at 2 PM (UTC), you get the
--     first aggregation result at 2:03 PM (UTC). You get the second
--     aggregation result at 2:08 PM (UTC).
--
-- -   The offset time zone.
--
--     For example, if you specify @2021-07-23T18:00-08@ for @offset@ and
--     @1d@ for @interval@, IoT SiteWise aggregates data in one of the
--     following ways:
--
--     -   If you create the metric before or at 6:00 PM (PST), you get the
--         first aggregation result at 6 PM (PST) on the day when you
--         create the metric.
--
--     -   If you create the metric after 6:00 PM (PST), you get the first
--         aggregation result at 6 PM (PST) the next day.
tumblingWindow_offset :: Lens.Lens' TumblingWindow (Prelude.Maybe Prelude.Text)
tumblingWindow_offset :: (Maybe Text -> f (Maybe Text))
-> TumblingWindow -> f TumblingWindow
tumblingWindow_offset = (TumblingWindow -> Maybe Text)
-> (TumblingWindow -> Maybe Text -> TumblingWindow)
-> Lens TumblingWindow TumblingWindow (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TumblingWindow' {Maybe Text
offset :: Maybe Text
$sel:offset:TumblingWindow' :: TumblingWindow -> Maybe Text
offset} -> Maybe Text
offset) (\s :: TumblingWindow
s@TumblingWindow' {} Maybe Text
a -> TumblingWindow
s {$sel:offset:TumblingWindow' :: Maybe Text
offset = Maybe Text
a} :: TumblingWindow)

-- | The time interval for the tumbling window. The interval time must be
-- between 1 minute and 1 week.
--
-- IoT SiteWise computes the @1w@ interval the end of Sunday at midnight
-- each week (UTC), the @1d@ interval at the end of each day at midnight
-- (UTC), the @1h@ interval at the end of each hour, and so on.
--
-- When IoT SiteWise aggregates data points for metric computations, the
-- start of each interval is exclusive and the end of each interval is
-- inclusive. IoT SiteWise places the computed data point at the end of the
-- interval.
tumblingWindow_interval :: Lens.Lens' TumblingWindow Prelude.Text
tumblingWindow_interval :: (Text -> f Text) -> TumblingWindow -> f TumblingWindow
tumblingWindow_interval = (TumblingWindow -> Text)
-> (TumblingWindow -> Text -> TumblingWindow)
-> Lens TumblingWindow TumblingWindow Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TumblingWindow' {Text
interval :: Text
$sel:interval:TumblingWindow' :: TumblingWindow -> Text
interval} -> Text
interval) (\s :: TumblingWindow
s@TumblingWindow' {} Text
a -> TumblingWindow
s {$sel:interval:TumblingWindow' :: Text
interval = Text
a} :: TumblingWindow)

instance Core.FromJSON TumblingWindow where
  parseJSON :: Value -> Parser TumblingWindow
parseJSON =
    String
-> (Object -> Parser TumblingWindow)
-> Value
-> Parser TumblingWindow
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TumblingWindow"
      ( \Object
x ->
          Maybe Text -> Text -> TumblingWindow
TumblingWindow'
            (Maybe Text -> Text -> TumblingWindow)
-> Parser (Maybe Text) -> Parser (Text -> TumblingWindow)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"offset")
            Parser (Text -> TumblingWindow)
-> Parser Text -> Parser TumblingWindow
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
"interval")
      )

instance Prelude.Hashable TumblingWindow

instance Prelude.NFData TumblingWindow

instance Core.ToJSON TumblingWindow where
  toJSON :: TumblingWindow -> Value
toJSON TumblingWindow' {Maybe Text
Text
interval :: Text
offset :: Maybe Text
$sel:interval:TumblingWindow' :: TumblingWindow -> Text
$sel:offset:TumblingWindow' :: TumblingWindow -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"offset" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
offset,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"interval" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
interval)
          ]
      )