{-# 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.DatabaseInput
-- 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.DatabaseInput where

import qualified Amazonka.Core as Core
import Amazonka.Glue.Types.DatabaseIdentifier
import Amazonka.Glue.Types.PrincipalPermissions
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The structure used to create or update a database.
--
-- /See:/ 'newDatabaseInput' smart constructor.
data DatabaseInput = DatabaseInput'
  { -- | The location of the database (for example, an HDFS path).
    DatabaseInput -> Maybe Text
locationUri :: Prelude.Maybe Prelude.Text,
    -- | A @DatabaseIdentifier@ structure that describes a target database for
    -- resource linking.
    DatabaseInput -> Maybe DatabaseIdentifier
targetDatabase :: Prelude.Maybe DatabaseIdentifier,
    -- | These key-value pairs define parameters and properties of the database.
    --
    -- These key-value pairs define parameters and properties of the database.
    DatabaseInput -> Maybe (HashMap Text Text)
parameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | A description of the database.
    DatabaseInput -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | Creates a set of default permissions on the table for principals.
    DatabaseInput -> Maybe [PrincipalPermissions]
createTableDefaultPermissions :: Prelude.Maybe [PrincipalPermissions],
    -- | The name of the database. For Hive compatibility, this is folded to
    -- lowercase when it is stored.
    DatabaseInput -> Text
name :: Prelude.Text
  }
  deriving (DatabaseInput -> DatabaseInput -> Bool
(DatabaseInput -> DatabaseInput -> Bool)
-> (DatabaseInput -> DatabaseInput -> Bool) -> Eq DatabaseInput
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DatabaseInput -> DatabaseInput -> Bool
$c/= :: DatabaseInput -> DatabaseInput -> Bool
== :: DatabaseInput -> DatabaseInput -> Bool
$c== :: DatabaseInput -> DatabaseInput -> Bool
Prelude.Eq, ReadPrec [DatabaseInput]
ReadPrec DatabaseInput
Int -> ReadS DatabaseInput
ReadS [DatabaseInput]
(Int -> ReadS DatabaseInput)
-> ReadS [DatabaseInput]
-> ReadPrec DatabaseInput
-> ReadPrec [DatabaseInput]
-> Read DatabaseInput
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DatabaseInput]
$creadListPrec :: ReadPrec [DatabaseInput]
readPrec :: ReadPrec DatabaseInput
$creadPrec :: ReadPrec DatabaseInput
readList :: ReadS [DatabaseInput]
$creadList :: ReadS [DatabaseInput]
readsPrec :: Int -> ReadS DatabaseInput
$creadsPrec :: Int -> ReadS DatabaseInput
Prelude.Read, Int -> DatabaseInput -> ShowS
[DatabaseInput] -> ShowS
DatabaseInput -> String
(Int -> DatabaseInput -> ShowS)
-> (DatabaseInput -> String)
-> ([DatabaseInput] -> ShowS)
-> Show DatabaseInput
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DatabaseInput] -> ShowS
$cshowList :: [DatabaseInput] -> ShowS
show :: DatabaseInput -> String
$cshow :: DatabaseInput -> String
showsPrec :: Int -> DatabaseInput -> ShowS
$cshowsPrec :: Int -> DatabaseInput -> ShowS
Prelude.Show, (forall x. DatabaseInput -> Rep DatabaseInput x)
-> (forall x. Rep DatabaseInput x -> DatabaseInput)
-> Generic DatabaseInput
forall x. Rep DatabaseInput x -> DatabaseInput
forall x. DatabaseInput -> Rep DatabaseInput x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DatabaseInput x -> DatabaseInput
$cfrom :: forall x. DatabaseInput -> Rep DatabaseInput x
Prelude.Generic)

-- |
-- Create a value of 'DatabaseInput' 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:
--
-- 'locationUri', 'databaseInput_locationUri' - The location of the database (for example, an HDFS path).
--
-- 'targetDatabase', 'databaseInput_targetDatabase' - A @DatabaseIdentifier@ structure that describes a target database for
-- resource linking.
--
-- 'parameters', 'databaseInput_parameters' - These key-value pairs define parameters and properties of the database.
--
-- These key-value pairs define parameters and properties of the database.
--
-- 'description', 'databaseInput_description' - A description of the database.
--
-- 'createTableDefaultPermissions', 'databaseInput_createTableDefaultPermissions' - Creates a set of default permissions on the table for principals.
--
-- 'name', 'databaseInput_name' - The name of the database. For Hive compatibility, this is folded to
-- lowercase when it is stored.
newDatabaseInput ::
  -- | 'name'
  Prelude.Text ->
  DatabaseInput
newDatabaseInput :: Text -> DatabaseInput
newDatabaseInput Text
pName_ =
  DatabaseInput' :: Maybe Text
