{-# 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.AggregationFunction
-- 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.AggregationFunction 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.CategoricalAggregationFunction
import Amazonka.QuickSight.Types.DateAggregationFunction
import Amazonka.QuickSight.Types.NumericalAggregationFunction

-- | An aggregation function aggregates values from a dimension or measure.
--
-- This is a union type structure. For this structure to be valid, only one
-- of the attributes can be defined.
--
-- /See:/ 'newAggregationFunction' smart constructor.
data AggregationFunction = AggregationFunction'
  { -- | Aggregation for categorical values.
    --
    -- -   @COUNT@: Aggregate by the total number of values, including
    --     duplicates.
    --
    -- -   @DISTINCT_COUNT@: Aggregate by the total number of distinct values.
    AggregationFunction -> Maybe CategoricalAggregationFunction
categoricalAggregationFunction :: Prelude.Maybe CategoricalAggregationFunction,
    -- | Aggregation for date values.
    --
    -- -   @COUNT@: Aggregate by the total number of values, including
    --     duplicates.
    --
    -- -   @DISTINCT_COUNT@: Aggregate by the total number of distinct values.
    --
    -- -   @MIN@: Select the smallest date value.
    --
    -- -   @MAX@: Select the largest date value.
    AggregationFunction -> Maybe DateAggregationFunction
dateAggregationFunction :: Prelude.Maybe DateAggregationFunction,
    -- | Aggregation for numerical values.
    AggregationFunction -> Maybe NumericalAggregationFunction
numericalAggregationFunction :: Prelude.Maybe NumericalAggregationFunction
  }
  deriving (AggregationFunction -> AggregationFunction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AggregationFunction -> AggregationFunction -> Bool
$c/= :: AggregationFunction -> AggregationFunction -> Bool
== :: AggregationFunction -> AggregationFunction -> Bool
$c== :: AggregationFunction -> AggregationFunction -> Bool
Prelude.Eq, ReadPrec [AggregationFunction]
ReadPrec AggregationFunction
Int -> ReadS AggregationFunction
ReadS [AggregationFunction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AggregationFunction]
$creadListPrec :: ReadPrec [AggregationFunction]
readPrec :: ReadPrec AggregationFunction
$creadPrec :: ReadPrec AggregationFunction
readList :: ReadS [AggregationFunction]
$creadList :: ReadS [AggregationFunction]
readsPrec :: Int -> ReadS AggregationFunction
$creadsPrec :: Int -> ReadS AggregationFunction
Prelude.Read, Int -> AggregationFunction -> ShowS
[AggregationFunction] -> ShowS
AggregationFunction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AggregationFunction] -> ShowS
$cshowList :: [AggregationFunction] -> ShowS
show :: AggregationFunction -> String
$cshow :: AggregationFunction -> String
showsPrec :: Int -> AggregationFunction -> ShowS
$cshowsPrec :: Int -> AggregationFunction -> ShowS
Prelude.Show, forall x. Rep AggregationFunction x -> AggregationFunction
forall x. AggregationFunction -> Rep AggregationFunction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AggregationFunction x -> AggregationFunction
$cfrom :: forall x. AggregationFunction -> Rep AggregationFunction x
Prelude.Generic)

-- |
-- Create a value of 'AggregationFunction' 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:
--
-- 'categoricalAggregationFunction', 'aggregationFunction_categoricalAggregationFunction' - Aggregation for categorical values.
--
-- -   @COUNT@: Aggregate by the total number of values, including
--     duplicates.
--
-- -   @DISTINCT_COUNT@: Aggregate by the total number of distinct values.
--
-- 'dateAggregationFunction', 'aggregationFunction_dateAggregationFunction' - Aggregation for date values.
--
-- -   @COUNT@: Aggregate by the total number of values, including
--     duplicates.
--
-- -   @DISTINCT_COUNT@: Aggregate by the total number of distinct values.
--
-- -   @MIN@: Select the smallest date value.
--
-- -   @MAX@: Select the largest date value.
--
-- 'numericalAggregationFunction', 'aggregationFunction_numericalAggregationFunction' - Aggregation for numerical values.
newAggregationFunction ::
  AggregationFunction
