{-# 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.LakeFormation.Types.TableResource
-- 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.LakeFormation.Types.TableResource where

import qualified Amazonka.Core as Core
import Amazonka.LakeFormation.Types.TableWildcard
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A structure for the table object. A table is a metadata definition that
-- represents your data. You can Grant and Revoke table privileges to a
-- principal.
--
-- /See:/ 'newTableResource' smart constructor.
data TableResource = TableResource'
  { -- | The identifier for the Data Catalog. By default, it is the account ID of
    -- the caller.
    TableResource -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | A wildcard object representing every table under a database.
    --
    -- At least one of @TableResource$Name@ or @TableResource$TableWildcard@ is
    -- required.
    TableResource -> Maybe TableWildcard
tableWildcard :: Prelude.Maybe TableWildcard,
    -- | The name of the table.
    TableResource -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The name of the database for the table. Unique to a Data Catalog. A
    -- database is a set of associated table definitions organized into a
    -- logical group. You can Grant and Revoke database privileges to a
    -- principal.
    TableResource -> Text
databaseName :: Prelude.Text
  }
  deriving (TableResource -> TableResource -> Bool
(TableResource -> TableResource -> Bool)
-> (TableResource -> TableResource -> Bool) -> Eq TableResource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TableResource -> TableResource -> Bool
$c/= :: TableResource -> TableResource -> Bool
== :: TableResource -> TableResource -> Bool
$c== :: TableResource -> TableResource -> Bool
Prelude.Eq, ReadPrec [TableResource]
ReadPrec TableResource
Int -> ReadS TableResource
ReadS [TableResource]
(Int -> ReadS TableResource)
-> ReadS [TableResource]
-> ReadPrec TableResource
-> ReadPrec [TableResource]
-> Read TableResource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TableResource]
$creadListPrec :: ReadPrec [TableResource]
readPrec :: ReadPrec TableResource
$creadPrec :: ReadPrec TableResource
readList :: ReadS [TableResource]
$creadList :: ReadS [TableResource]
readsPrec :: Int -> ReadS TableResource
$creadsPrec :: Int -> ReadS TableResource
Prelude.Read, Int -> TableResource -> ShowS
[TableResource] -> ShowS
TableResource -> String
(Int -> TableResource -> ShowS)
-> (TableResource -> String)
-> ([TableResource] -> ShowS)
-> Show TableResource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TableResource] -> ShowS
$cshowList :: [TableResource] -> ShowS
show :: TableResource -> String
$cshow :: TableResource -> String
showsPrec :: Int -> TableResource -> ShowS
$cshowsPrec :: Int -> TableResource -> ShowS
Prelude.Show, (forall x. TableResource -> Rep TableResource x)
-> (forall x. Rep TableResource x -> TableResource)
-> Generic TableResource
forall x. Rep TableResource x -> TableResource
forall x. TableResource -> Rep TableResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TableResource x -> TableResource
$cfrom :: forall x. TableResource -> Rep TableResource x
Prelude.Generic)

-- |
-- Create a value of 'TableResource' 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:
--
-- 'catalogId', 'tableResource_catalogId' - The identifier for the Data Catalog. By default, it is the account ID of
-- the caller.
--
-- 'tableWildcard', 'tableResource_tableWildcard' - A wildcard object representing every table under a database.
--
-- At least one of @TableResource$Name@ or @TableResource$TableWildcard@ is
-- required.
--
-- 'name', 'tableResource_name' - The name of the table.
--
-- 'databaseName', 'tableResource_databaseName' - The name of the database for the table. Unique to a Data Catalog. A
-- database is a set of associated table definitions organized into a
-- logical group. You can Grant and Revoke database privileges to a
-- principal.
newTableResource ::
  -- | 'databaseName'
  Prelude.Text ->
  TableResource
newTableResource :: Text -> TableResource
newTableResource Text
pDatabaseName_ =
  TableResource' :: Maybe Text
-> Maybe TableWildcard -> Maybe Text -> Text -> TableResource
TableResource'
    { $sel:catalogId:TableResource' :: Maybe Text
catalogId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tableWildcard:TableResource' :: Maybe TableWildcard
tableWildcard = Maybe TableWildcard
forall a. Maybe a
Prelude.Nothing,
      $sel:name:TableResource' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:databaseName:TableResource' :: Text
databaseName = Text
pDatabaseName_
    }

-- | The identifier for the Data Catalog. By default, it is the account ID of
-- the caller.
tableResource_catalogId :: Lens.Lens' TableResource (Prelude.Maybe Prelude.Text)
tableResource_catalogId :: (Maybe Text -> f (Maybe Text)) -> TableResource -> f TableResource
tableResource_catalogId = (TableResource -> Maybe Text)
-> (TableResource -> Maybe Text -> TableResource)
-> Lens TableResource TableResource (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TableResource' {Maybe Text
catalogId :: Maybe Text
$sel:catalogId:TableResource' :: TableResource -> Maybe Text
catalogId} -> Maybe Text
catalogId) (\s :: TableResource
s@TableResource' {} Maybe Text
a -> TableResource
s {$sel:catalogId:TableResource' :: Maybe Text
catalogId = Maybe Text
a} :: TableResource)

