{-# 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.DateMeasureField
-- 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.DateMeasureField 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.ColumnIdentifier
import Amazonka.QuickSight.Types.DateAggregationFunction
import Amazonka.QuickSight.Types.DateTimeFormatConfiguration

-- | The measure type field with date type columns.
--
-- /See:/ 'newDateMeasureField' smart constructor.
data DateMeasureField = DateMeasureField'
  { -- | The aggregation function of the measure field.
    DateMeasureField -> Maybe DateAggregationFunction
aggregationFunction :: Prelude.Maybe DateAggregationFunction,
    -- | The format configuration of the field.
    DateMeasureField -> Maybe DateTimeFormatConfiguration
formatConfiguration :: Prelude.Maybe DateTimeFormatConfiguration,
    -- | The custom field ID.
    DateMeasureField -> Text
fieldId :: Prelude.Text,
    -- | The column that is used in the @DateMeasureField@.
    DateMeasureField -> ColumnIdentifier
column :: ColumnIdentifier
  }
  deriving (DateMeasureField -> DateMeasureField -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DateMeasureField -> DateMeasureField -> Bool
$c/= :: DateMeasureField -> DateMeasureField -> Bool
== :: DateMeasureField -> DateMeasureField -> Bool
$c== :: DateMeasureField -> DateMeasureField -> Bool
Prelude.Eq, Int -> DateMeasureField -> ShowS
[DateMeasureField] -> ShowS
DateMeasureField -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DateMeasureField] -> ShowS
$cshowList :: [DateMeasureField] -> ShowS
show :: DateMeasureField -> String
$cshow :: DateMeasureField -> String
showsPrec :: Int -> DateMeasureField -> ShowS
$cshowsPrec :: Int -> DateMeasureField -> ShowS
Prelude.Show, forall x. Rep DateMeasureField x -> DateMeasureField
forall x. DateMeasureField -> Rep DateMeasureField x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DateMeasureField x -> DateMeasureField
$cfrom :: forall x. DateMeasureField -> Rep DateMeasureField x
Prelude.Generic)

-- |
-- Create a value of 'DateMeasureField' 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:
--
-- 'aggregationFunction', 'dateMeasureField_aggregationFunction' - The aggregation function of the measure field.
--
-- 'formatConfiguration', 'dateMeasureField_formatConfiguration' - The format configuration of the field.
--
-- 'fieldId', 'dateMeasureField_fieldId' - The custom field ID.
--
-- 'column', 'dateMeasureField_column' - The column that is used in the @DateMeasureField@.
newDateMeasureField ::
  -- | 'fieldId'
  Prelude.Text ->
  -- | 'column'
  ColumnIdentifier ->
  DateMeasureField
newDateMeasureField :: Text -> ColumnIdentifier -> DateMeasureField
newDateMeasureField Text
pFieldId_ ColumnIdentifier
pColumn_ =
  DateMeasureField'
    { $sel:aggregationFunction:DateMeasureField' :: Maybe DateAggregationFunction
aggregationFunction =
        forall a. Maybe a
Prelude.Nothing,
      $sel:formatConfiguration:DateMeasureField' :: Maybe DateTimeFormatConfiguration
formatConfiguration = forall a. Maybe a
Prelude.Nothing,
      $sel:fieldId:DateMeasureField' :: Text
fieldId = Text
pFieldId_,
      $sel:column:DateMeasureField' :: ColumnIdentifier
column = ColumnIdentifier
pColumn_
    }

-- | The aggregation function of the measure field.
dateMeasureField_aggregationFunction :: Lens.Lens' DateMeasureField (Prelude.Maybe DateAggregationFunction)
dateMeasureField_aggregationFunction :: Lens' DateMeasureField (Maybe DateAggregationFunction)
dateMeasureField_aggregationFunction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DateMeasureField' {Maybe DateAggregationFunction
aggregationFunction :: Maybe DateAggregationFunction
$sel:aggregationFunction:DateMeasureField' :: DateMeasureField -> Maybe DateAggregationFunction
aggregationFunction} -> Maybe DateAggregationFunction
aggregationFunction) (\s :: DateMeasureField
s@DateMeasureField' {} Maybe DateAggregationFunction
a -> DateMeasureField
s {$sel:aggregationFunction:DateMeasureField' :: Maybe DateAggregationFunction
aggregationFunction = Maybe DateAggregationFunction
a} :: DateMeasureField)

-- | The format configuration of the field.
dateMeasureField_formatConfiguration :: Lens.Lens' DateMeasureField (Prelude.Maybe DateTimeFormatConfiguration)
dateMeasureField_formatConfiguration :: Lens' DateMeasureField (Maybe DateTimeFormatConfiguration)
dateMeasureField_formatConfiguration = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DateMeasureField' {Maybe DateTimeFormatConfiguration
formatConfiguration :: Maybe DateTimeFormatConfiguration
$sel:formatConfiguration:DateMeasureField' :: DateMeasureField -> Maybe DateTimeFormatConfiguration
formatConfiguration} -> Maybe DateTimeFormatConfiguration
formatConfiguration) (\s :: DateMeasureField
s@DateMeasureField' {} Maybe DateTimeFormatConfiguration
a -> DateMeasureField
s {$sel:formatConfiguration:DateMeasureField' :: Maybe DateTimeFormatConfiguration
formatConfiguration = Maybe DateTimeFormatConfiguration
a} :: DateMeasureField)

