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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoTSiteWise.Types.TumblingWindow
import qualified Amazonka.Prelude as Prelude

-- | Contains a time interval window used for data aggregate computations
-- (for example, average, sum, count, and so on).
--
-- /See:/ 'newMetricWindow' smart constructor.
data MetricWindow = MetricWindow'
  { -- | The tumbling time interval window.
    MetricWindow -> Maybe TumblingWindow
tumbling :: Prelude.Maybe TumblingWindow
  }
  deriving (MetricWindow -> MetricWindow -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricWindow -> MetricWindow -> Bool
$c/= :: MetricWindow -> MetricWindow -> Bool
== :: MetricWindow -> MetricWindow -> Bool
$c== :: MetricWindow -> MetricWindow -> Bool
Prelude.Eq, ReadPrec [MetricWindow]
ReadPrec MetricWindow
Int -> ReadS MetricWindow
ReadS [MetricWindow]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricWindow]
$creadListPrec :: ReadPrec [MetricWindow]
readPrec :: ReadPrec MetricWindow
$creadPrec :: ReadPrec MetricWindow
readList :: ReadS [MetricWindow]
$creadList :: ReadS [MetricWindow]
readsPrec :: Int -> ReadS MetricWindow
$creadsPrec :: Int -> ReadS MetricWindow
Prelude.Read, Int -> MetricWindow -> ShowS
[MetricWindow] -> ShowS
MetricWindow -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricWindow] -> ShowS
$cshowList :: [MetricWindow] -> ShowS
show :: MetricWindow -> String
$cshow :: MetricWindow -> String
showsPrec :: Int -> MetricWindow -> ShowS
$cshowsPrec :: Int -> MetricWindow -> ShowS
Prelude.Show, forall x. Rep MetricWindow x -> MetricWindow
forall x. MetricWindow -> Rep MetricWindow x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricWindow x -> MetricWindow
$cfrom :: forall x. MetricWindow -> Rep MetricWindow x
Prelude.Generic)

-- |
-- Create a value of 'MetricWindow' 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:
--
-- 'tumbling', 'metricWindow_tumbling' - The tumbling time interval window.
newMetricWindow ::
  MetricWindow
newMetricWindow :: MetricWindow
newMetricWindow =
  MetricWindow' {$sel:tumbling:MetricWindow' :: Maybe TumblingWindow
tumbling = forall a. Maybe a
Prelude.Nothing}

-- | The tumbling time interval window.
metricWindow_tumbling :: Lens.Lens' MetricWindow (Prelude.Maybe TumblingWindow)
metricWindow_tumbling :: Lens' MetricWindow (Maybe TumblingWindow)
metricWindow_tumbling = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricWindow' {Maybe TumblingWindow
tumbling :: Maybe TumblingWindow
$sel:tumbling:MetricWindow' :: MetricWindow -> Maybe TumblingWindow
tumbling} -> Maybe TumblingWindow
tumbling) (\s :: MetricWindow
s@MetricWindow' {} Maybe TumblingWindow
a -> MetricWindow
s {$sel:tumbling:MetricWindow' :: Maybe TumblingWindow
tumbling = Maybe TumblingWindow
a} :: MetricWindow)

instance Data.FromJSON MetricWindow where
  parseJSON :: Value -> Parser MetricWindow
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MetricWindow"
      ( \Object
x ->
          Maybe TumblingWindow -> MetricWindow
MetricWindow' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"tumbling")
      )

instance Prelude.Hashable MetricWindow where
  hashWithSalt :: Int -> MetricWindow -> Int
hashWithSalt Int
_salt MetricWindow' {Maybe TumblingWindow
tumbling :: Maybe TumblingWindow
$sel:tumbling:MetricWindow' :: MetricWindow -> Maybe TumblingWindow
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe TumblingWindow
tumbling

instance Prelude.NFData MetricWindow where
  rnf :: MetricWindow -> ()
rnf MetricWindow' {Maybe TumblingWindow
tumbling :: Maybe TumblingWindow
$sel:tumbling:MetricWindow' :: MetricWindow -> Maybe TumblingWindow
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe TumblingWindow
tumbling

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