{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.DeleteDatabase
-- 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)
--
-- Removes a specified database from a Data Catalog.
--
-- After completing this operation, you no longer have access to the tables
-- (and all table versions and partitions that might belong to the tables)
-- and the user-defined functions in the deleted database. Glue deletes
-- these \"orphaned\" resources asynchronously in a timely manner, at the
-- discretion of the service.
--
-- To ensure the immediate deletion of all related resources, before
-- calling @DeleteDatabase@, use @DeleteTableVersion@ or
-- @BatchDeleteTableVersion@, @DeletePartition@ or @BatchDeletePartition@,
-- @DeleteUserDefinedFunction@, and @DeleteTable@ or @BatchDeleteTable@, to
-- delete any resources that belong to the database.
module Amazonka.Glue.DeleteDatabase
  ( -- * Creating a Request
    DeleteDatabase (..),
    newDeleteDatabase,

    -- * Request Lenses
    deleteDatabase_catalogId,
    deleteDatabase_name,

    -- * Destructuring the Response
    DeleteDatabaseResponse (..),
    newDeleteDatabaseResponse,

    -- * Response Lenses
    deleteDatabaseResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.Glue.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newDeleteDatabase' smart constructor.
data DeleteDatabase = DeleteDatabase'
  { -- | The ID of the Data Catalog in which the database resides. If none is
    -- provided, the Amazon Web Services account ID is used by default.
    DeleteDatabase -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | The name of the database to delete. For Hive compatibility, this must be
    -- all lowercase.
    DeleteDatabase -> Text
name :: Prelude.Text
  }
  deriving (DeleteDatabase -> DeleteDatabase -> Bool
(DeleteDatabase -> DeleteDatabase -> Bool)
-> (DeleteDatabase -> DeleteDatabase -> Bool) -> Eq DeleteDatabase
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteDatabase -> DeleteDatabase -> Bool
$c/= :: DeleteDatabase -> DeleteDatabase -> Bool
== :: DeleteDatabase -> DeleteDatabase -> Bool
$c== :: DeleteDatabase -> DeleteDatabase -> Bool
Prelude.Eq, ReadPrec [DeleteDatabase]
ReadPrec DeleteDatabase
Int -> ReadS DeleteDatabase
ReadS [DeleteDatabase]
(Int -> ReadS DeleteDatabase)
-> ReadS [DeleteDatabase]
-> ReadPrec DeleteDatabase
-> ReadPrec [DeleteDatabase]
-> Read DeleteDatabase
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteDatabase]
$creadListPrec :: ReadPrec [DeleteDatabase]
readPrec :: ReadPrec DeleteDatabase
$creadPrec :: ReadPrec DeleteDatabase
readList :: ReadS [DeleteDatabase]
$creadList :: ReadS [DeleteDatabase]
readsPrec :: Int -> ReadS DeleteDatabase
$creadsPrec :: Int -> ReadS DeleteDatabase
Prelude.Read, Int -> DeleteDatabase -> ShowS
[DeleteDatabase] -> ShowS
DeleteDatabase -> String
(Int -> DeleteDatabase -> ShowS)
-> (DeleteDatabase -> String)
-> ([DeleteDatabase] -> ShowS)
-> Show DeleteDatabase
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteDatabase] -> ShowS
$cshowList :: [DeleteDatabase] -> ShowS
show :: DeleteDatabase -> String
$cshow :: DeleteDatabase -> String
showsPrec :: Int -> DeleteDatabase -> ShowS
$cshowsPrec :: Int -> DeleteDatabase -> ShowS
Prelude.Show, (forall x. DeleteDatabase -> Rep DeleteDatabase x)
-> (forall x. Rep DeleteDatabase x -> DeleteDatabase)
-> Generic DeleteDatabase
forall x. Rep DeleteDatabase x -> DeleteDatabase
forall x. DeleteDatabase -> Rep DeleteDatabase x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteDatabase x -> DeleteDatabase
$cfrom :: forall x. DeleteDatabase -> Rep DeleteDatabase x
Prelude.Generic)

-- |
-- Create a value of 'DeleteDatabase' 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', 'deleteDatabase_catalogId' - The ID of the Data Catalog in which the database resides. If none is
-- provided, the Amazon Web Services account ID is used by default.
--
-- 'name', 'deleteDatabase_name' - The name of the database to delete. For Hive compatibility, this must be
-- all lowercase.
newDeleteDatabase ::
  -- | 'name'
  Prelude.Text ->
  DeleteDatabase
