{-# 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.PostgreSQLCatalogTarget
-- 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.PostgreSQLCatalogTarget 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 target that uses Postgres SQL.
--
-- /See:/ 'newPostgreSQLCatalogTarget' smart constructor.
data PostgreSQLCatalogTarget = PostgreSQLCatalogTarget'
  { -- | The name of the data target.
    PostgreSQLCatalogTarget -> Text
name :: Prelude.Text,
    -- | The nodes that are inputs to the data target.
    PostgreSQLCatalogTarget -> NonEmpty Text
inputs :: Prelude.NonEmpty Prelude.Text,
    -- | The name of the database to write to.
    PostgreSQLCatalogTarget -> Text
database :: Prelude.Text,
    -- | The name of the table in the database to write to.
    PostgreSQLCatalogTarget -> Text
table :: Prelude.Text
  }
  deriving (PostgreSQLCatalogTarget -> PostgreSQLCatalogTarget -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PostgreSQLCatalogTarget -> PostgreSQLCatalogTarget -> Bool
$c/= :: PostgreSQLCatalogTarget -> PostgreSQLCatalogTarget -> Bool
== :: PostgreSQLCatalogTarget -> PostgreSQLCatalogTarget -> Bool
$c== :: PostgreSQLCatalogTarget -> PostgreSQLCatalogTarget -> Bool
Prelude.Eq, ReadPrec [PostgreSQLCatalogTarget]
ReadPrec PostgreSQLCatalogTarget
Int -> ReadS PostgreSQLCatalogTarget
ReadS [PostgreSQLCatalogTarget]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PostgreSQLCatalogTarget]
$creadListPrec :: ReadPrec [PostgreSQLCatalogTarget]
readPrec :: ReadPrec PostgreSQLCatalogTarget
$creadPrec :: ReadPrec PostgreSQLCatalogTarget
readList :: ReadS [PostgreSQLCatalogTarget]
$creadList :: ReadS [PostgreSQLCatalogTarget]
readsPrec :: Int -> ReadS PostgreSQLCatalogTarget
$creadsPrec :: Int -> ReadS PostgreSQLCatalogTarget
Prelude.Read, Int -> PostgreSQLCatalogTarget -> ShowS
[PostgreSQLCatalogTarget] -> ShowS
PostgreSQLCatalogTarget -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PostgreSQLCatalogTarget] -> ShowS
$cshowList :: [PostgreSQLCatalogTarget] -> ShowS
show :: PostgreSQLCatalogTarget -> String
$cshow :: PostgreSQLCatalogTarget -> String
showsPrec :: Int -> PostgreSQLCatalogTarget -> ShowS
$cshowsPrec :: Int -> PostgreSQLCatalogTarget -> ShowS
Prelude.Show, forall x. Rep PostgreSQLCatalogTarget x -> PostgreSQLCatalogTarget
forall x. PostgreSQLCatalogTarget -> Rep PostgreSQLCatalogTarget x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PostgreSQLCatalogTarget x -> PostgreSQLCatalogTarget
$cfrom :: forall x. PostgreSQLCatalogTarget -> Rep PostgreSQLCatalogTarget x
Prelude.Generic)

-- |
-- Create a value of 'PostgreSQLCatalogTarget' 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', 'postgreSQLCatalogTarget_name' - The name of the data target.
--
-- 'inputs', 'postgreSQLCatalogTarget_inputs' - The nodes that are inputs to the data target.
--
-- 'database', 'postgreSQLCatalogTarget_database' - The name of the database to write to.
--
-- 'table', 'postgreSQLCatalogTarget_table' - The name of the table in the database to write to.
newPostgreSQLCatalogTarget ::
  -- | 'name'
  Prelude.Text ->
  -- | 'inputs'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'database'
  Prelude.Text ->
  -- | 'table'
  Prelude.Text ->
  PostgreSQLCatalogTarget
newPostgreSQLCatalogTarget :: Text -> NonEmpty Text -> Text -> Text -> PostgreSQLCatalogTarget
newPostgreSQLCatalogTarget
  Text
pName_
  NonEmpty Text
pInputs_
  Text
pDatabase_
  Text
