{-# 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.Glue.Types.PostgreSQLCatalogSource
-- 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.Glue.Types.PostgreSQLCatalogSource 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

-- | Specifies a PostgresSQL data source in the Glue Data Catalog.
--
-- /See:/ 'newPostgreSQLCatalogSource' smart constructor.
data PostgreSQLCatalogSource = PostgreSQLCatalogSource'
  { -- | The name of the data source.
    PostgreSQLCatalogSource -> Text
name :: Prelude.Text,
    -- | The name of the database to read from.
    PostgreSQLCatalogSource -> Text
database :: Prelude.Text,
    -- | The name of the table in the database to read from.
    PostgreSQLCatalogSource -> Text
table :: Prelude.Text
  }
  deriving (PostgreSQLCatalogSource -> PostgreSQLCatalogSource -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PostgreSQLCatalogSource -> PostgreSQLCatalogSource -> Bool
$c/= :: PostgreSQLCatalogSource -> PostgreSQLCatalogSource -> Bool
== :: PostgreSQLCatalogSource -> PostgreSQLCatalogSource -> Bool
$c== :: PostgreSQLCatalogSource -> PostgreSQLCatalogSource -> Bool
Prelude.Eq, ReadPrec [PostgreSQLCatalogSource]
ReadPrec PostgreSQLCatalogSource
Int -> ReadS PostgreSQLCatalogSource
ReadS [PostgreSQLCatalogSource]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PostgreSQLCatalogSource]
$creadListPrec :: ReadPrec [PostgreSQLCatalogSource]
readPrec :: ReadPrec PostgreSQLCatalogSource
$creadPrec :: ReadPrec PostgreSQLCatalogSource
readList :: ReadS [PostgreSQLCatalogSource]
$creadList :: ReadS [PostgreSQLCatalogSource]
readsPrec :: Int -> ReadS PostgreSQLCatalogSource
$creadsPrec :: Int -> ReadS PostgreSQLCatalogSource
Prelude.Read, Int -> PostgreSQLCatalogSource -> ShowS
[PostgreSQLCatalogSource] -> ShowS
PostgreSQLCatalogSource -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PostgreSQLCatalogSource] -> ShowS
$cshowList :: [PostgreSQLCatalogSource] -> ShowS
show :: PostgreSQLCatalogSource -> String
$cshow :: PostgreSQLCatalogSource -> String
showsPrec :: Int -> PostgreSQLCatalogSource -> ShowS
$cshowsPrec :: Int -> PostgreSQLCatalogSource -> ShowS
Prelude.Show, forall x. Rep PostgreSQLCatalogSource x -> PostgreSQLCatalogSource
forall x. PostgreSQLCatalogSource -> Rep PostgreSQLCatalogSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PostgreSQLCatalogSource x -> PostgreSQLCatalogSource
$cfrom :: forall x. PostgreSQLCatalogSource -> Rep PostgreSQLCatalogSource x
Prelude.Generic)

-- |
-- Create a value of 'PostgreSQLCatalogSource' 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', 'postgreSQLCatalogSource_name' - The name of the data source.
--
-- 'database', 'postgreSQLCatalogSource_database' - The name of the database to read from.
--
-- 'table', 'postgreSQLCatalogSource_table' - The name of the table in the database to read from.
newPostgreSQLCatalogSource ::
  -- | 'name'
  Prelude.Text ->
  -- | 'database'
  Prelude.Text ->
  -- | 'table'
  Prelude.Text ->
  PostgreSQLCatalogSource
newPostgreSQLCatalogSource :: Text -> Text -> Text -> PostgreSQLCatalogSource
newPostgreSQLCatalogSource Text
pName_ Text
pDatabase_ Text
pTable_ =
  PostgreSQLCatalogSource'
    { $sel:name:PostgreSQLCatalogSource' :: Text
name = Text
pName_,
      $sel:database:PostgreSQLCatalogSource' :: Text
database = Text
pDatabase_,
      $sel:table:PostgreSQLCatalogSource' :: Text
table = Text
pTable_
    }