-> Maybe DatabaseIdentifier
-> Maybe (HashMap Text Text)
-> Maybe Text
-> Maybe [PrincipalPermissions]
-> Text
-> DatabaseInput
DatabaseInput'
    { $sel:locationUri:DatabaseInput' :: Maybe Text
locationUri = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:targetDatabase:DatabaseInput' :: Maybe DatabaseIdentifier
targetDatabase = Maybe DatabaseIdentifier
forall a. Maybe a
Prelude.Nothing,
      $sel:parameters:DatabaseInput' :: Maybe (HashMap Text Text)
parameters = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:description:DatabaseInput' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:createTableDefaultPermissions:DatabaseInput' :: Maybe [PrincipalPermissions]
createTableDefaultPermissions = Maybe [PrincipalPermissions]
forall a. Maybe a
Prelude.Nothing,
      $sel:name:DatabaseInput' :: Text
name = Text
pName_
    }

-- | The location of the database (for example, an HDFS path).
databaseInput_locationUri :: Lens.Lens' DatabaseInput (Prelude.Maybe Prelude.Text)
databaseInput_locationUri :: (Maybe Text -> f (Maybe Text)) -> DatabaseInput -> f DatabaseInput
databaseInput_locationUri = (DatabaseInput -> Maybe Text)
-> (DatabaseInput -> Maybe Text -> DatabaseInput)
-> Lens DatabaseInput DatabaseInput (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatabaseInput' {Maybe Text
locationUri :: Maybe Text
$sel:locationUri:DatabaseInput' :: DatabaseInput -> Maybe Text
locationUri} -> Maybe Text
locationUri) (\s :: DatabaseInput
s@DatabaseInput' {} Maybe Text
a -> DatabaseInput
s {$sel:locationUri:DatabaseInput' :: Maybe Text
locationUri = Maybe Text
a} :: DatabaseInput)

-- | A @DatabaseIdentifier@ structure that describes a target database for
-- resource linking.
databaseInput_targetDatabase :: Lens.Lens' DatabaseInput (Prelude.Maybe DatabaseIdentifier)
databaseInput_targetDatabase :: (Maybe DatabaseIdentifier -> f (Maybe DatabaseIdentifier))
-> DatabaseInput -> f DatabaseInput
databaseInput_targetDatabase = (DatabaseInput -> Maybe DatabaseIdentifier)
-> (DatabaseInput -> Maybe DatabaseIdentifier -> DatabaseInput)
-> Lens
     DatabaseInput
     DatabaseInput
     (Maybe DatabaseIdentifier)
     (Maybe DatabaseIdentifier)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatabaseInput' {Maybe DatabaseIdentifier
targetDatabase :: Maybe DatabaseIdentifier
$sel:targetDatabase:DatabaseInput' :: DatabaseInput -> Maybe DatabaseIdentifier
targetDatabase} -> Maybe DatabaseIdentifier
targetDatabase) (\s :: DatabaseInput
s@DatabaseInput' {} Maybe DatabaseIdentifier
a -> DatabaseInput
s {$sel:targetDatabase:DatabaseInput' :: Maybe DatabaseIdentifier
targetDatabase = Maybe DatabaseIdentifier
a} :: DatabaseInput)

-- | These key-value pairs define parameters and properties of the database.
--
-- These key-value pairs define parameters and properties of the database.
databaseInput_parameters :: Lens.Lens' DatabaseInput (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
databaseInput_parameters :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> DatabaseInput -> f DatabaseInput
databaseInput_parameters = (DatabaseInput -> Maybe (HashMap Text Text))
-> (DatabaseInput -> Maybe (HashMap Text Text) -> DatabaseInput)
-> Lens
     DatabaseInput
     DatabaseInput
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatabaseInput' {Maybe (HashMap Text Text)
parameters :: Maybe (HashMap Text Text)
$sel:parameters:DatabaseInput' :: DatabaseInput -> Maybe (HashMap Text Text)
parameters} -> Maybe (HashMap Text Text)
parameters) (\s :: DatabaseInput
s@DatabaseInput' {} Maybe (HashMap Text Text)
a -> DatabaseInput
s {$sel:parameters:DatabaseInput' :: Maybe (HashMap Text Text)
parameters = Maybe (HashMap Text Text)
a} :: DatabaseInput) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> DatabaseInput -> f DatabaseInput)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> DatabaseInput
-> f DatabaseInput
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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 AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A description of the database.
databaseInput_description :: Lens.Lens' DatabaseInput (Prelude.Maybe Prelude.Text)
databaseInput_description :: (Maybe Text -> f (Maybe Text)) -> DatabaseInput -> f DatabaseInput
databaseInput_description = (DatabaseInput -> Maybe Text)
-> (DatabaseInput -> Maybe Text -> DatabaseInput)
-> Lens DatabaseInput DatabaseInput (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatabaseInput' {Maybe Text
description :: Maybe Text
$sel:description:DatabaseInput' :: DatabaseInput -> Maybe Text
description} -> Maybe Text
description) (\s :: DatabaseInput
s@DatabaseInput' {} Maybe Text
a -> DatabaseInput
s {$sel:description:DatabaseInput' :: Maybe Text
description = Maybe Text
a} :: DatabaseInput)

