{-# 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.QuickSight.Types.NumericalAggregationFunction
-- 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.QuickSight.Types.NumericalAggregationFunction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.QuickSight.Types.PercentileAggregation
import Amazonka.QuickSight.Types.SimpleNumericalAggregationFunction

-- | Aggregation for numerical values.
--
-- /See:/ 'newNumericalAggregationFunction' smart constructor.
data NumericalAggregationFunction = NumericalAggregationFunction'
  { -- | An aggregation based on the percentile of values in a dimension or
    -- measure.
    NumericalAggregationFunction -> Maybe PercentileAggregation
percentileAggregation :: Prelude.Maybe PercentileAggregation,
    -- | Built-in aggregation functions for numerical values.
    --
    -- -   @SUM@: The sum of a dimension or measure.
    --
    -- -   @AVERAGE@: The average of a dimension or measure.
    --
    -- -   @MIN@: The minimum value of a dimension or measure.
    --
    -- -   @MAX@: The maximum value of a dimension or measure.
    --
    -- -   @COUNT@: The count of a dimension or measure.
    --
    -- -   @DISTINCT_COUNT@: The count of distinct values in a dimension or
    --     measure.
    --
    -- -   @VAR@: The variance of a dimension or measure.
    --
    -- -   @VARP@: The partitioned variance of a dimension or measure.
    --
    -- -   @STDEV@: The standard deviation of a dimension or measure.
    --
    -- -   @STDEVP@: The partitioned standard deviation of a dimension or
    --     measure.
    --
    -- -   @MEDIAN@: The median value of a dimension or measure.
    NumericalAggregationFunction
-> Maybe SimpleNumericalAggregationFunction
simpleNumericalAggregation :: Prelude.Maybe SimpleNumericalAggregationFunction
  }
  deriving (NumericalAggregationFunction
-> NumericalAggregationFunction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NumericalAggregationFunction
-> NumericalAggregationFunction -> Bool
$c/= :: NumericalAggregationFunction
-> NumericalAggregationFunction -> Bool
== :: NumericalAggregationFunction
-> NumericalAggregationFunction -> Bool
$c== :: NumericalAggregationFunction
-> NumericalAggregationFunction -> Bool
Prelude.Eq, ReadPrec [NumericalAggregationFunction]
ReadPrec NumericalAggregationFunction
Int -> ReadS NumericalAggregationFunction
ReadS [NumericalAggregationFunction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NumericalAggregationFunction]
$creadListPrec :: ReadPrec [NumericalAggregationFunction]
readPrec :: ReadPrec NumericalAggregationFunction
$creadPrec :: ReadPrec NumericalAggregationFunction
readList :: ReadS [NumericalAggregationFunction]
$creadList :: ReadS [NumericalAggregationFunction]
readsPrec :: Int -> ReadS NumericalAggregationFunction
$creadsPrec :: Int -> ReadS NumericalAggregationFunction
Prelude.Read, Int -> NumericalAggregationFunction -> ShowS
[NumericalAggregationFunction] -> ShowS
NumericalAggregationFunction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NumericalAggregationFunction] -> ShowS
$cshowList :: [NumericalAggregationFunction] -> ShowS
show :: NumericalAggregationFunction -> String
$cshow :: NumericalAggregationFunction -> String
showsPrec :: Int -> NumericalAggregationFunction -> ShowS
$cshowsPrec :: Int -> NumericalAggregationFunction -> ShowS
Prelude.Show, forall x.
Rep NumericalAggregationFunction x -> NumericalAggregationFunction
forall x.
NumericalAggregationFunction -> Rep NumericalAggregationFunction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep NumericalAggregationFunction x -> NumericalAggregationFunction
$cfrom :: forall x.
NumericalAggregationFunction -> Rep NumericalAggregationFunction x
Prelude.Generic)

