{-# 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.LogicalTable
-- 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.LogicalTable 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.LogicalTableSource
import Amazonka.QuickSight.Types.TransformOperation

-- | A /logical table/ is a unit that joins and that data transformations
-- operate on. A logical table has a source, which can be either a physical
-- table or result of a join. When a logical table points to a physical
-- table, the logical table acts as a mutable copy of that physical table
-- through transform operations.
--
-- /See:/ 'newLogicalTable' smart constructor.
data LogicalTable = LogicalTable'
  { -- | Transform operations that act on this logical table.
    LogicalTable -> Maybe (NonEmpty TransformOperation)
dataTransforms :: Prelude.Maybe (Prelude.NonEmpty TransformOperation),
    -- | A display name for the logical table.
    LogicalTable -> Text
alias :: Prelude.Text,
    -- | Source of this logical table.
    LogicalTable -> LogicalTableSource
source :: LogicalTableSource
  }
  deriving (LogicalTable -> LogicalTable -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LogicalTable -> LogicalTable -> Bool
$c/= :: LogicalTable -> LogicalTable -> Bool
== :: LogicalTable -> LogicalTable -> Bool
$c== :: LogicalTable -> LogicalTable -> Bool
Prelude.Eq, Int -> LogicalTable -> ShowS
[LogicalTable] -> ShowS
LogicalTable -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LogicalTable] -> ShowS
$cshowList :: [LogicalTable] -> ShowS
show :: LogicalTable -> String
$cshow :: LogicalTable -> String
showsPrec :: Int -> LogicalTable -> ShowS
$cshowsPrec :: Int -> LogicalTable -> ShowS
Prelude.Show, forall x. Rep LogicalTable x -> LogicalTable
forall x. LogicalTable -> Rep LogicalTable x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LogicalTable x -> LogicalTable
$cfrom :: forall x. LogicalTable -> Rep LogicalTable x
Prelude.Generic)

-- |
-- Create a value of 'LogicalTable' 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:
--
-- 'dataTransforms', 'logicalTable_dataTransforms' - Transform operations that act on this logical table.
--
-- 'alias', 'logicalTable_alias' - A display name for the logical table.
--
-- 'source', 'logicalTable_source' - Source of this logical table.
newLogicalTable ::
  -- | 'alias'
  Prelude.Text ->
  -- | 'source'
  LogicalTableSource ->
  LogicalTable
newLogicalTable :: Text -> LogicalTableSource -> LogicalTable
newLogicalTable Text
pAlias_ LogicalTableSource
pSource_ =
  LogicalTable'
    { $sel:dataTransforms:LogicalTable' :: Maybe (NonEmpty TransformOperation)
dataTransforms = forall a. Maybe a
Prelude.Nothing,
      $sel:alias:LogicalTable' :: Text
alias = Text
pAlias_,
      $sel:source:LogicalTable' :: LogicalTableSource
source = LogicalTableSource
pSource_
    }

-- | Transform operations that act on this logical table.
logicalTable_dataTransforms :: Lens.Lens' LogicalTable (Prelude.Maybe (Prelude.NonEmpty TransformOperation))
logicalTable_dataTransforms :: Lens' LogicalTable (Maybe (NonEmpty TransformOperation))
logicalTable_dataTransforms = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogicalTable' {Maybe (NonEmpty TransformOperation)
dataTransforms :: Maybe (NonEmpty TransformOperation)
$sel:dataTransforms:LogicalTable' :: LogicalTable -> Maybe (NonEmpty TransformOperation)
dataTransforms} -> Maybe (NonEmpty TransformOperation)
dataTransforms) (\s :: LogicalTable
s@LogicalTable' {} Maybe (NonEmpty TransformOperation)
a -> LogicalTable
s {$sel:dataTransforms:LogicalTable' :: Maybe (NonEmpty TransformOperation)
dataTransforms = Maybe (NonEmpty TransformOperation)
a} :: LogicalTable) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A display name for the logical table.
logicalTable_alias :: Lens.Lens' LogicalTable Prelude.Text
logicalTable_alias :: Lens' LogicalTable Text
logicalTable_alias = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogicalTable' {Text
alias :: Text
$sel:alias:LogicalTable' :: LogicalTable -> Text
alias} -> Text
alias) (\s :: LogicalTable
s@LogicalTable' {} Text
a -> LogicalTable
s {$sel:alias:LogicalTable' :: Text
alias = Text
a} :: LogicalTable)

-- | Source of this logical table.
logicalTable_source :: Lens.Lens' LogicalTable LogicalTableSource
logicalTable_source :: Lens' LogicalTable LogicalTableSource
logicalTable_source = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogicalTable' {LogicalTableSource
source :: LogicalTableSource
$sel:source:LogicalTable' :: LogicalTable -> LogicalTableSource
source} -> LogicalTableSource
source) (\s :: LogicalTable
s@LogicalTable' {} LogicalTableSource
a -> LogicalTable
s {$sel:source:LogicalTable' :: LogicalTableSource
source = LogicalTableSource
a} :: LogicalTable)

instance Data.FromJSON LogicalTable where
  parseJSON :: Value -> Parser LogicalTable
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"LogicalTable"
      ( \Object
x ->
          Maybe (NonEmpty TransformOperation)
-> Text -> LogicalTableSource -> LogicalTable
LogicalTable'
            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
"DataTransforms")
            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
"Alias")
            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
"Source")
      )

instance Prelude.Hashable LogicalTable where
  hashWithSalt :: Int -> LogicalTable -> Int
hashWithSalt Int
_salt LogicalTable' {Maybe (NonEmpty TransformOperation)
Text
LogicalTableSource
source :: LogicalTableSource
alias :: Text
dataTransforms :: Maybe (NonEmpty TransformOperation)
$sel:source:LogicalTable' :: LogicalTable -> LogicalTableSource
$sel:alias:LogicalTable' :: LogicalTable -> Text
$sel:dataTransforms:LogicalTable' :: LogicalTable -> Maybe (NonEmpty TransformOperation)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty TransformOperation)
dataTransforms
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
alias
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` LogicalTableSource
source

instance Prelude.NFData LogicalTable where
  rnf :: LogicalTable -> ()
rnf LogicalTable' {Maybe (NonEmpty TransformOperation)
Text
LogicalTableSource
source :: LogicalTableSource
alias :: Text
dataTransforms :: Maybe (NonEmpty TransformOperation)
$sel:source:LogicalTable' :: LogicalTable -> LogicalTableSource
$sel:alias:LogicalTable' :: LogicalTable -> Text
$sel:dataTransforms:LogicalTable' :: LogicalTable -> Maybe (NonEmpty TransformOperation)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty TransformOperation)
dataTransforms
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
alias
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf LogicalTableSource
source

instance Data.ToJSON LogicalTable where
  toJSON :: LogicalTable -> Value
toJSON LogicalTable' {Maybe (NonEmpty TransformOperation)
Text
LogicalTableSource
source :: LogicalTableSource
alias :: Text
dataTransforms :: Maybe (NonEmpty TransformOperation)
$sel:source:LogicalTable' :: LogicalTable -> LogicalTableSource
$sel:alias:LogicalTable' :: LogicalTable -> Text
$sel:dataTransforms:LogicalTable' :: LogicalTable -> Maybe (NonEmpty TransformOperation)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"DataTransforms" 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 (NonEmpty TransformOperation)
dataTransforms,
            forall a. a -> Maybe a
Prelude.Just (Key
"Alias" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
alias),
            forall a. a -> Maybe a
Prelude.Just (Key
"Source" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= LogicalTableSource
source)
          ]
      )