newDeleteDatabase :: Text -> DeleteDatabase
newDeleteDatabase Text
pName_ =
  DeleteDatabase' :: Maybe Text -> Text -> DeleteDatabase
DeleteDatabase'
    { $sel:catalogId:DeleteDatabase' :: Maybe Text
catalogId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:DeleteDatabase' :: Text
name = Text
pName_
    }

-- | The ID of the Data Catalog in which the database resides. If none is
-- provided, the Amazon Web Services account ID is used by default.
deleteDatabase_catalogId :: Lens.Lens' DeleteDatabase (Prelude.Maybe Prelude.Text)
deleteDatabase_catalogId :: (Maybe Text -> f (Maybe Text))
-> DeleteDatabase -> f DeleteDatabase
deleteDatabase_catalogId = (DeleteDatabase -> Maybe Text)
-> (DeleteDatabase -> Maybe Text -> DeleteDatabase)
-> Lens DeleteDatabase DeleteDatabase (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteDatabase' {Maybe Text
catalogId :: Maybe Text
$sel:catalogId:DeleteDatabase' :: DeleteDatabase -> Maybe Text
catalogId} -> Maybe Text
catalogId) (\s :: DeleteDatabase
s@DeleteDatabase' {} Maybe Text
a -> DeleteDatabase
s {$sel:catalogId:DeleteDatabase' :: Maybe Text
catalogId = Maybe Text
a} :: DeleteDatabase)

-- | The name of the database to delete. For Hive compatibility, this must be
-- all lowercase.
deleteDatabase_name :: Lens.Lens' DeleteDatabase Prelude.Text
deleteDatabase_name :: (Text -> f Text) -> DeleteDatabase -> f DeleteDatabase
deleteDatabase_name = (DeleteDatabase -> Text)
-> (DeleteDatabase -> Text -> DeleteDatabase)
-> Lens DeleteDatabase DeleteDatabase Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteDatabase' {Text
name :: Text
$sel:name:DeleteDatabase' :: DeleteDatabase -> Text
name} -> Text
name) (\s :: DeleteDatabase
s@DeleteDatabase' {} Text
a -> DeleteDatabase
s {$sel:name:DeleteDatabase' :: Text
name = Text
a} :: DeleteDatabase)

instance Core.AWSRequest DeleteDatabase where
  type
    AWSResponse DeleteDatabase =
      DeleteDatabaseResponse
  request :: DeleteDatabase -> Request DeleteDatabase
request = Service -> DeleteDatabase -> Request DeleteDatabase
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteDatabase
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteDatabase)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse DeleteDatabase))
-> Logger
-> Service
-> Proxy DeleteDatabase
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteDatabase)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> DeleteDatabaseResponse
DeleteDatabaseResponse'
            (Int -> DeleteDatabaseResponse)
-> Either String Int -> Either String DeleteDatabaseResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable DeleteDatabase

instance Prelude.NFData DeleteDatabase

instance Core.ToHeaders DeleteDatabase where
  toHeaders :: DeleteDatabase -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DeleteDatabase -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"AWSGlue.DeleteDatabase" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON DeleteDatabase where
  toJSON :: DeleteDatabase -> Value
toJSON DeleteDatabase' {Maybe Text
Text
name :: Text
catalogId :: Maybe Text
$sel:name:DeleteDatabase' :: DeleteDatabase -> Text
$sel:catalogId:DeleteDatabase' :: DeleteDatabase -> 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,
            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)
          ]
      )

instance Core.ToPath DeleteDatabase where
  toPath :: DeleteDatabase -> ByteString
toPath = ByteString -> DeleteDatabase -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery DeleteDatabase where
  toQuery :: DeleteDatabase -> QueryString