-- |
-- Create a value of 'NumericalAggregationFunction' 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:
--
-- 'percentileAggregation', 'numericalAggregationFunction_percentileAggregation' - An aggregation based on the percentile of values in a dimension or
-- measure.
--
-- 'simpleNumericalAggregation', 'numericalAggregationFunction_simpleNumericalAggregation' - Built-in aggregation functions for numerical values.
--
-- -   @SUM@: The sum of a dimension or measure.
--
-- -   @AVERAGE@: The average of a dimension or measure.
--
-- -   @MIN@: The minimum value of a dimension or measure.
--
-- -   @MAX@: The maximum value of a dimension or measure.
--
-- -   @COUNT@: The count of a dimension or measure.
--
-- -   @DISTINCT_COUNT@: The count of distinct values in a dimension or
--     measure.
--
-- -   @VAR@: The variance of a dimension or measure.
--
-- -   @VARP@: The partitioned variance of a dimension or measure.
--
-- -   @STDEV@: The standard deviation of a dimension or measure.
--
-- -   @STDEVP@: The partitioned standard deviation of a dimension or
--     measure.
--
-- -   @MEDIAN@: The median value of a dimension or measure.
newNumericalAggregationFunction ::
  NumericalAggregationFunction
newNumericalAggregationFunction :: NumericalAggregationFunction
newNumericalAggregationFunction =
  NumericalAggregationFunction'
    { $sel:percentileAggregation:NumericalAggregationFunction' :: Maybe PercentileAggregation
percentileAggregation =
        forall a. Maybe a
Prelude.Nothing,
      $sel:simpleNumericalAggregation:NumericalAggregationFunction' :: Maybe SimpleNumericalAggregationFunction
simpleNumericalAggregation = forall a. Maybe a
Prelude.Nothing
    }

-- | An aggregation based on the percentile of values in a dimension or
-- measure.
numericalAggregationFunction_percentileAggregation :: Lens.Lens' NumericalAggregationFunction (Prelude.Maybe PercentileAggregation)
numericalAggregationFunction_percentileAggregation :: Lens' NumericalAggregationFunction (Maybe PercentileAggregation)
numericalAggregationFunction_percentileAggregation = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NumericalAggregationFunction' {Maybe PercentileAggregation
percentileAggregation :: Maybe PercentileAggregation
$sel:percentileAggregation:NumericalAggregationFunction' :: NumericalAggregationFunction -> Maybe PercentileAggregation
percentileAggregation} -> Maybe PercentileAggregation
percentileAggregation) (\s :: NumericalAggregationFunction
s@NumericalAggregationFunction' {} Maybe PercentileAggregation
a -> NumericalAggregationFunction
s {$sel:percentileAggregation:NumericalAggregationFunction' :: Maybe PercentileAggregation
percentileAggregation = Maybe PercentileAggregation
a} :: NumericalAggregationFunction)

-- | Built-in aggregation functions for numerical values.
--
-- -   @SUM@: The sum of a dimension or measure.
--
-- -   @AVERAGE@: The average of a dimension or measure.
--
-- -   @MIN@: The minimum value of a dimension or measure.
--
-- -   @MAX@: The maximum value of a dimension or measure.
--
-- -   @COUNT@: The count of a dimension or measure.
--
-- -   @DISTINCT_COUNT@: The count of distinct values in a dimension or
--     measure.
--
-- -   @VAR@: The variance of a dimension or measure.
--
-- -   @VARP@: The partitioned variance of a dimension or measure.
--
-- -   @STDEV@: The standard deviation of a dimension or measure.
--
-- -   @STDEVP@: The partitioned standard deviation of a dimension or
--     measure.
--
-- -   @MEDIAN@: The median value of a dimension or measure.
numericalAggregationFunction_simpleNumericalAggregation :: Lens.Lens' NumericalAggregationFunction (Prelude.Maybe SimpleNumericalAggregationFunction)
numericalAggregationFunction_simpleNumericalAggregation :: Lens'
  NumericalAggregationFunction
  (Maybe SimpleNumericalAggregationFunction)
