{-# 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.CustomSql
-- 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.CustomSql 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.InputColumn

-- | A physical table type built from the results of the custom SQL query.
--
-- /See:/ 'newCustomSql' smart constructor.
data CustomSql = CustomSql'
  { -- | The column schema from the SQL query result set.
    CustomSql -> Maybe (NonEmpty InputColumn)
columns :: Prelude.Maybe (Prelude.NonEmpty InputColumn),
    -- | The Amazon Resource Name (ARN) of the data source.
    CustomSql -> Text
dataSourceArn :: Prelude.Text,
    -- | A display name for the SQL query result.
    CustomSql -> Text
name :: Prelude.Text,
    -- | The SQL query.
    CustomSql -> Text
sqlQuery :: Prelude.Text
  }
  deriving (CustomSql -> CustomSql -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomSql -> CustomSql -> Bool
$c/= :: CustomSql -> CustomSql -> Bool
== :: CustomSql -> CustomSql -> Bool
$c== :: CustomSql -> CustomSql -> Bool
Prelude.Eq, ReadPrec [CustomSql]
ReadPrec CustomSql
Int -> ReadS CustomSql
ReadS [CustomSql]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CustomSql]
$creadListPrec :: ReadPrec [CustomSql]
readPrec :: ReadPrec CustomSql
$creadPrec :: ReadPrec CustomSql
readList :: ReadS [CustomSql]
$creadList :: ReadS [CustomSql]
readsPrec :: Int -> ReadS CustomSql
$creadsPrec :: Int -> ReadS CustomSql
Prelude.Read, Int -> CustomSql -> ShowS
[CustomSql] -> ShowS
CustomSql -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomSql] -> ShowS
$cshowList :: [CustomSql] -> ShowS
show :: CustomSql -> String
$cshow :: CustomSql -> String
showsPrec :: Int -> CustomSql -> ShowS
$cshowsPrec :: Int -> CustomSql -> ShowS
Prelude.Show, forall x. Rep CustomSql x -> CustomSql
forall x. CustomSql -> Rep CustomSql x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CustomSql x -> CustomSql
$cfrom :: forall x. CustomSql -> Rep CustomSql x
Prelude.Generic)

-- |
-- Create a value of 'CustomSql' 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:
--
-- 'columns', 'customSql_columns' - The column schema from the SQL query result set.
--
-- 'dataSourceArn', 'customSql_dataSourceArn' - The Amazon Resource Name (ARN) of the data source.
--
-- 'name', 'customSql_name' - A display name for the SQL query result.
--
-- 'sqlQuery', 'customSql_sqlQuery' - The SQL query.
newCustomSql ::
  -- | 'dataSourceArn'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  -- | 'sqlQuery'
  Prelude.Text ->
  CustomSql
newCustomSql :: Text -> Text -> Text -> CustomSql
newCustomSql Text
pDataSourceArn_ Text
pName_ Text
pSqlQuery_ =
  CustomSql'
    { $sel:columns:CustomSql' :: Maybe (NonEmpty InputColumn)
columns = forall a. Maybe a
Prelude.Nothing,
      $sel:dataSourceArn:CustomSql' :: Text
dataSourceArn = Text
pDataSourceArn_,
      $sel:name:CustomSql' :: Text
name = Text
pName_,
      $sel:sqlQuery:CustomSql' :: Text
sqlQuery = Text
pSqlQuery_
    }

-- | The column schema from the SQL query result set.
customSql_columns :: Lens.Lens' CustomSql (Prelude.Maybe (Prelude.NonEmpty InputColumn))
customSql_columns :: Lens' CustomSql (Maybe (NonEmpty InputColumn))
customSql_columns = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomSql' {Maybe (NonEmpty InputColumn)
columns :: Maybe (NonEmpty InputColumn)
$sel:columns:CustomSql' :: CustomSql -> Maybe (NonEmpty InputColumn)
columns} -> Maybe (NonEmpty InputColumn)
columns) (\s :: CustomSql
s@CustomSql' {} Maybe (NonEmpty InputColumn)
a -> CustomSql
s {$sel:columns:CustomSql' :: Maybe (NonEmpty InputColumn)
columns = Maybe (NonEmpty InputColumn)
a} :: CustomSql) 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

