{-# 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.UpsertRedshiftTargetOptions
-- 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.UpsertRedshiftTargetOptions 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

-- | The options to configure an upsert operation when writing to a Redshift
-- target .
--
-- /See:/ 'newUpsertRedshiftTargetOptions' smart constructor.
data UpsertRedshiftTargetOptions = UpsertRedshiftTargetOptions'
  { -- | The name of the connection to use to write to Redshift.
    UpsertRedshiftTargetOptions -> Maybe Text
connectionName :: Prelude.Maybe Prelude.Text,
    -- | The physical location of the Redshift table.
    UpsertRedshiftTargetOptions -> Maybe Text
tableLocation :: Prelude.Maybe Prelude.Text,
    -- | The keys used to determine whether to perform an update or insert.
    UpsertRedshiftTargetOptions -> Maybe [Text]
upsertKeys :: Prelude.Maybe [Prelude.Text]
  }
  deriving (UpsertRedshiftTargetOptions -> UpsertRedshiftTargetOptions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpsertRedshiftTargetOptions -> UpsertRedshiftTargetOptions -> Bool
$c/= :: UpsertRedshiftTargetOptions -> UpsertRedshiftTargetOptions -> Bool
== :: UpsertRedshiftTargetOptions -> UpsertRedshiftTargetOptions -> Bool
$c== :: UpsertRedshiftTargetOptions -> UpsertRedshiftTargetOptions -> Bool
Prelude.Eq, ReadPrec [UpsertRedshiftTargetOptions]
ReadPrec UpsertRedshiftTargetOptions
Int -> ReadS UpsertRedshiftTargetOptions
ReadS [UpsertRedshiftTargetOptions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpsertRedshiftTargetOptions]
$creadListPrec :: ReadPrec [UpsertRedshiftTargetOptions]
readPrec :: ReadPrec UpsertRedshiftTargetOptions
$creadPrec :: ReadPrec UpsertRedshiftTargetOptions
readList :: ReadS [UpsertRedshiftTargetOptions]
$creadList :: ReadS [UpsertRedshiftTargetOptions]
readsPrec :: Int -> ReadS UpsertRedshiftTargetOptions
$creadsPrec :: Int -> ReadS UpsertRedshiftTargetOptions
Prelude.Read, Int -> UpsertRedshiftTargetOptions -> ShowS
[UpsertRedshiftTargetOptions] -> ShowS
UpsertRedshiftTargetOptions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpsertRedshiftTargetOptions] -> ShowS
$cshowList :: [UpsertRedshiftTargetOptions] -> ShowS
show :: UpsertRedshiftTargetOptions -> String
$cshow :: UpsertRedshiftTargetOptions -> String
showsPrec :: Int -> UpsertRedshiftTargetOptions -> ShowS
$cshowsPrec :: Int -> UpsertRedshiftTargetOptions -> ShowS
Prelude.Show, forall x.
Rep UpsertRedshiftTargetOptions x -> UpsertRedshiftTargetOptions
forall x.
UpsertRedshiftTargetOptions -> Rep UpsertRedshiftTargetOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpsertRedshiftTargetOptions x -> UpsertRedshiftTargetOptions
$cfrom :: forall x.
UpsertRedshiftTargetOptions -> Rep UpsertRedshiftTargetOptions x
Prelude.Generic)

-- |
-- Create a value of 'UpsertRedshiftTargetOptions' 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:
--
-- 'connectionName', 'upsertRedshiftTargetOptions_connectionName' - The name of the connection to use to write to Redshift.
--
-- 'tableLocation', 'upsertRedshiftTargetOptions_tableLocation' - The physical location of the Redshift table.
--
-- 'upsertKeys', 'upsertRedshiftTargetOptions_upsertKeys' - The keys used to determine whether to perform an update or insert.
newUpsertRedshiftTargetOptions ::
  UpsertRedshiftTargetOptions
newUpsertRedshiftTargetOptions :: UpsertRedshiftTargetOptions
newUpsertRedshiftTargetOptions =
  UpsertRedshiftTargetOptions'
    { $sel:connectionName:UpsertRedshiftTargetOptions' :: Maybe Text
connectionName =
        forall a. Maybe a
Prelude.Nothing,
      $sel:tableLocation:UpsertRedshiftTargetOptions' :: Maybe Text
tableLocation = forall a. Maybe a
Prelude.Nothing,
      $sel:upsertKeys:UpsertRedshiftTargetOptions' :: Maybe [Text]
upsertKeys = forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the connection to use to write to Redshift.
upsertRedshiftTargetOptions_connectionName :: Lens.Lens' UpsertRedshiftTargetOptions (Prelude.Maybe Prelude.Text)
upsertRedshiftTargetOptions_connectionName :: Lens' UpsertRedshiftTargetOptions (Maybe Text)
upsertRedshiftTargetOptions_connectionName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpsertRedshiftTargetOptions' {Maybe Text
connectionName :: Maybe Text
$sel:connectionName:UpsertRedshiftTargetOptions' :: UpsertRedshiftTargetOptions -> Maybe Text
connectionName} -> Maybe Text
connectionName) (\s :: UpsertRedshiftTargetOptions
s@UpsertRedshiftTargetOptions' {} Maybe Text
a -> UpsertRedshiftTargetOptions
s {$sel:connectionName:UpsertRedshiftTargetOptions' :: Maybe Text
connectionName = Maybe Text
a} :: UpsertRedshiftTargetOptions)