-- | A wildcard object representing every table under a database.
--
-- At least one of @TableResource$Name@ or @TableResource$TableWildcard@ is
-- required.
tableResource_tableWildcard :: Lens.Lens' TableResource (Prelude.Maybe TableWildcard)
tableResource_tableWildcard :: (Maybe TableWildcard -> f (Maybe TableWildcard))
-> TableResource -> f TableResource
tableResource_tableWildcard = (TableResource -> Maybe TableWildcard)
-> (TableResource -> Maybe TableWildcard -> TableResource)
-> Lens
     TableResource
     TableResource
     (Maybe TableWildcard)
     (Maybe TableWildcard)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TableResource' {Maybe TableWildcard
tableWildcard :: Maybe TableWildcard
$sel:tableWildcard:TableResource' :: TableResource -> Maybe TableWildcard
tableWildcard} -> Maybe TableWildcard
tableWildcard) (\s :: TableResource
s@TableResource' {} Maybe TableWildcard
a -> TableResource
s {$sel:tableWildcard:TableResource' :: Maybe TableWildcard
tableWildcard = Maybe TableWildcard
a} :: TableResource)

-- | The name of the table.
tableResource_name :: Lens.Lens' TableResource (Prelude.Maybe Prelude.Text)
tableResource_name :: (Maybe Text -> f (Maybe Text)) -> TableResource -> f TableResource
tableResource_name = (TableResource -> Maybe Text)
-> (TableResource -> Maybe Text -> TableResource)
-> Lens TableResource TableResource (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TableResource' {Maybe Text
name :: Maybe Text
$sel:name:TableResource' :: TableResource -> Maybe Text
name} -> Maybe Text
name) (\s :: TableResource
s@TableResource' {} Maybe Text
a -> TableResource
s {$sel:name:TableResource' :: Maybe Text
name = Maybe Text
a} :: TableResource)

-- | The name of the database for the table. Unique to a Data Catalog. A
-- database is a set of associated table definitions organized into a
-- logical group. You can Grant and Revoke database privileges to a
-- principal.
tableResource_databaseName :: Lens.Lens' TableResource Prelude.Text
tableResource_databaseName :: (Text -> f Text) -> TableResource -> f TableResource
tableResource_databaseName = (TableResource -> Text)
-> (TableResource -> Text -> TableResource)
-> Lens TableResource TableResource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TableResource' {Text
databaseName :: Text
$sel:databaseName:TableResource' :: TableResource -> Text
databaseName} -> Text
databaseName) (\s :: TableResource
s@TableResource' {} Text
a -> TableResource
s {$sel:databaseName:TableResource' :: Text
databaseName = Text
a} :: TableResource)

instance Core.FromJSON TableResource where
  parseJSON :: Value -> Parser TableResource
parseJSON =
    String
-> (Object -> Parser TableResource)
-> Value
-> Parser TableResource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TableResource"
      ( \Object
x ->
          Maybe Text
-> Maybe TableWildcard -> Maybe Text -> Text -> TableResource
TableResource'
            (Maybe Text
 -> Maybe TableWildcard -> Maybe Text -> Text -> TableResource)
-> Parser (Maybe Text)
-> Parser
     (Maybe TableWildcard -> Maybe Text -> Text -> TableResource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CatalogId")
            Parser (Maybe TableWildcard -> Maybe Text -> Text -> TableResource)
-> Parser (Maybe TableWildcard)
-> Parser (Maybe Text -> Text -> TableResource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe TableWildcard)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"TableWildcard")
            Parser (Maybe Text -> Text -> TableResource)
-> Parser (Maybe Text) -> Parser (Text -> TableResource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Name")
            Parser (Text -> TableResource)
-> Parser Text -> Parser TableResource
forall (f :: * -> *) a b. Applicative f => 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")
      )

instance Prelude.Hashable TableResource

instance Prelude.NFData TableResource

instance Core.ToJSON TableResource where
  toJSON :: TableResource -> Value
toJSON TableResource' {Maybe Text
Maybe TableWildcard
Text
databaseName :: Text
name :: Maybe Text
tableWildcard :: Maybe TableWildcard
catalogId :: Maybe Text
$sel:databaseName:TableResource' :: TableResource -> Text
$sel:name:TableResource' :: TableResource -> Maybe Text
$sel:tableWildcard:TableResource' :: TableResource -> Maybe TableWildcard
$sel:catalogId:TableResource' :: TableResource -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"CatalogId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
catalogId,
            (Text
"TableWildcard" Text -> TableWildcard -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (TableWildcard -> Pair) -> Maybe TableWildcard -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TableWildcard
tableWildcard,
            (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
name,
            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)
          ]
      )