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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies an Glue Data Catalog target.
--
-- /See:/ 'newCatalogTarget' smart constructor.
data CatalogTarget = CatalogTarget'
  { -- | The name of the database to be synchronized.
    CatalogTarget -> Text
databaseName :: Prelude.Text,
    -- | A list of the tables to be synchronized.
    CatalogTarget -> NonEmpty Text
tables :: Prelude.NonEmpty Prelude.Text
  }
  deriving (CatalogTarget -> CatalogTarget -> Bool
(CatalogTarget -> CatalogTarget -> Bool)
-> (CatalogTarget -> CatalogTarget -> Bool) -> Eq CatalogTarget
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CatalogTarget -> CatalogTarget -> Bool
$c/= :: CatalogTarget -> CatalogTarget -> Bool
== :: CatalogTarget -> CatalogTarget -> Bool
$c== :: CatalogTarget -> CatalogTarget -> Bool
Prelude.Eq, ReadPrec [CatalogTarget]
ReadPrec CatalogTarget
Int -> ReadS CatalogTarget
ReadS [CatalogTarget]
(Int -> ReadS CatalogTarget)
-> ReadS [CatalogTarget]
-> ReadPrec CatalogTarget
-> ReadPrec [CatalogTarget]
-> Read CatalogTarget
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CatalogTarget]
$creadListPrec :: ReadPrec [CatalogTarget]
readPrec :: ReadPrec CatalogTarget
$creadPrec :: ReadPrec CatalogTarget
readList :: ReadS [CatalogTarget]
$creadList :: ReadS [CatalogTarget]
readsPrec :: Int -> ReadS CatalogTarget
$creadsPrec :: Int -> ReadS CatalogTarget
Prelude.Read, Int -> CatalogTarget -> ShowS
[CatalogTarget] -> ShowS
CatalogTarget -> String
(Int -> CatalogTarget -> ShowS)
-> (CatalogTarget -> String)
-> ([CatalogTarget] -> ShowS)
-> Show CatalogTarget
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CatalogTarget] -> ShowS
$cshowList :: [CatalogTarget] -> ShowS
show :: CatalogTarget -> String
$cshow :: CatalogTarget -> String
showsPrec :: Int -> CatalogTarget -> ShowS
$cshowsPrec :: Int -> CatalogTarget -> ShowS
Prelude.Show, (forall x. CatalogTarget -> Rep CatalogTarget x)
-> (forall x. Rep CatalogTarget x -> CatalogTarget)
-> Generic CatalogTarget
forall x. Rep CatalogTarget x -> CatalogTarget
forall x. CatalogTarget -> Rep CatalogTarget x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CatalogTarget x -> CatalogTarget
$cfrom :: forall x. CatalogTarget -> Rep CatalogTarget x
Prelude.Generic)

-- |
-- Create a value of 'CatalogTarget' 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:
--
-- 'databaseName', 'catalogTarget_databaseName' - The name of the database to be synchronized.
--
-- 'tables', 'catalogTarget_tables' - A list of the tables to be synchronized.
newCatalogTarget ::
  -- | 'databaseName'
  Prelude.Text ->
  -- | 'tables'
  Prelude.NonEmpty Prelude.Text ->
  CatalogTarget
newCatalogTarget :: Text -> NonEmpty Text -> CatalogTarget
newCatalogTarget Text
pDatabaseName_ NonEmpty Text
pTables_ =
  CatalogTarget' :: Text -> NonEmpty Text -> CatalogTarget
CatalogTarget'
    { $sel:databaseName:CatalogTarget' :: Text
databaseName = Text
pDatabaseName_,
      $sel:tables:CatalogTarget' :: NonEmpty Text
tables = Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pTables_
    }

-- | The name of the database to be synchronized.
catalogTarget_databaseName :: Lens.Lens' CatalogTarget Prelude.Text
catalogTarget_databaseName :: (Text -> f Text) -> CatalogTarget -> f CatalogTarget
catalogTarget_databaseName = (CatalogTarget -> Text)
-> (CatalogTarget -> Text -> CatalogTarget)
-> Lens CatalogTarget CatalogTarget Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CatalogTarget' {Text
databaseName :: Text
$sel:databaseName:CatalogTarget' :: CatalogTarget -> Text
databaseName} -> Text
databaseName) (\s :: CatalogTarget
s@CatalogTarget' {} Text
a -> CatalogTarget
s {$sel:databaseName:CatalogTarget' :: Text
databaseName = Text
a} :: CatalogTarget)

-- | A list of the tables to be synchronized.
catalogTarget_tables :: Lens.Lens' CatalogTarget (Prelude.NonEmpty Prelude.Text)
catalogTarget_tables :: (NonEmpty Text -> f (NonEmpty Text))
-> CatalogTarget -> f CatalogTarget
catalogTarget_tables = (CatalogTarget -> NonEmpty Text)
-> (CatalogTarget -> NonEmpty Text -> CatalogTarget)
-> Lens CatalogTarget CatalogTarget (NonEmpty Text) (NonEmpty Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CatalogTarget' {NonEmpty Text
tables :: NonEmpty Text
$sel:tables:CatalogTarget' :: CatalogTarget -> NonEmpty Text
tables} -> NonEmpty Text
tables) (\s :: CatalogTarget
s@CatalogTarget' {} NonEmpty Text
a -> CatalogTarget
s {$sel:tables:CatalogTarget' :: NonEmpty Text
tables = NonEmpty Text
a} :: CatalogTarget) ((NonEmpty Text -> f (NonEmpty Text))
 -> CatalogTarget -> f CatalogTarget)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> CatalogTarget
-> f CatalogTarget
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON CatalogTarget where
  parseJSON :: Value -> Parser CatalogTarget
parseJSON =
    String
-> (Object -> Parser CatalogTarget)
-> Value
-> Parser CatalogTarget
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CatalogTarget"
      ( \Object
x ->
          Text -> NonEmpty Text -> CatalogTarget
CatalogTarget'
            (Text -> NonEmpty Text -> CatalogTarget)
-> Parser Text -> Parser (NonEmpty Text -> CatalogTarget)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"DatabaseName")
            Parser (NonEmpty Text -> CatalogTarget)
-> Parser (NonEmpty Text) -> Parser CatalogTarget
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (NonEmpty Text)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Tables")
      )

instance Prelude.Hashable CatalogTarget

instance Prelude.NFData CatalogTarget

instance Core.ToJSON CatalogTarget where
  toJSON :: CatalogTarget -> Value
toJSON CatalogTarget' {NonEmpty Text
Text
tables :: NonEmpty Text
databaseName :: Text
$sel:tables:CatalogTarget' :: CatalogTarget -> NonEmpty Text
$sel:databaseName:CatalogTarget' :: CatalogTarget -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"DatabaseName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
databaseName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Tables" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
tables)
          ]
      )