newAggregationFunction :: AggregationFunction
newAggregationFunction =
  AggregationFunction'
    { $sel:categoricalAggregationFunction:AggregationFunction' :: Maybe CategoricalAggregationFunction
categoricalAggregationFunction =
        forall a. Maybe a
Prelude.Nothing,
      $sel:dateAggregationFunction:AggregationFunction' :: Maybe DateAggregationFunction
dateAggregationFunction = forall a. Maybe a
Prelude.Nothing,
      $sel:numericalAggregationFunction:AggregationFunction' :: Maybe NumericalAggregationFunction
numericalAggregationFunction = forall a. Maybe a
Prelude.Nothing
    }

-- | Aggregation for categorical values.
--
-- -   @COUNT@: Aggregate by the total number of values, including
--     duplicates.
--
-- -   @DISTINCT_COUNT@: Aggregate by the total number of distinct values.
aggregationFunction_categoricalAggregationFunction :: Lens.Lens' AggregationFunction (Prelude.Maybe CategoricalAggregationFunction)
aggregationFunction_categoricalAggregationFunction :: Lens' AggregationFunction (Maybe CategoricalAggregationFunction)
aggregationFunction_categoricalAggregationFunction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AggregationFunction' {Maybe CategoricalAggregationFunction
categoricalAggregationFunction :: Maybe CategoricalAggregationFunction
$sel:categoricalAggregationFunction:AggregationFunction' :: AggregationFunction -> Maybe CategoricalAggregationFunction
categoricalAggregationFunction} -> Maybe CategoricalAggregationFunction
categoricalAggregationFunction) (\s :: AggregationFunction
s@AggregationFunction' {} Maybe CategoricalAggregationFunction
a -> AggregationFunction
s {$sel:categoricalAggregationFunction:AggregationFunction' :: Maybe CategoricalAggregationFunction
categoricalAggregationFunction = Maybe CategoricalAggregationFunction
a} :: AggregationFunction)

-- | Aggregation for date values.
--
-- -   @COUNT@: Aggregate by the total number of values, including
--     duplicates.
--
-- -   @DISTINCT_COUNT@: Aggregate by the total number of distinct values.
--
-- -   @MIN@: Select the smallest date value.
--
-- -   @MAX@: Select the largest date value.
aggregationFunction_dateAggregationFunction :: Lens.Lens' AggregationFunction (Prelude.Maybe DateAggregationFunction)
aggregationFunction_dateAggregationFunction :: Lens' AggregationFunction (Maybe DateAggregationFunction)
aggregationFunction_dateAggregationFunction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AggregationFunction' {Maybe DateAggregationFunction
dateAggregationFunction :: Maybe DateAggregationFunction
$sel:dateAggregationFunction:AggregationFunction' :: AggregationFunction -> Maybe DateAggregationFunction
dateAggregationFunction} -> Maybe DateAggregationFunction
dateAggregationFunction) (\s :: AggregationFunction
s@AggregationFunction' {} Maybe DateAggregationFunction
a -> AggregationFunction
s {$sel:dateAggregationFunction:AggregationFunction' :: Maybe DateAggregationFunction
dateAggregationFunction = Maybe DateAggregationFunction
a} :: AggregationFunction)

-- | Aggregation for numerical values.
aggregationFunction_numericalAggregationFunction :: Lens.Lens' AggregationFunction (Prelude.Maybe NumericalAggregationFunction)
aggregationFunction_numericalAggregationFunction :: Lens' AggregationFunction (Maybe NumericalAggregationFunction)
aggregationFunction_numericalAggregationFunction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AggregationFunction' {Maybe NumericalAggregationFunction
numericalAggregationFunction :: Maybe NumericalAggregationFunction
$sel:numericalAggregationFunction:AggregationFunction' :: AggregationFunction -> Maybe NumericalAggregationFunction
numericalAggregationFunction} -> Maybe NumericalAggregationFunction
numericalAggregationFunction) (\s :: AggregationFunction
s@AggregationFunction' {} Maybe NumericalAggregationFunction
a -> AggregationFunction
s {$sel:numericalAggregationFunction:AggregationFunction' :: Maybe NumericalAggregationFunction
numericalAggregationFunction = Maybe NumericalAggregationFunction
a} :: AggregationFunction)