toQuery = QueryString -> DeleteDatabase -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newDeleteDatabaseResponse' smart constructor.
data DeleteDatabaseResponse = DeleteDatabaseResponse'
  { -- | The response's http status code.
    DeleteDatabaseResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DeleteDatabaseResponse -> DeleteDatabaseResponse -> Bool
(DeleteDatabaseResponse -> DeleteDatabaseResponse -> Bool)
-> (DeleteDatabaseResponse -> DeleteDatabaseResponse -> Bool)
-> Eq DeleteDatabaseResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteDatabaseResponse -> DeleteDatabaseResponse -> Bool
$c/= :: DeleteDatabaseResponse -> DeleteDatabaseResponse -> Bool
== :: DeleteDatabaseResponse -> DeleteDatabaseResponse -> Bool
$c== :: DeleteDatabaseResponse -> DeleteDatabaseResponse -> Bool
Prelude.Eq, ReadPrec [DeleteDatabaseResponse]
ReadPrec DeleteDatabaseResponse
Int -> ReadS DeleteDatabaseResponse
ReadS [DeleteDatabaseResponse]
(Int -> ReadS DeleteDatabaseResponse)
-> ReadS [DeleteDatabaseResponse]
-> ReadPrec DeleteDatabaseResponse
-> ReadPrec [DeleteDatabaseResponse]
-> Read DeleteDatabaseResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteDatabaseResponse]
$creadListPrec :: ReadPrec [DeleteDatabaseResponse]
readPrec :: ReadPrec DeleteDatabaseResponse
$creadPrec :: ReadPrec DeleteDatabaseResponse
readList :: ReadS [DeleteDatabaseResponse]
$creadList :: ReadS [DeleteDatabaseResponse]
readsPrec :: Int -> ReadS DeleteDatabaseResponse
$creadsPrec :: Int -> ReadS DeleteDatabaseResponse
Prelude.Read, Int -> DeleteDatabaseResponse -> ShowS
[DeleteDatabaseResponse] -> ShowS
DeleteDatabaseResponse -> String
(Int -> DeleteDatabaseResponse -> ShowS)
-> (DeleteDatabaseResponse -> String)
-> ([DeleteDatabaseResponse] -> ShowS)
-> Show DeleteDatabaseResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteDatabaseResponse] -> ShowS
$cshowList :: [DeleteDatabaseResponse] -> ShowS
show :: DeleteDatabaseResponse -> String
$cshow :: DeleteDatabaseResponse -> String
showsPrec :: Int -> DeleteDatabaseResponse -> ShowS
$cshowsPrec :: Int -> DeleteDatabaseResponse -> ShowS
Prelude.Show, (forall x. DeleteDatabaseResponse -> Rep DeleteDatabaseResponse x)
-> (forall x.
    Rep DeleteDatabaseResponse x -> DeleteDatabaseResponse)
-> Generic DeleteDatabaseResponse
forall x. Rep DeleteDatabaseResponse x -> DeleteDatabaseResponse
forall x. DeleteDatabaseResponse -> Rep DeleteDatabaseResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteDatabaseResponse x -> DeleteDatabaseResponse
$cfrom :: forall x. DeleteDatabaseResponse -> Rep DeleteDatabaseResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeleteDatabaseResponse' 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:
--
-- 'httpStatus', 'deleteDatabaseResponse_httpStatus' - The response's http status code.
newDeleteDatabaseResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteDatabaseResponse
newDeleteDatabaseResponse :: Int -> DeleteDatabaseResponse
newDeleteDatabaseResponse Int
pHttpStatus_ =
  DeleteDatabaseResponse' :: Int -> DeleteDatabaseResponse
DeleteDatabaseResponse' {$sel:httpStatus:DeleteDatabaseResponse' :: Int
httpStatus = Int
pHttpStatus_}

-- | The response's http status code.
deleteDatabaseResponse_httpStatus :: Lens.Lens' DeleteDatabaseResponse Prelude.Int
deleteDatabaseResponse_httpStatus :: (Int -> f Int)
-> DeleteDatabaseResponse -> f DeleteDatabaseResponse
deleteDatabaseResponse_httpStatus = (DeleteDatabaseResponse -> Int)
-> (DeleteDatabaseResponse -> Int -> DeleteDatabaseResponse)
-> Lens DeleteDatabaseResponse DeleteDatabaseResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteDatabaseResponse' {Int
httpStatus :: Int
$sel:httpStatus:DeleteDatabaseResponse' :: DeleteDatabaseResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: DeleteDatabaseResponse
s@DeleteDatabaseResponse' {} Int
a -> DeleteDatabaseResponse
s {$sel:httpStatus:DeleteDatabaseResponse' :: Int
httpStatus = Int
a} :: DeleteDatabaseResponse)

instance Prelude.NFData DeleteDatabaseResponse