{-# 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.PeriodToDateComputation
-- 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.PeriodToDateComputation 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
import Amazonka.QuickSight.Types.MeasureField
import Amazonka.QuickSight.Types.TimeGranularity

-- | The period to date computation configuration.
--
-- /See:/ 'newPeriodToDateComputation' smart constructor.
data PeriodToDateComputation = PeriodToDateComputation'
  { -- | The name of a computation.
    PeriodToDateComputation -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The time granularity setup of period to date computation. Choose from
    -- the following options:
    --
    -- -   YEAR: Year to date.
    --
    -- -   MONTH: Month to date.
    PeriodToDateComputation -> Maybe TimeGranularity
periodTimeGranularity :: Prelude.Maybe TimeGranularity,
    -- | The value field that is used in a computation.
    PeriodToDateComputation -> Maybe MeasureField
value :: Prelude.Maybe MeasureField,
    -- | The ID for a computation.
    PeriodToDateComputation -> Text
computationId :: Prelude.Text,
    -- | The time field that is used in a computation.
    PeriodToDateComputation -> DimensionField
time :: DimensionField
  }
  deriving (PeriodToDateComputation -> PeriodToDateComputation -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PeriodToDateComputation -> PeriodToDateComputation -> Bool
$c/= :: PeriodToDateComputation -> PeriodToDateComputation -> Bool
== :: PeriodToDateComputation -> PeriodToDateComputation -> Bool
$c== :: PeriodToDateComputation -> PeriodToDateComputation -> Bool
Prelude.Eq, Int -> PeriodToDateComputation -> ShowS
[PeriodToDateComputation] -> ShowS
PeriodToDateComputation -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PeriodToDateComputation] -> ShowS
$cshowList :: [PeriodToDateComputation] -> ShowS
show :: PeriodToDateComputation -> String
$cshow :: PeriodToDateComputation -> String
showsPrec :: Int -> PeriodToDateComputation -> ShowS
$cshowsPrec :: Int -> PeriodToDateComputation -> ShowS
Prelude.Show, forall x. Rep PeriodToDateComputation x -> PeriodToDateComputation
forall x. PeriodToDateComputation -> Rep PeriodToDateComputation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PeriodToDateComputation x -> PeriodToDateComputation
$cfrom :: forall x. PeriodToDateComputation -> Rep PeriodToDateComputation x
Prelude.Generic)

-- |
-- Create a value of 'PeriodToDateComputation' 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', 'periodToDateComputation_name' - The name of a computation.
--
-- 'periodTimeGranularity', 'periodToDateComputation_periodTimeGranularity' - The time granularity setup of period to date computation. Choose from
-- the following options:
--
-- -   YEAR: Year to date.
--
-- -   MONTH: Month to date.
--
-- 'value', 'periodToDateComputation_value' - The value field that is used in a computation.
--
-- 'computationId', 'periodToDateComputation_computationId' - The ID for a computation.
--
-- 'time', 'periodToDateComputation_time' - The time field that is used in a computation.
newPeriodToDateComputation ::
  -- | 'computationId'
  Prelude.Text ->
  -- | 'time'
  DimensionField ->
  PeriodToDateComputation
newPeriodToDateComputation :: Text -> DimensionField -> PeriodToDateComputation
newPeriodToDateComputation Text
pComputationId_ DimensionField
pTime_ =
  PeriodToDateComputation'
    { $sel:name:PeriodToDateComputation' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:periodTimeGranularity:PeriodToDateComputation' :: Maybe TimeGranularity
periodTimeGranularity = forall a. Maybe a
Prelude.Nothing,
      $sel:value:PeriodToDateComputation' :: Maybe MeasureField
value = forall a. Maybe a
Prelude.Nothing,
      $sel:computationId:PeriodToDateComputation' :: Text
computationId = Text
pComputationId_,
      $sel:time:PeriodToDateComputation' :: DimensionField
time = DimensionField
pTime_
    }

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

-- | The time granularity setup of period to date computation. Choose from
-- the following options:
--
-- -   YEAR: Year to date.
--
-- -   MONTH: Month to date.
periodToDateComputation_periodTimeGranularity :: Lens.Lens' PeriodToDateComputation (Prelude.Maybe TimeGranularity)
periodToDateComputation_periodTimeGranularity :: Lens' PeriodToDateComputation (Maybe TimeGranularity)
periodToDateComputation_periodTimeGranularity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PeriodToDateComputation' {Maybe TimeGranularity
periodTimeGranularity :: Maybe TimeGranularity
$sel:periodTimeGranularity:PeriodToDateComputation' :: PeriodToDateComputation -> Maybe TimeGranularity
periodTimeGranularity} -> Maybe TimeGranularity
periodTimeGranularity) (\s :: PeriodToDateComputation
s@PeriodToDateComputation' {} Maybe TimeGranularity
a -> PeriodToDateComputation
s {$sel:periodTimeGranularity:PeriodToDateComputation' :: Maybe TimeGranularity
periodTimeGranularity = Maybe TimeGranularity
a} :: PeriodToDateComputation)

