{-# 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.IoT.Types.StatisticalThreshold
-- 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.IoT.Types.StatisticalThreshold where

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

-- | A statistical ranking (percentile) that indicates a threshold value by
-- which a behavior is determined to be in compliance or in violation of
-- the behavior.
--
-- /See:/ 'newStatisticalThreshold' smart constructor.
data StatisticalThreshold = StatisticalThreshold'
  { -- | The percentile that resolves to a threshold value by which compliance
    -- with a behavior is determined. Metrics are collected over the specified
    -- period (@durationSeconds@) from all reporting devices in your account
    -- and statistical ranks are calculated. Then, the measurements from a
    -- device are collected over the same period. If the accumulated
    -- measurements from the device fall above or below (@comparisonOperator@)
    -- the value associated with the percentile specified, then the device is
    -- considered to be in compliance with the behavior, otherwise a violation
    -- occurs.
    StatisticalThreshold -> Maybe Text
statistic :: Prelude.Maybe Prelude.Text
  }
  deriving (StatisticalThreshold -> StatisticalThreshold -> Bool
(StatisticalThreshold -> StatisticalThreshold -> Bool)
-> (StatisticalThreshold -> StatisticalThreshold -> Bool)
-> Eq StatisticalThreshold
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StatisticalThreshold -> StatisticalThreshold -> Bool
$c/= :: StatisticalThreshold -> StatisticalThreshold -> Bool
== :: StatisticalThreshold -> StatisticalThreshold -> Bool
$c== :: StatisticalThreshold -> StatisticalThreshold -> Bool
Prelude.Eq, ReadPrec [StatisticalThreshold]
ReadPrec StatisticalThreshold
Int -> ReadS StatisticalThreshold
ReadS [StatisticalThreshold]
(Int -> ReadS StatisticalThreshold)
-> ReadS [StatisticalThreshold]
-> ReadPrec StatisticalThreshold
-> ReadPrec [StatisticalThreshold]
-> Read StatisticalThreshold
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StatisticalThreshold]
$creadListPrec :: ReadPrec [StatisticalThreshold]
readPrec :: ReadPrec StatisticalThreshold
$creadPrec :: ReadPrec StatisticalThreshold
readList :: ReadS [StatisticalThreshold]
$creadList :: ReadS [StatisticalThreshold]
readsPrec :: Int -> ReadS StatisticalThreshold
$creadsPrec :: Int -> ReadS StatisticalThreshold
Prelude.Read, Int -> StatisticalThreshold -> ShowS
[StatisticalThreshold] -> ShowS
StatisticalThreshold -> String
(Int -> StatisticalThreshold -> ShowS)
-> (StatisticalThreshold -> String)
-> ([StatisticalThreshold] -> ShowS)
-> Show StatisticalThreshold
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StatisticalThreshold] -> ShowS
$cshowList :: [StatisticalThreshold] -> ShowS
show :: StatisticalThreshold -> String
$cshow :: StatisticalThreshold -> String
showsPrec :: Int -> StatisticalThreshold -> ShowS
$cshowsPrec :: Int -> StatisticalThreshold -> ShowS
Prelude.Show, (forall x. StatisticalThreshold -> Rep StatisticalThreshold x)
-> (forall x. Rep StatisticalThreshold x -> StatisticalThreshold)
-> Generic StatisticalThreshold
forall x. Rep StatisticalThreshold x -> StatisticalThreshold
forall x. StatisticalThreshold -> Rep StatisticalThreshold x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StatisticalThreshold x -> StatisticalThreshold
$cfrom :: forall x. StatisticalThreshold -> Rep StatisticalThreshold x
Prelude.Generic)

-- |
-- Create a value of 'StatisticalThreshold' 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:
--
-- 'statistic', 'statisticalThreshold_statistic' - The percentile that resolves to a threshold value by which compliance
-- with a behavior is determined. Metrics are collected over the specified
-- period (@durationSeconds@) from all reporting devices in your account
-- and statistical ranks are calculated. Then, the measurements from a
-- device are collected over the same period. If the accumulated
-- measurements from the device fall above or below (@comparisonOperator@)
-- the value associated with the percentile specified, then the device is
-- considered to be in compliance with the behavior, otherwise a violation
-- occurs.
newStatisticalThreshold ::
  StatisticalThreshold
newStatisticalThreshold :: StatisticalThreshold
newStatisticalThreshold =
  StatisticalThreshold' :: Maybe Text -> StatisticalThreshold
StatisticalThreshold' {$sel:statistic:StatisticalThreshold' :: Maybe Text
statistic = Maybe Text
forall a. Maybe a
Prelude.Nothing}

-- | The percentile that resolves to a threshold value by which compliance
-- with a behavior is determined. Metrics are collected over the specified
-- period (@durationSeconds@) from all reporting devices in your account
-- and statistical ranks are calculated. Then, the measurements from a
-- device are collected over the same period. If the accumulated
-- measurements from the device fall above or below (@comparisonOperator@)
-- the value associated with the percentile specified, then the device is
-- considered to be in compliance with the behavior, otherwise a violation
-- occurs.
statisticalThreshold_statistic :: Lens.Lens' StatisticalThreshold (Prelude.Maybe Prelude.Text)
statisticalThreshold_statistic :: (Maybe Text -> f (Maybe Text))
-> StatisticalThreshold -> f StatisticalThreshold
statisticalThreshold_statistic = (StatisticalThreshold -> Maybe Text)
-> (StatisticalThreshold -> Maybe Text -> StatisticalThreshold)
-> Lens
     StatisticalThreshold StatisticalThreshold (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StatisticalThreshold' {Maybe Text
statistic :: Maybe Text
$sel:statistic:StatisticalThreshold' :: StatisticalThreshold -> Maybe Text
statistic} -> Maybe Text
statistic) (\s :: StatisticalThreshold
s@StatisticalThreshold' {} Maybe Text
a -> StatisticalThreshold
s {$sel:statistic:StatisticalThreshold' :: Maybe Text
statistic = Maybe Text
a} :: StatisticalThreshold)

instance Core.FromJSON StatisticalThreshold where
  parseJSON :: Value -> Parser StatisticalThreshold
parseJSON =
    String
-> (Object -> Parser StatisticalThreshold)
-> Value
-> Parser StatisticalThreshold
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"StatisticalThreshold"
      ( \Object
x ->
          Maybe Text -> StatisticalThreshold
StatisticalThreshold'
            (Maybe Text -> StatisticalThreshold)
-> Parser (Maybe Text) -> Parser StatisticalThreshold
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
"statistic")
      )

instance Prelude.Hashable StatisticalThreshold

instance Prelude.NFData StatisticalThreshold

instance Core.ToJSON StatisticalThreshold where
  toJSON :: StatisticalThreshold -> Value
toJSON StatisticalThreshold' {Maybe Text
statistic :: Maybe Text
$sel:statistic:StatisticalThreshold' :: StatisticalThreshold -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"statistic" 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
statistic]
      )