{-# 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.UniqueValuesComputation
-- 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.UniqueValuesComputation 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.DimensionField

-- | The unique values computation configuration.
--
-- /See:/ 'newUniqueValuesComputation' smart constructor.
data UniqueValuesComputation = UniqueValuesComputation'
  { -- | The name of a computation.
    UniqueValuesComputation -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The ID for a computation.
    UniqueValuesComputation -> Text
computationId :: Prelude.Text,
    -- | The category field that is used in a computation.
    UniqueValuesComputation -> DimensionField
category :: DimensionField
  }
  deriving (UniqueValuesComputation -> UniqueValuesComputation -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UniqueValuesComputation -> UniqueValuesComputation -> Bool
$c/= :: UniqueValuesComputation -> UniqueValuesComputation -> Bool
== :: UniqueValuesComputation -> UniqueValuesComputation -> Bool
$c== :: UniqueValuesComputation -> UniqueValuesComputation -> Bool
Prelude.Eq, Int -> UniqueValuesComputation -> ShowS
[UniqueValuesComputation] -> ShowS
UniqueValuesComputation -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UniqueValuesComputation] -> ShowS
$cshowList :: [UniqueValuesComputation] -> ShowS
show :: UniqueValuesComputation -> String
$cshow :: UniqueValuesComputation -> String
showsPrec :: Int -> UniqueValuesComputation -> ShowS
$cshowsPrec :: Int -> UniqueValuesComputation -> ShowS
Prelude.Show, forall x. Rep UniqueValuesComputation x -> UniqueValuesComputation
forall x. UniqueValuesComputation -> Rep UniqueValuesComputation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UniqueValuesComputation x -> UniqueValuesComputation
$cfrom :: forall x. UniqueValuesComputation -> Rep UniqueValuesComputation x
Prelude.Generic)

-- |
-- Create a value of 'UniqueValuesComputation' 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:
--
-- 'name', 'uniqueValuesComputation_name' - The name of a computation.
--
-- 'computationId', 'uniqueValuesComputation_computationId' - The ID for a computation.
--
-- 'category', 'uniqueValuesComputation_category' - The category field that is used in a computation.
newUniqueValuesComputation ::
  -- | 'computationId'
  Prelude.Text ->
  -- | 'category'
  DimensionField ->
  UniqueValuesComputation
newUniqueValuesComputation :: Text -> DimensionField -> UniqueValuesComputation
newUniqueValuesComputation Text
pComputationId_ DimensionField
pCategory_ =
  UniqueValuesComputation'
    { $sel:name:UniqueValuesComputation' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:computationId:UniqueValuesComputation' :: Text
computationId = Text
pComputationId_,
      $sel:category:UniqueValuesComputation' :: DimensionField
category = DimensionField
pCategory_
    }

-- | The name of a computation.
uniqueValuesComputation_name :: Lens.Lens' UniqueValuesComputation (Prelude.Maybe Prelude.Text)
uniqueValuesComputation_name :: Lens' UniqueValuesComputation (Maybe Text)
uniqueValuesComputation_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UniqueValuesComputation' {Maybe Text
name :: Maybe Text
$sel:name:UniqueValuesComputation' :: UniqueValuesComputation -> Maybe Text
name} -> Maybe Text
name) (\s :: UniqueValuesComputation
s@UniqueValuesComputation' {} Maybe Text
a -> UniqueValuesComputation
s {$sel:name:UniqueValuesComputation' :: Maybe Text
name = Maybe Text
a} :: UniqueValuesComputation)

-- | The ID for a computation.
uniqueValuesComputation_computationId :: Lens.Lens' UniqueValuesComputation Prelude.Text
uniqueValuesComputation_computationId :: Lens' UniqueValuesComputation Text
uniqueValuesComputation_computationId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UniqueValuesComputation' {Text
computationId :: Text
$sel:computationId:UniqueValuesComputation' :: UniqueValuesComputation -> Text
computationId} -> Text
computationId) (\s :: UniqueValuesComputation
s@UniqueValuesComputation' {} Text
a -> UniqueValuesComputation
s {$sel:computationId:UniqueValuesComputation' :: Text
computationId = Text
a} :: UniqueValuesComputation)

-- | The category field that is used in a computation.
uniqueValuesComputation_category :: Lens.Lens' UniqueValuesComputation DimensionField
uniqueValuesComputation_category :: Lens' UniqueValuesComputation DimensionField
uniqueValuesComputation_category = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UniqueValuesComputation' {DimensionField
category :: DimensionField
$sel:category:UniqueValuesComputation' :: UniqueValuesComputation -> DimensionField
category} -> DimensionField
category) (\s :: UniqueValuesComputation
s@UniqueValuesComputation' {} DimensionField
a -> UniqueValuesComputation
s {$sel:category:UniqueValuesComputation' :: DimensionField
category = DimensionField
a} :: UniqueValuesComputation)

instance Data.FromJSON UniqueValuesComputation where
  parseJSON :: Value -> Parser UniqueValuesComputation
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"UniqueValuesComputation"
      ( \Object
x ->
          Maybe Text -> Text -> DimensionField -> UniqueValuesComputation
UniqueValuesComputation'
            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
"Name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ComputationId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Category")
      )

instance Prelude.Hashable UniqueValuesComputation where
  hashWithSalt :: Int -> UniqueValuesComputation -> Int
hashWithSalt Int
_salt UniqueValuesComputation' {Maybe Text
Text
DimensionField
category :: DimensionField
computationId :: Text
name :: Maybe Text
$sel:category:UniqueValuesComputation' :: UniqueValuesComputation -> DimensionField
$sel:computationId:UniqueValuesComputation' :: UniqueValuesComputation -> Text
$sel:name:UniqueValuesComputation' :: UniqueValuesComputation -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
computationId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` DimensionField
category

instance Prelude.NFData UniqueValuesComputation where
  rnf :: UniqueValuesComputation -> ()
rnf UniqueValuesComputation' {Maybe Text
Text
DimensionField
category :: DimensionField
computationId :: Text
name :: Maybe Text
$sel:category:UniqueValuesComputation' :: UniqueValuesComputation -> DimensionField
$sel:computationId:UniqueValuesComputation' :: UniqueValuesComputation -> Text
$sel:name:UniqueValuesComputation' :: UniqueValuesComputation -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
computationId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf DimensionField
category

instance Data.ToJSON UniqueValuesComputation where
  toJSON :: UniqueValuesComputation -> Value
toJSON UniqueValuesComputation' {Maybe Text
Text
DimensionField
category :: DimensionField
computationId :: Text
name :: Maybe Text
$sel:category:UniqueValuesComputation' :: UniqueValuesComputation -> DimensionField
$sel:computationId:UniqueValuesComputation' :: UniqueValuesComputation -> Text
$sel:name:UniqueValuesComputation' :: UniqueValuesComputation -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Name" 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 Text
name,
            forall a. a -> Maybe a
Prelude.Just (Key
"ComputationId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
computationId),
            forall a. a -> Maybe a
Prelude.Just (Key
"Category" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= DimensionField
category)
          ]
      )