-- | The physical location of the Redshift table.
upsertRedshiftTargetOptions_tableLocation :: Lens.Lens' UpsertRedshiftTargetOptions (Prelude.Maybe Prelude.Text)
upsertRedshiftTargetOptions_tableLocation :: Lens' UpsertRedshiftTargetOptions (Maybe Text)
upsertRedshiftTargetOptions_tableLocation = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpsertRedshiftTargetOptions' {Maybe Text
tableLocation :: Maybe Text
$sel:tableLocation:UpsertRedshiftTargetOptions' :: UpsertRedshiftTargetOptions -> Maybe Text
tableLocation} -> Maybe Text
tableLocation) (\s :: UpsertRedshiftTargetOptions
s@UpsertRedshiftTargetOptions' {} Maybe Text
a -> UpsertRedshiftTargetOptions
s {$sel:tableLocation:UpsertRedshiftTargetOptions' :: Maybe Text
tableLocation = Maybe Text
a} :: UpsertRedshiftTargetOptions)

-- | The keys used to determine whether to perform an update or insert.
upsertRedshiftTargetOptions_upsertKeys :: Lens.Lens' UpsertRedshiftTargetOptions (Prelude.Maybe [Prelude.Text])
upsertRedshiftTargetOptions_upsertKeys :: Lens' UpsertRedshiftTargetOptions (Maybe [Text])
upsertRedshiftTargetOptions_upsertKeys = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpsertRedshiftTargetOptions' {Maybe [Text]
upsertKeys :: Maybe [Text]
$sel:upsertKeys:UpsertRedshiftTargetOptions' :: UpsertRedshiftTargetOptions -> Maybe [Text]
upsertKeys} -> Maybe [Text]
upsertKeys) (\s :: UpsertRedshiftTargetOptions
s@UpsertRedshiftTargetOptions' {} Maybe [Text]
a -> UpsertRedshiftTargetOptions
s {$sel:upsertKeys:UpsertRedshiftTargetOptions' :: Maybe [Text]
upsertKeys = Maybe [Text]
a} :: UpsertRedshiftTargetOptions) 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

instance Data.FromJSON UpsertRedshiftTargetOptions where
  parseJSON :: Value -> Parser UpsertRedshiftTargetOptions
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"UpsertRedshiftTargetOptions"
      ( \Object
x ->
          Maybe Text
-> Maybe Text -> Maybe [Text] -> UpsertRedshiftTargetOptions
UpsertRedshiftTargetOptions'
            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
"ConnectionName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"TableLocation")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"UpsertKeys" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable UpsertRedshiftTargetOptions where
  hashWithSalt :: Int -> UpsertRedshiftTargetOptions -> Int
hashWithSalt Int
_salt UpsertRedshiftTargetOptions' {Maybe [Text]
Maybe Text
upsertKeys :: Maybe [Text]
tableLocation :: Maybe Text
connectionName :: Maybe Text
$sel:upsertKeys:UpsertRedshiftTargetOptions' :: UpsertRedshiftTargetOptions -> Maybe [Text]
$sel:tableLocation:UpsertRedshiftTargetOptions' :: UpsertRedshiftTargetOptions -> Maybe Text
$sel:connectionName:UpsertRedshiftTargetOptions' :: UpsertRedshiftTargetOptions -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
connectionName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
tableLocation
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
upsertKeys

instance Prelude.NFData UpsertRedshiftTargetOptions where
  rnf :: UpsertRedshiftTargetOptions -> ()
rnf UpsertRedshiftTargetOptions' {Maybe [Text]
Maybe Text
upsertKeys :: Maybe [Text]
tableLocation :: Maybe Text
connectionName :: Maybe Text
$sel:upsertKeys:UpsertRedshiftTargetOptions' :: UpsertRedshiftTargetOptions -> Maybe [Text]
$sel:tableLocation:UpsertRedshiftTargetOptions' :: UpsertRedshiftTargetOptions -> Maybe Text
$sel:connectionName:UpsertRedshiftTargetOptions' :: UpsertRedshiftTargetOptions -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
connectionName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
tableLocation
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
upsertKeys

instance Data.ToJSON UpsertRedshiftTargetOptions where
  toJSON :: UpsertRedshiftTargetOptions -> Value
toJSON UpsertRedshiftTargetOptions' {Maybe [Text]
Maybe Text
upsertKeys :: Maybe [Text]
tableLocation :: Maybe Text
connectionName :: Maybe Text
$sel:upsertKeys:UpsertRedshiftTargetOptions' :: UpsertRedshiftTargetOptions -> Maybe [Text]
$sel:tableLocation:UpsertRedshiftTargetOptions' :: UpsertRedshiftTargetOptions -> Maybe Text
$sel:connectionName:UpsertRedshiftTargetOptions' :: UpsertRedshiftTargetOptions -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ConnectionName" 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 Text
connectionName,
            (Key
"TableLocation" 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 Text
tableLocation,
            (Key
"UpsertKeys" 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 [Text]
upsertKeys
          ]
      )