{-# 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-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.LogicalTable where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(LogicalTable -> LogicalTable -> Bool)
-> (LogicalTable -> LogicalTable -> Bool) -> Eq LogicalTable
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, ReadPrec [LogicalTable]
ReadPrec LogicalTable
Int -> ReadS LogicalTable
ReadS [LogicalTable]
(Int -> ReadS LogicalTable)
-> ReadS [LogicalTable]
-> ReadPrec LogicalTable
-> ReadPrec [LogicalTable]
-> Read LogicalTable
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LogicalTable]
$creadListPrec :: ReadPrec [LogicalTable]
readPrec :: ReadPrec LogicalTable
$creadPrec :: ReadPrec LogicalTable
readList :: ReadS [LogicalTable]
$creadList :: ReadS [LogicalTable]
readsPrec :: Int -> ReadS LogicalTable
$creadsPrec :: Int -> ReadS LogicalTable
Prelude.Read, Int -> LogicalTable -> ShowS
[LogicalTable] -> ShowS
LogicalTable -> String
(Int -> LogicalTable -> ShowS)
-> (LogicalTable -> String)
-> ([LogicalTable] -> ShowS)
-> Show LogicalTable
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. LogicalTable -> Rep LogicalTable x)
-> (forall x. Rep LogicalTable x -> LogicalTable)
-> Generic LogicalTable
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' :: Maybe (NonEmpty TransformOperation)
-> Text -> LogicalTableSource -> LogicalTable
LogicalTable'
    { $sel:dataTransforms:LogicalTable' :: Maybe (NonEmpty TransformOperation)
dataTransforms = Maybe (NonEmpty TransformOperation)
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 :: (Maybe (NonEmpty TransformOperation)
 -> f (Maybe (NonEmpty TransformOperation)))
-> LogicalTable -> f LogicalTable
logicalTable_dataTransforms = (LogicalTable -> Maybe (NonEmpty TransformOperation))
-> (LogicalTable
    -> Maybe (NonEmpty TransformOperation) -> LogicalTable)
-> Lens
     LogicalTable
     LogicalTable
     (Maybe (NonEmpty TransformOperation))
     (Maybe (NonEmpty TransformOperation))
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) ((Maybe (NonEmpty TransformOperation)
  -> f (Maybe (NonEmpty TransformOperation)))
 -> LogicalTable -> f LogicalTable)
-> ((Maybe (NonEmpty TransformOperation)
     -> f (Maybe (NonEmpty TransformOperation)))
    -> Maybe (NonEmpty TransformOperation)
    -> f (Maybe (NonEmpty TransformOperation)))
-> (Maybe (NonEmpty TransformOperation)
    -> f (Maybe (NonEmpty TransformOperation)))
-> LogicalTable
-> f LogicalTable
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty TransformOperation)
  (NonEmpty TransformOperation)
  (NonEmpty TransformOperation)
  (NonEmpty TransformOperation)
-> Iso
     (Maybe (NonEmpty TransformOperation))
     (Maybe (NonEmpty TransformOperation))
     (Maybe (NonEmpty TransformOperation))
     (Maybe (NonEmpty TransformOperation))
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 AnIso
  (NonEmpty TransformOperation)
  (NonEmpty TransformOperation)
  (NonEmpty TransformOperation)
  (NonEmpty TransformOperation)
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 :: (Text -> f Text) -> LogicalTable -> f LogicalTable
logicalTable_alias = (LogicalTable -> Text)
-> (LogicalTable -> Text -> LogicalTable)
-> Lens LogicalTable LogicalTable Text Text
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 :: (LogicalTableSource -> f LogicalTableSource)
-> LogicalTable -> f LogicalTable
logicalTable_source = (LogicalTable -> LogicalTableSource)
-> (LogicalTable -> LogicalTableSource -> LogicalTable)
-> Lens
     LogicalTable LogicalTable LogicalTableSource LogicalTableSource
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 Core.FromJSON LogicalTable where
  parseJSON :: Value -> Parser LogicalTable
parseJSON =
    String
-> (Object -> Parser LogicalTable) -> Value -> Parser LogicalTable
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"LogicalTable"
      ( \Object
x ->
          Maybe (NonEmpty TransformOperation)
-> Text -> LogicalTableSource -> LogicalTable
LogicalTable'
            (Maybe (NonEmpty TransformOperation)
 -> Text -> LogicalTableSource -> LogicalTable)
-> Parser (Maybe (NonEmpty TransformOperation))
-> Parser (Text -> LogicalTableSource -> LogicalTable)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (NonEmpty TransformOperation))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"DataTransforms")
            Parser (Text -> LogicalTableSource -> LogicalTable)
-> Parser Text -> Parser (LogicalTableSource -> LogicalTable)
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
"Alias")
            Parser (LogicalTableSource -> LogicalTable)
-> Parser LogicalTableSource -> Parser LogicalTable
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser LogicalTableSource
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Source")
      )

instance Prelude.Hashable LogicalTable

instance Prelude.NFData LogicalTable

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"DataTransforms" Text -> NonEmpty TransformOperation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty TransformOperation -> Pair)
-> Maybe (NonEmpty TransformOperation) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty TransformOperation)
dataTransforms,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Alias" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
alias),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Source" Text -> LogicalTableSource -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= LogicalTableSource
source)
          ]
      )