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

import qualified Amazonka.Core as Core
import Amazonka.IoTSiteWise.Types.TumblingWindow
import qualified Amazonka.Lens as Lens
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
(MetricWindow -> MetricWindow -> Bool)
-> (MetricWindow -> MetricWindow -> Bool) -> Eq MetricWindow
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]
(Int -> ReadS MetricWindow)
-> ReadS [MetricWindow]
-> ReadPrec MetricWindow
-> ReadPrec [MetricWindow]
-> Read 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
(Int -> MetricWindow -> ShowS)
-> (MetricWindow -> String)
-> ([MetricWindow] -> ShowS)
-> Show MetricWindow
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. MetricWindow -> Rep MetricWindow x)
-> (forall x. Rep MetricWindow x -> MetricWindow)
-> Generic MetricWindow
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' :: Maybe TumblingWindow -> MetricWindow
MetricWindow' {$sel:tumbling:MetricWindow' :: Maybe TumblingWindow
tumbling = Maybe TumblingWindow
forall a. Maybe a
Prelude.Nothing}

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

instance Prelude.Hashable MetricWindow

instance Prelude.NFData MetricWindow

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