{-# 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.CalculatedColumn
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.QuickSight.Types.CalculatedColumn where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A calculated column for a dataset.
--
-- /See:/ 'newCalculatedColumn' smart constructor.
data CalculatedColumn = CalculatedColumn'
  { -- | Column name.
    CalculatedColumn -> Text
columnName :: Prelude.Text,
    -- | A unique ID to identify a calculated column. During a dataset update, if
    -- the column ID of a calculated column matches that of an existing
    -- calculated column, Amazon QuickSight preserves the existing calculated
    -- column.
    CalculatedColumn -> Text
columnId :: Prelude.Text,
    -- | An expression that defines the calculated column.
    CalculatedColumn -> Text
expression :: Prelude.Text
  }
  deriving (CalculatedColumn -> CalculatedColumn -> Bool
(CalculatedColumn -> CalculatedColumn -> Bool)
-> (CalculatedColumn -> CalculatedColumn -> Bool)
-> Eq CalculatedColumn
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CalculatedColumn -> CalculatedColumn -> Bool
$c/= :: CalculatedColumn -> CalculatedColumn -> Bool
== :: CalculatedColumn -> CalculatedColumn -> Bool
$c== :: CalculatedColumn -> CalculatedColumn -> Bool
Prelude.Eq, ReadPrec [CalculatedColumn]
ReadPrec CalculatedColumn
Int -> ReadS CalculatedColumn
ReadS [CalculatedColumn]
(Int -> ReadS CalculatedColumn)
-> ReadS [CalculatedColumn]
-> ReadPrec CalculatedColumn
-> ReadPrec [CalculatedColumn]
-> Read CalculatedColumn
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CalculatedColumn]
$creadListPrec :: ReadPrec [CalculatedColumn]
readPrec :: ReadPrec CalculatedColumn
$creadPrec :: ReadPrec CalculatedColumn
readList :: ReadS [CalculatedColumn]
$creadList :: ReadS [CalculatedColumn]
readsPrec :: Int -> ReadS CalculatedColumn
$creadsPrec :: Int -> ReadS CalculatedColumn
Prelude.Read, Int -> CalculatedColumn -> ShowS
[CalculatedColumn] -> ShowS
CalculatedColumn -> String
(Int -> CalculatedColumn -> ShowS)
-> (CalculatedColumn -> String)
-> ([CalculatedColumn] -> ShowS)
-> Show CalculatedColumn
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CalculatedColumn] -> ShowS
$cshowList :: [CalculatedColumn] -> ShowS
show :: CalculatedColumn -> String
$cshow :: CalculatedColumn -> String
showsPrec :: Int -> CalculatedColumn -> ShowS
$cshowsPrec :: Int -> CalculatedColumn -> ShowS
Prelude.Show, (forall x. CalculatedColumn -> Rep CalculatedColumn x)
-> (forall x. Rep CalculatedColumn x -> CalculatedColumn)
-> Generic CalculatedColumn
forall x. Rep CalculatedColumn x -> CalculatedColumn
forall x. CalculatedColumn -> Rep CalculatedColumn x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CalculatedColumn x -> CalculatedColumn
$cfrom :: forall x. CalculatedColumn -> Rep CalculatedColumn x
Prelude.Generic)

-- |
-- Create a value of 'CalculatedColumn' 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:
--
-- 'columnName', 'calculatedColumn_columnName' - Column name.
--
-- 'columnId', 'calculatedColumn_columnId' - A unique ID to identify a calculated column. During a dataset update, if
-- the column ID of a calculated column matches that of an existing
-- calculated column, Amazon QuickSight preserves the existing calculated
-- column.
--
-- 'expression', 'calculatedColumn_expression' - An expression that defines the calculated column.
newCalculatedColumn ::
  -- | 'columnName'
  Prelude.Text ->
  -- | 'columnId'
  Prelude.Text ->
  -- | 'expression'
  Prelude.Text ->
  CalculatedColumn
newCalculatedColumn :: Text -> Text -> Text -> CalculatedColumn
newCalculatedColumn
  Text
pColumnName_
  Text
pColumnId_
  Text
pExpression_ =
    CalculatedColumn' :: Text -> Text -> Text -> CalculatedColumn