pTable_ =
    PostgreSQLCatalogTarget'
      { $sel:name:PostgreSQLCatalogTarget' :: Text
name = Text
pName_,
        $sel:inputs:PostgreSQLCatalogTarget' :: NonEmpty Text
inputs = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pInputs_,
        $sel:database:PostgreSQLCatalogTarget' :: Text
database = Text
pDatabase_,
        $sel:table:PostgreSQLCatalogTarget' :: Text
table = Text
pTable_
      }

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

-- | The nodes that are inputs to the data target.
postgreSQLCatalogTarget_inputs :: Lens.Lens' PostgreSQLCatalogTarget (Prelude.NonEmpty Prelude.Text)
postgreSQLCatalogTarget_inputs :: Lens' PostgreSQLCatalogTarget (NonEmpty Text)
postgreSQLCatalogTarget_inputs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PostgreSQLCatalogTarget' {NonEmpty Text
inputs :: NonEmpty Text
$sel:inputs:PostgreSQLCatalogTarget' :: PostgreSQLCatalogTarget -> NonEmpty Text
inputs} -> NonEmpty Text
inputs) (\s :: PostgreSQLCatalogTarget
s@PostgreSQLCatalogTarget' {} NonEmpty Text
a -> PostgreSQLCatalogTarget
s {$sel:inputs:PostgreSQLCatalogTarget' :: NonEmpty Text
inputs = NonEmpty Text
a} :: PostgreSQLCatalogTarget) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

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

instance Data.FromJSON PostgreSQLCatalogTarget where
  parseJSON :: Value -> Parser PostgreSQLCatalogTarget
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PostgreSQLCatalogTarget"
      ( \Object
x ->
          Text -> NonEmpty Text -> Text -> Text -> PostgreSQLCatalogTarget
PostgreSQLCatalogTarget'
            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
"Inputs")
            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 PostgreSQLCatalogTarget where
  hashWithSalt :: Int -> PostgreSQLCatalogTarget -> Int
hashWithSalt Int
_salt PostgreSQLCatalogTarget' {NonEmpty Text
Text
table :: Text
database :: Text
inputs :: NonEmpty Text
name :: Text
$sel:table:PostgreSQLCatalogTarget' :: PostgreSQLCatalogTarget -> Text
$sel:database:PostgreSQLCatalogTarget' :: PostgreSQLCatalogTarget -> Text
$sel:inputs:PostgreSQLCatalogTarget' :: PostgreSQLCatalogTarget -> NonEmpty Text
$sel:name:PostgreSQLCatalogTarget' :: PostgreSQLCatalogTarget -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
inputs
      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 PostgreSQLCatalogTarget where
  rnf :: PostgreSQLCatalogTarget -> ()
rnf PostgreSQLCatalogTarget' {NonEmpty Text
Text
table :: Text
database :: Text
inputs :: NonEmpty Text
name :: Text
$sel:table:PostgreSQLCatalogTarget' :: PostgreSQLCatalogTarget -> Text
$sel:database:PostgreSQLCatalogTarget' :: PostgreSQLCatalogTarget -> Text
$sel:inputs:PostgreSQLCatalogTarget' :: PostgreSQLCatalogTarget -> NonEmpty Text
$sel:name:PostgreSQLCatalogTarget' :: PostgreSQLCatalogTarget -> 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 NonEmpty Text
inputs
      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 PostgreSQLCatalogTarget where
  toJSON :: PostgreSQLCatalogTarget -> Value
toJSON PostgreSQLCatalogTarget' {NonEmpty Text
Text
table :: Text
database :: Text
inputs :: NonEmpty Text
name :: Text
$sel:table:PostgreSQLCatalogTarget' :: PostgreSQLCatalogTarget -> Text
$sel:database:PostgreSQLCatalogTarget' :: PostgreSQLCatalogTarget -> Text
$sel:inputs:PostgreSQLCatalogTarget' :: PostgreSQLCatalogTarget -> NonEmpty Text
$sel:name:PostgreSQLCatalogTarget' :: PostgreSQLCatalogTarget -> 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
"Inputs" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
inputs),
            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)
          ]
      )