numericalAggregationFunction_simpleNumericalAggregation = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NumericalAggregationFunction' {Maybe SimpleNumericalAggregationFunction
simpleNumericalAggregation :: Maybe SimpleNumericalAggregationFunction
$sel:simpleNumericalAggregation:NumericalAggregationFunction' :: NumericalAggregationFunction
-> Maybe SimpleNumericalAggregationFunction
simpleNumericalAggregation} -> Maybe SimpleNumericalAggregationFunction
simpleNumericalAggregation) (\s :: NumericalAggregationFunction
s@NumericalAggregationFunction' {} Maybe SimpleNumericalAggregationFunction
a -> NumericalAggregationFunction
s {$sel:simpleNumericalAggregation:NumericalAggregationFunction' :: Maybe SimpleNumericalAggregationFunction
simpleNumericalAggregation = Maybe SimpleNumericalAggregationFunction
a} :: NumericalAggregationFunction)

instance Data.FromJSON NumericalAggregationFunction where
  parseJSON :: Value -> Parser NumericalAggregationFunction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"NumericalAggregationFunction"
      ( \Object
x ->
          Maybe PercentileAggregation
-> Maybe SimpleNumericalAggregationFunction
-> NumericalAggregationFunction
NumericalAggregationFunction'
            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
"PercentileAggregation")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"SimpleNumericalAggregation")
      )

instance
  Prelude.Hashable
    NumericalAggregationFunction
  where
  hashWithSalt :: Int -> NumericalAggregationFunction -> Int
hashWithSalt Int
_salt NumericalAggregationFunction' {Maybe PercentileAggregation
Maybe SimpleNumericalAggregationFunction
simpleNumericalAggregation :: Maybe SimpleNumericalAggregationFunction
percentileAggregation :: Maybe PercentileAggregation
$sel:simpleNumericalAggregation:NumericalAggregationFunction' :: NumericalAggregationFunction
-> Maybe SimpleNumericalAggregationFunction
$sel:percentileAggregation:NumericalAggregationFunction' :: NumericalAggregationFunction -> Maybe PercentileAggregation
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe PercentileAggregation
percentileAggregation
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe SimpleNumericalAggregationFunction
simpleNumericalAggregation

instance Prelude.NFData NumericalAggregationFunction where
  rnf :: NumericalAggregationFunction -> ()
rnf NumericalAggregationFunction' {Maybe PercentileAggregation
Maybe SimpleNumericalAggregationFunction
simpleNumericalAggregation :: Maybe SimpleNumericalAggregationFunction
percentileAggregation :: Maybe PercentileAggregation
$sel:simpleNumericalAggregation:NumericalAggregationFunction' :: NumericalAggregationFunction
-> Maybe SimpleNumericalAggregationFunction
$sel:percentileAggregation:NumericalAggregationFunction' :: NumericalAggregationFunction -> Maybe PercentileAggregation
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe PercentileAggregation
percentileAggregation
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe SimpleNumericalAggregationFunction
simpleNumericalAggregation

instance Data.ToJSON NumericalAggregationFunction where
  toJSON :: NumericalAggregationFunction -> Value
toJSON NumericalAggregationFunction' {Maybe PercentileAggregation
Maybe SimpleNumericalAggregationFunction
simpleNumericalAggregation :: Maybe SimpleNumericalAggregationFunction
percentileAggregation :: Maybe PercentileAggregation
$sel:simpleNumericalAggregation:NumericalAggregationFunction' :: NumericalAggregationFunction
-> Maybe SimpleNumericalAggregationFunction
$sel:percentileAggregation:NumericalAggregationFunction' :: NumericalAggregationFunction -> Maybe PercentileAggregation
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"PercentileAggregation" 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 PercentileAggregation
percentileAggregation,
            (Key
"SimpleNumericalAggregation" 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 SimpleNumericalAggregationFunction
simpleNumericalAggregation
          ]
      )