-- | The custom field ID.
dateMeasureField_fieldId :: Lens.Lens' DateMeasureField Prelude.Text
dateMeasureField_fieldId :: Lens' DateMeasureField Text
dateMeasureField_fieldId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DateMeasureField' {Text
fieldId :: Text
$sel:fieldId:DateMeasureField' :: DateMeasureField -> Text
fieldId} -> Text
fieldId) (\s :: DateMeasureField
s@DateMeasureField' {} Text
a -> DateMeasureField
s {$sel:fieldId:DateMeasureField' :: Text
fieldId = Text
a} :: DateMeasureField)

-- | The column that is used in the @DateMeasureField@.
dateMeasureField_column :: Lens.Lens' DateMeasureField ColumnIdentifier
dateMeasureField_column :: Lens' DateMeasureField ColumnIdentifier
dateMeasureField_column = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DateMeasureField' {ColumnIdentifier
column :: ColumnIdentifier
$sel:column:DateMeasureField' :: DateMeasureField -> ColumnIdentifier
column} -> ColumnIdentifier
column) (\s :: DateMeasureField
s@DateMeasureField' {} ColumnIdentifier
a -> DateMeasureField
s {$sel:column:DateMeasureField' :: ColumnIdentifier
column = ColumnIdentifier
a} :: DateMeasureField)

instance Data.FromJSON DateMeasureField where
  parseJSON :: Value -> Parser DateMeasureField
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DateMeasureField"
      ( \Object
x ->
          Maybe DateAggregationFunction
-> Maybe DateTimeFormatConfiguration
-> Text
-> ColumnIdentifier
-> DateMeasureField
DateMeasureField'
            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
"AggregationFunction")
            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
"FormatConfiguration")
            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
"FieldId")
            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
"Column")
      )

instance Prelude.Hashable DateMeasureField where
  hashWithSalt :: Int -> DateMeasureField -> Int
hashWithSalt Int
_salt DateMeasureField' {Maybe DateAggregationFunction
Maybe DateTimeFormatConfiguration
Text
ColumnIdentifier
column :: ColumnIdentifier
fieldId :: Text
formatConfiguration :: Maybe DateTimeFormatConfiguration
aggregationFunction :: Maybe DateAggregationFunction
$sel:column:DateMeasureField' :: DateMeasureField -> ColumnIdentifier
$sel:fieldId:DateMeasureField' :: DateMeasureField -> Text
$sel:formatConfiguration:DateMeasureField' :: DateMeasureField -> Maybe DateTimeFormatConfiguration
$sel:aggregationFunction:DateMeasureField' :: DateMeasureField -> Maybe DateAggregationFunction
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DateAggregationFunction
aggregationFunction
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DateTimeFormatConfiguration
formatConfiguration
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
fieldId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ColumnIdentifier
column

instance Prelude.NFData DateMeasureField where
  rnf :: DateMeasureField -> ()
rnf DateMeasureField' {Maybe DateAggregationFunction
Maybe DateTimeFormatConfiguration
Text
ColumnIdentifier
column :: ColumnIdentifier
fieldId :: Text
formatConfiguration :: Maybe DateTimeFormatConfiguration
aggregationFunction :: Maybe DateAggregationFunction
$sel:column:DateMeasureField' :: DateMeasureField -> ColumnIdentifier
$sel:fieldId:DateMeasureField' :: DateMeasureField -> Text
$sel:formatConfiguration:DateMeasureField' :: DateMeasureField -> Maybe DateTimeFormatConfiguration
$sel:aggregationFunction:DateMeasureField' :: DateMeasureField -> Maybe DateAggregationFunction
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe DateAggregationFunction
aggregationFunction
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe DateTimeFormatConfiguration
formatConfiguration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
fieldId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ColumnIdentifier
column

instance Data.ToJSON DateMeasureField where
  toJSON :: DateMeasureField -> Value
toJSON DateMeasureField' {Maybe DateAggregationFunction
Maybe DateTimeFormatConfiguration
Text
ColumnIdentifier
column :: ColumnIdentifier
fieldId :: Text
formatConfiguration :: Maybe DateTimeFormatConfiguration
aggregationFunction :: Maybe DateAggregationFunction
$sel:column:DateMeasureField' :: DateMeasureField -> ColumnIdentifier
$sel:fieldId:DateMeasureField' :: DateMeasureField -> Text
$sel:formatConfiguration:DateMeasureField' :: DateMeasureField -> Maybe DateTimeFormatConfiguration
$sel:aggregationFunction:DateMeasureField' :: DateMeasureField -> Maybe DateAggregationFunction
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"AggregationFunction" 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
aggregationFunction,
            (Key
"FormatConfiguration" 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 DateTimeFormatConfiguration
formatConfiguration,
            forall a. a -> Maybe a
Prelude.Just (Key
"FieldId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
fieldId),
            forall a. a -> Maybe a
Prelude.Just (Key
"Column" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ColumnIdentifier
column)
          ]
      )