CalculatedColumn'
      { $sel:columnName:CalculatedColumn' :: Text
columnName = Text
pColumnName_,
        $sel:columnId:CalculatedColumn' :: Text
columnId = Text
pColumnId_,
        $sel:expression:CalculatedColumn' :: Text
expression = Text
pExpression_
      }

-- | Column name.
calculatedColumn_columnName :: Lens.Lens' CalculatedColumn Prelude.Text
calculatedColumn_columnName :: (Text -> f Text) -> CalculatedColumn -> f CalculatedColumn
calculatedColumn_columnName = (CalculatedColumn -> Text)
-> (CalculatedColumn -> Text -> CalculatedColumn)
-> Lens CalculatedColumn CalculatedColumn Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CalculatedColumn' {Text
columnName :: Text
$sel:columnName:CalculatedColumn' :: CalculatedColumn -> Text
columnName} -> Text
columnName) (\s :: CalculatedColumn
s@CalculatedColumn' {} Text
a -> CalculatedColumn
s {$sel:columnName:CalculatedColumn' :: Text
columnName = Text
a} :: CalculatedColumn)

-- | A unique ID to identify a calculated column. During a dataset update, if
-- the column ID of a calculated column matches that of an existing
-- calculated column, Amazon QuickSight preserves the existing calculated
-- column.
calculatedColumn_columnId :: Lens.Lens' CalculatedColumn Prelude.Text
calculatedColumn_columnId :: (Text -> f Text) -> CalculatedColumn -> f CalculatedColumn
calculatedColumn_columnId = (CalculatedColumn -> Text)
-> (CalculatedColumn -> Text -> CalculatedColumn)
-> Lens CalculatedColumn CalculatedColumn Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CalculatedColumn' {Text
columnId :: Text
$sel:columnId:CalculatedColumn' :: CalculatedColumn -> Text
columnId} -> Text
columnId) (\s :: CalculatedColumn
s@CalculatedColumn' {} Text
a -> CalculatedColumn
s {$sel:columnId:CalculatedColumn' :: Text
columnId = Text
a} :: CalculatedColumn)

-- | An expression that defines the calculated column.
calculatedColumn_expression :: Lens.Lens' CalculatedColumn Prelude.Text
calculatedColumn_expression :: (Text -> f Text) -> CalculatedColumn -> f CalculatedColumn
calculatedColumn_expression = (CalculatedColumn -> Text)
-> (CalculatedColumn -> Text -> CalculatedColumn)
-> Lens CalculatedColumn CalculatedColumn Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CalculatedColumn' {Text
expression :: Text
$sel:expression:CalculatedColumn' :: CalculatedColumn -> Text
expression} -> Text
expression) (\s :: CalculatedColumn
s@CalculatedColumn' {} Text
a -> CalculatedColumn
s {$sel:expression:CalculatedColumn' :: Text
expression = Text
a} :: CalculatedColumn)

instance Core.FromJSON CalculatedColumn where
  parseJSON :: Value -> Parser CalculatedColumn
parseJSON =
    String
-> (Object -> Parser CalculatedColumn)
-> Value
-> Parser CalculatedColumn
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CalculatedColumn"
      ( \Object
x ->
          Text -> Text -> Text -> CalculatedColumn
CalculatedColumn'
            (Text -> Text -> Text -> CalculatedColumn)
-> Parser Text -> Parser (Text -> Text -> CalculatedColumn)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ColumnName")
            Parser (Text -> Text -> CalculatedColumn)
-> Parser Text -> Parser (Text -> CalculatedColumn)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ColumnId")
            Parser (Text -> CalculatedColumn)
-> Parser Text -> Parser CalculatedColumn
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Expression")
      )

instance Prelude.Hashable CalculatedColumn

instance Prelude.NFData CalculatedColumn

instance Core.ToJSON CalculatedColumn where
  toJSON :: CalculatedColumn -> Value
toJSON CalculatedColumn' {Text
expression :: Text
columnId :: Text
columnName :: Text
$sel:expression:CalculatedColumn' :: CalculatedColumn -> Text
$sel:columnId:CalculatedColumn' :: CalculatedColumn -> Text
$sel:columnName:CalculatedColumn' :: CalculatedColumn -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ColumnName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
columnName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ColumnId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
columnId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Expression" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
expression)
          ]
      )