instance Data.FromJSON AggregationFunction where
  parseJSON :: Value -> Parser AggregationFunction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AggregationFunction"
      ( \Object
x ->
          Maybe CategoricalAggregationFunction
-> Maybe DateAggregationFunction
-> Maybe NumericalAggregationFunction
-> AggregationFunction
AggregationFunction'
            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
"CategoricalAggregationFunction")
            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
"DateAggregationFunction")
            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
"NumericalAggregationFunction")
      )

instance Prelude.Hashable AggregationFunction where
  hashWithSalt :: Int -> AggregationFunction -> Int
hashWithSalt Int
_salt AggregationFunction' {Maybe CategoricalAggregationFunction
Maybe DateAggregationFunction
Maybe NumericalAggregationFunction
numericalAggregationFunction :: Maybe NumericalAggregationFunction
dateAggregationFunction :: Maybe DateAggregationFunction
categoricalAggregationFunction :: Maybe CategoricalAggregationFunction
$sel:numericalAggregationFunction:AggregationFunction' :: AggregationFunction -> Maybe NumericalAggregationFunction
$sel:dateAggregationFunction:AggregationFunction' :: AggregationFunction -> Maybe DateAggregationFunction
$sel:categoricalAggregationFunction:AggregationFunction' :: AggregationFunction -> Maybe CategoricalAggregationFunction
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CategoricalAggregationFunction
categoricalAggregationFunction
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DateAggregationFunction
dateAggregationFunction
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe NumericalAggregationFunction
numericalAggregationFunction

instance Prelude.NFData AggregationFunction where
  rnf :: AggregationFunction -> ()
rnf AggregationFunction' {Maybe CategoricalAggregationFunction
Maybe DateAggregationFunction
Maybe NumericalAggregationFunction
numericalAggregationFunction :: Maybe NumericalAggregationFunction
dateAggregationFunction :: Maybe DateAggregationFunction
categoricalAggregationFunction :: Maybe CategoricalAggregationFunction
$sel:numericalAggregationFunction:AggregationFunction' :: AggregationFunction -> Maybe NumericalAggregationFunction
$sel:dateAggregationFunction:AggregationFunction' :: AggregationFunction -> Maybe DateAggregationFunction
$sel:categoricalAggregationFunction:AggregationFunction' :: AggregationFunction -> Maybe CategoricalAggregationFunction
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe CategoricalAggregationFunction
categoricalAggregationFunction
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe DateAggregationFunction
dateAggregationFunction
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe NumericalAggregationFunction
numericalAggregationFunction

instance Data.ToJSON AggregationFunction where
  toJSON :: AggregationFunction -> Value
toJSON AggregationFunction' {Maybe CategoricalAggregationFunction
Maybe DateAggregationFunction
Maybe NumericalAggregationFunction
numericalAggregationFunction :: Maybe NumericalAggregationFunction
dateAggregationFunction :: Maybe DateAggregationFunction
categoricalAggregationFunction :: Maybe CategoricalAggregationFunction
$sel:numericalAggregationFunction:AggregationFunction' :: AggregationFunction -> Maybe NumericalAggregationFunction
$sel:dateAggregationFunction:AggregationFunction' :: AggregationFunction -> Maybe DateAggregationFunction
$sel:categoricalAggregationFunction:AggregationFunction' :: AggregationFunction -> Maybe CategoricalAggregationFunction
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CategoricalAggregationFunction" 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 CategoricalAggregationFunction
categoricalAggregationFunction,
            (Key
"DateAggregationFunction" 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 DateAggregationFunction
dateAggregationFunction,
            (Key
"NumericalAggregationFunction" 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 NumericalAggregationFunction
numericalAggregationFunction
          ]
      )