-- | The Amazon Resource Name (ARN) of the data source.
customSql_dataSourceArn :: Lens.Lens' CustomSql Prelude.Text
customSql_dataSourceArn :: Lens' CustomSql Text
customSql_dataSourceArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomSql' {Text
dataSourceArn :: Text
$sel:dataSourceArn:CustomSql' :: CustomSql -> Text
dataSourceArn} -> Text
dataSourceArn) (\s :: CustomSql
s@CustomSql' {} Text
a -> CustomSql
s {$sel:dataSourceArn:CustomSql' :: Text
dataSourceArn = Text
a} :: CustomSql)

-- | A display name for the SQL query result.
customSql_name :: Lens.Lens' CustomSql Prelude.Text
customSql_name :: Lens' CustomSql Text
customSql_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomSql' {Text
name :: Text
$sel:name:CustomSql' :: CustomSql -> Text
name} -> Text
name) (\s :: CustomSql
s@CustomSql' {} Text
a -> CustomSql
s {$sel:name:CustomSql' :: Text
name = Text
a} :: CustomSql)

-- | The SQL query.
customSql_sqlQuery :: Lens.Lens' CustomSql Prelude.Text
customSql_sqlQuery :: Lens' CustomSql Text
customSql_sqlQuery = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomSql' {Text
sqlQuery :: Text
$sel:sqlQuery:CustomSql' :: CustomSql -> Text
sqlQuery} -> Text
sqlQuery) (\s :: CustomSql
s@CustomSql' {} Text
a -> CustomSql
s {$sel:sqlQuery:CustomSql' :: Text
sqlQuery = Text
a} :: CustomSql)

instance Data.FromJSON CustomSql where
  parseJSON :: Value -> Parser CustomSql
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CustomSql"
      ( \Object
x ->
          Maybe (NonEmpty InputColumn) -> Text -> Text -> Text -> CustomSql
CustomSql'
            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
"Columns")
            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
"DataSourceArn")
            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
"Name")
            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
"SqlQuery")
      )

instance Prelude.Hashable CustomSql where
  hashWithSalt :: Int -> CustomSql -> Int
hashWithSalt Int
_salt CustomSql' {Maybe (NonEmpty InputColumn)
Text
sqlQuery :: Text
name :: Text
dataSourceArn :: Text
columns :: Maybe (NonEmpty InputColumn)
$sel:sqlQuery:CustomSql' :: CustomSql -> Text
$sel:name:CustomSql' :: CustomSql -> Text
$sel:dataSourceArn:CustomSql' :: CustomSql -> Text
$sel:columns:CustomSql' :: CustomSql -> Maybe (NonEmpty InputColumn)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty InputColumn)
columns
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
dataSourceArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
sqlQuery

instance Prelude.NFData CustomSql where
  rnf :: CustomSql -> ()
rnf CustomSql' {Maybe (NonEmpty InputColumn)
Text
sqlQuery :: Text
name :: Text
dataSourceArn :: Text
columns :: Maybe (NonEmpty InputColumn)
$sel:sqlQuery:CustomSql' :: CustomSql -> Text
$sel:name:CustomSql' :: CustomSql -> Text
$sel:dataSourceArn:CustomSql' :: CustomSql -> Text
$sel:columns:CustomSql' :: CustomSql -> Maybe (NonEmpty InputColumn)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty InputColumn)
columns
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
dataSourceArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
sqlQuery

instance Data.ToJSON CustomSql where
  toJSON :: CustomSql -> Value
toJSON CustomSql' {Maybe (NonEmpty InputColumn)
Text
sqlQuery :: Text
name :: Text
dataSourceArn :: Text
columns :: Maybe (NonEmpty InputColumn)
$sel:sqlQuery:CustomSql' :: CustomSql -> Text
$sel:name:CustomSql' :: CustomSql -> Text
$sel:dataSourceArn:CustomSql' :: CustomSql -> Text
$sel:columns:CustomSql' :: CustomSql -> Maybe (NonEmpty InputColumn)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Columns" 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 InputColumn)
columns,
            forall a. a -> Maybe a
Prelude.Just (Key
"DataSourceArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
dataSourceArn),
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"SqlQuery" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
sqlQuery)
          ]
      )