-- | Creates a set of default permissions on the table for principals.
databaseInput_createTableDefaultPermissions :: Lens.Lens' DatabaseInput (Prelude.Maybe [PrincipalPermissions])
databaseInput_createTableDefaultPermissions :: (Maybe [PrincipalPermissions] -> f (Maybe [PrincipalPermissions]))
-> DatabaseInput -> f DatabaseInput
databaseInput_createTableDefaultPermissions = (DatabaseInput -> Maybe [PrincipalPermissions])
-> (DatabaseInput -> Maybe [PrincipalPermissions] -> DatabaseInput)
-> Lens
     DatabaseInput
     DatabaseInput
     (Maybe [PrincipalPermissions])
     (Maybe [PrincipalPermissions])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatabaseInput' {Maybe [PrincipalPermissions]
createTableDefaultPermissions :: Maybe [PrincipalPermissions]
$sel:createTableDefaultPermissions:DatabaseInput' :: DatabaseInput -> Maybe [PrincipalPermissions]
createTableDefaultPermissions} -> Maybe [PrincipalPermissions]
createTableDefaultPermissions) (\s :: DatabaseInput
s@DatabaseInput' {} Maybe [PrincipalPermissions]
a -> DatabaseInput
s {$sel:createTableDefaultPermissions:DatabaseInput' :: Maybe [PrincipalPermissions]
createTableDefaultPermissions = Maybe [PrincipalPermissions]
a} :: DatabaseInput) ((Maybe [PrincipalPermissions] -> f (Maybe [PrincipalPermissions]))
 -> DatabaseInput -> f DatabaseInput)
-> ((Maybe [PrincipalPermissions]
     -> f (Maybe [PrincipalPermissions]))
    -> Maybe [PrincipalPermissions]
    -> f (Maybe [PrincipalPermissions]))
-> (Maybe [PrincipalPermissions]
    -> f (Maybe [PrincipalPermissions]))
-> DatabaseInput
-> f DatabaseInput
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [PrincipalPermissions]
  [PrincipalPermissions]
  [PrincipalPermissions]
  [PrincipalPermissions]
-> Iso
     (Maybe [PrincipalPermissions])
     (Maybe [PrincipalPermissions])
     (Maybe [PrincipalPermissions])
     (Maybe [PrincipalPermissions])
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 AnIso
  [PrincipalPermissions]
  [PrincipalPermissions]
  [PrincipalPermissions]
  [PrincipalPermissions]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the database. For Hive compatibility, this is folded to
-- lowercase when it is stored.
databaseInput_name :: Lens.Lens' DatabaseInput Prelude.Text
databaseInput_name :: (Text -> f Text) -> DatabaseInput -> f DatabaseInput
databaseInput_name = (DatabaseInput -> Text)
-> (DatabaseInput -> Text -> DatabaseInput)
-> Lens DatabaseInput DatabaseInput Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatabaseInput' {Text
name :: Text
$sel:name:DatabaseInput' :: DatabaseInput -> Text
name} -> Text
name) (\s :: DatabaseInput
s@DatabaseInput' {} Text
a -> DatabaseInput
s {$sel:name:DatabaseInput' :: Text
name = Text
a} :: DatabaseInput)

instance Prelude.Hashable DatabaseInput

instance Prelude.NFData DatabaseInput

instance Core.ToJSON DatabaseInput where
  toJSON :: DatabaseInput -> Value
toJSON DatabaseInput' {Maybe [PrincipalPermissions]
Maybe Text
Maybe (HashMap Text Text)
Maybe DatabaseIdentifier
Text
name :: Text
createTableDefaultPermissions :: Maybe [PrincipalPermissions]
description :: Maybe Text
parameters :: Maybe (HashMap Text Text)
targetDatabase :: Maybe DatabaseIdentifier
locationUri :: Maybe Text
$sel:name:DatabaseInput' :: DatabaseInput -> Text
$sel:createTableDefaultPermissions:DatabaseInput' :: DatabaseInput -> Maybe [PrincipalPermissions]
$sel:description:DatabaseInput' :: DatabaseInput -> Maybe Text
$sel:parameters:DatabaseInput' :: DatabaseInput -> Maybe (HashMap Text Text)
$sel:targetDatabase:DatabaseInput' :: DatabaseInput -> Maybe DatabaseIdentifier
$sel:locationUri:DatabaseInput' :: DatabaseInput -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"LocationUri" 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
locationUri,
            (Text
"TargetDatabase" Text -> DatabaseIdentifier -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (DatabaseIdentifier -> Pair)
-> Maybe DatabaseIdentifier -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DatabaseIdentifier
targetDatabase,
            (Text
"Parameters" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
parameters,
            (Text
"Description" 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
description,
            (Text
"CreateTableDefaultPermissions" Text -> [PrincipalPermissions] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([PrincipalPermissions] -> Pair)
-> Maybe [PrincipalPermissions] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [PrincipalPermissions]
createTableDefaultPermissions,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)
          ]
      )