-- | The value field that is used in a computation.
periodToDateComputation_value :: Lens.Lens' PeriodToDateComputation (Prelude.Maybe MeasureField)
periodToDateComputation_value :: Lens' PeriodToDateComputation (Maybe MeasureField)
periodToDateComputation_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PeriodToDateComputation' {Maybe MeasureField
value :: Maybe MeasureField
$sel:value:PeriodToDateComputation' :: PeriodToDateComputation -> Maybe MeasureField
value} -> Maybe MeasureField
value) (\s :: PeriodToDateComputation
s@PeriodToDateComputation' {} Maybe MeasureField
a -> PeriodToDateComputation
s {$sel:value:PeriodToDateComputation' :: Maybe MeasureField
value = Maybe MeasureField
a} :: PeriodToDateComputation)

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

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

instance Data.FromJSON PeriodToDateComputation where
  parseJSON :: Value -> Parser PeriodToDateComputation
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PeriodToDateComputation"
      ( \Object
x ->
          Maybe Text
-> Maybe TimeGranularity
-> Maybe MeasureField
-> Text
-> DimensionField
-> PeriodToDateComputation
PeriodToDateComputation'
            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 (Maybe a)
Data..:? Key
"PeriodTimeGranularity")
            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
"Value")
            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
"Time")
      )

instance Prelude.Hashable PeriodToDateComputation where
  hashWithSalt :: Int -> PeriodToDateComputation -> Int
hashWithSalt Int
_salt PeriodToDateComputation' {Maybe Text
Maybe TimeGranularity
Maybe MeasureField
Text
DimensionField
time :: DimensionField
computationId :: Text
value :: Maybe MeasureField
periodTimeGranularity :: Maybe TimeGranularity
name :: Maybe Text
$sel:time:PeriodToDateComputation' :: PeriodToDateComputation -> DimensionField
$sel:computationId:PeriodToDateComputation' :: PeriodToDateComputation -> Text
$sel:value:PeriodToDateComputation' :: PeriodToDateComputation -> Maybe MeasureField
$sel:periodTimeGranularity:PeriodToDateComputation' :: PeriodToDateComputation -> Maybe TimeGranularity
$sel:name:PeriodToDateComputation' :: PeriodToDateComputation -> 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` Maybe TimeGranularity
periodTimeGranularity
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe MeasureField
value
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
computationId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` DimensionField
time

instance Prelude.NFData PeriodToDateComputation where
  rnf :: PeriodToDateComputation -> ()
rnf PeriodToDateComputation' {Maybe Text
Maybe TimeGranularity
Maybe MeasureField
Text
DimensionField
time :: DimensionField
computationId :: Text
value :: Maybe MeasureField
periodTimeGranularity :: Maybe TimeGranularity
name :: Maybe Text
$sel:time:PeriodToDateComputation' :: PeriodToDateComputation -> DimensionField
$sel:computationId:PeriodToDateComputation' :: PeriodToDateComputation -> Text
$sel:value:PeriodToDateComputation' :: PeriodToDateComputation -> Maybe MeasureField
$sel:periodTimeGranularity:PeriodToDateComputation' :: PeriodToDateComputation -> Maybe TimeGranularity
$sel:name:PeriodToDateComputation' :: PeriodToDateComputation -> 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 Maybe TimeGranularity
periodTimeGranularity
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe MeasureField
value
      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
time

instance Data.ToJSON PeriodToDateComputation where
  toJSON :: PeriodToDateComputation -> Value
toJSON PeriodToDateComputation' {Maybe Text
Maybe TimeGranularity
Maybe MeasureField
Text
DimensionField
time :: DimensionField
computationId :: Text
value :: Maybe MeasureField
periodTimeGranularity :: Maybe TimeGranularity
name :: Maybe Text
$sel:time:PeriodToDateComputation' :: PeriodToDateComputation -> DimensionField
$sel:computationId:PeriodToDateComputation' :: PeriodToDateComputation -> Text
$sel:value:PeriodToDateComputation' :: PeriodToDateComputation -> Maybe MeasureField
$sel:periodTimeGranularity:PeriodToDateComputation' :: PeriodToDateComputation -> Maybe TimeGranularity
$sel:name:PeriodToDateComputation' :: PeriodToDateComputation -> 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,
            (Key
"PeriodTimeGranularity" 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 TimeGranularity
periodTimeGranularity,
            (Key
"Value" 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 MeasureField
value,
            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
"Time" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= DimensionField
time)
          ]
      )