-- | The name of the data source.
postgreSQLCatalogSource_name :: Lens.Lens' PostgreSQLCatalogSource Prelude.Text
postgreSQLCatalogSource_name :: Lens' PostgreSQLCatalogSource Text
postgreSQLCatalogSource_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PostgreSQLCatalogSource' {Text
name :: Text
$sel:name:PostgreSQLCatalogSource' :: PostgreSQLCatalogSource -> Text
name} -> Text
name) (\s :: PostgreSQLCatalogSource
s@PostgreSQLCatalogSource' {} Text
a -> PostgreSQLCatalogSource
s {$sel:name:PostgreSQLCatalogSource' :: Text
name = Text
a} :: PostgreSQLCatalogSource)

-- | The name of the database to read from.
postgreSQLCatalogSource_database :: Lens.Lens' PostgreSQLCatalogSource Prelude.Text
postgreSQLCatalogSource_database :: Lens' PostgreSQLCatalogSource Text
postgreSQLCatalogSource_database = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PostgreSQLCatalogSource' {Text
database :: Text
$sel:database:PostgreSQLCatalogSource' :: PostgreSQLCatalogSource -> Text
database} -> Text
database) (\s :: PostgreSQLCatalogSource
s@PostgreSQLCatalogSource' {} Text
a -> PostgreSQLCatalogSource
s {$sel:database:PostgreSQLCatalogSource' :: Text
database = Text
a} :: PostgreSQLCatalogSource)

-- | The name of the table in the database to read from.
postgreSQLCatalogSource_table :: Lens.Lens' PostgreSQLCatalogSource Prelude.Text
postgreSQLCatalogSource_table :: Lens' PostgreSQLCatalogSource Text
postgreSQLCatalogSource_table = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PostgreSQLCatalogSource' {Text
table :: Text
$sel:table:PostgreSQLCatalogSource' :: PostgreSQLCatalogSource -> Text
table} -> Text
table) (\s :: PostgreSQLCatalogSource
s@PostgreSQLCatalogSource' {} Text
a -> PostgreSQLCatalogSource
s {$sel:table:PostgreSQLCatalogSource' :: Text
table = Text
a} :: PostgreSQLCatalogSource)

instance Data.FromJSON PostgreSQLCatalogSource where
  parseJSON :: Value -> Parser PostgreSQLCatalogSource
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PostgreSQLCatalogSource"
      ( \Object
x ->
          Text -> Text -> Text -> PostgreSQLCatalogSource
PostgreSQLCatalogSource'
            forall (f :: * -> *) a b. Functor 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
"Database")
            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
"Table")
      )

instance Prelude.Hashable PostgreSQLCatalogSource where
  hashWithSalt :: Int -> PostgreSQLCatalogSource -> Int
hashWithSalt Int
_salt PostgreSQLCatalogSource' {Text
table :: Text
database :: Text
name :: Text
$sel:table:PostgreSQLCatalogSource' :: PostgreSQLCatalogSource -> Text
$sel:database:PostgreSQLCatalogSource' :: PostgreSQLCatalogSource -> Text
$sel:name:PostgreSQLCatalogSource' :: PostgreSQLCatalogSource -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
database
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
table

instance Prelude.NFData PostgreSQLCatalogSource where
  rnf :: PostgreSQLCatalogSource -> ()
rnf PostgreSQLCatalogSource' {Text
table :: Text
database :: Text
name :: Text
$sel:table:PostgreSQLCatalogSource' :: PostgreSQLCatalogSource -> Text
$sel:database:PostgreSQLCatalogSource' :: PostgreSQLCatalogSource -> Text
$sel:name:PostgreSQLCatalogSource' :: PostgreSQLCatalogSource -> Text
..} =
    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
database
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
table

instance Data.ToJSON PostgreSQLCatalogSource where
  toJSON :: PostgreSQLCatalogSource -> Value
toJSON PostgreSQLCatalogSource' {Text
table :: Text
database :: Text
name :: Text
$sel:table:PostgreSQLCatalogSource' :: PostgreSQLCatalogSource -> Text
$sel:database:PostgreSQLCatalogSource' :: PostgreSQLCatalogSource -> Text
$sel:name:PostgreSQLCatalogSource' :: PostgreSQLCatalogSource -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ 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
"Database" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
database),
            forall a. a -> Maybe a
Prelude.Just (Key
"Table" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
table)
          ]
      )