{-# 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.UpdateDatabase
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Updates an existing database definition in a Data Catalog.
module Amazonka.Glue.UpdateDatabase
  ( -- * Creating a Request
    UpdateDatabase (..),
    newUpdateDatabase,

    -- * Request Lenses
    updateDatabase_catalogId,
    updateDatabase_name,
    updateDatabase_databaseInput,

    -- * Destructuring the Response
    UpdateDatabaseResponse (..),
    newUpdateDatabaseResponse,

    -- * Response Lenses
    updateDatabaseResponse_httpStatus,
  )
where

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

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

-- |
-- Create a value of 'UpdateDatabase' 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', 'updateDatabase_catalogId' - The ID of the Data Catalog in which the metadata database resides. If
-- none is provided, the Amazon Web Services account ID is used by default.
--
-- 'name', 'updateDatabase_name' - The name of the database to update in the catalog. For Hive
-- compatibility, this is folded to lowercase.
--
-- 'databaseInput', 'updateDatabase_databaseInput' - A @DatabaseInput@ object specifying the new definition of the metadata
-- database in the catalog.
newUpdateDatabase ::
  -- | 'name'
  Prelude.Text ->
  -- | 'databaseInput'
  DatabaseInput ->
  UpdateDatabase
newUpdateDatabase :: Text -> DatabaseInput -> UpdateDatabase
newUpdateDatabase Text
pName_ DatabaseInput
pDatabaseInput_ =
  UpdateDatabase'
    { $sel:catalogId:UpdateDatabase' :: Maybe Text
catalogId = forall a. Maybe a
Prelude.Nothing,
      $sel:name:UpdateDatabase' :: Text
name = Text
pName_,
      $sel:databaseInput:UpdateDatabase' :: DatabaseInput
databaseInput = DatabaseInput
pDatabaseInput_
    }

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

-- | The name of the database to update in the catalog. For Hive
-- compatibility, this is folded to lowercase.
updateDatabase_name :: Lens.Lens' UpdateDatabase Prelude.Text
updateDatabase_name :: Lens' UpdateDatabase Text
updateDatabase_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateDatabase' {Text
name :: Text
$sel:name:UpdateDatabase' :: UpdateDatabase -> Text
name} -> Text
name) (\s :: UpdateDatabase
s@UpdateDatabase' {} Text
a -> UpdateDatabase
s {$sel:name:UpdateDatabase' :: Text
name = Text
a} :: UpdateDatabase)

-- | A @DatabaseInput@ object specifying the new definition of the metadata
-- database in the catalog.
updateDatabase_databaseInput :: Lens.Lens' UpdateDatabase DatabaseInput
updateDatabase_databaseInput :: Lens' UpdateDatabase DatabaseInput
updateDatabase_databaseInput = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateDatabase' {DatabaseInput
databaseInput :: DatabaseInput
$sel:databaseInput:UpdateDatabase' :: UpdateDatabase -> DatabaseInput
databaseInput} -> DatabaseInput
databaseInput) (\s :: UpdateDatabase
s@UpdateDatabase' {} DatabaseInput
a -> UpdateDatabase
s {$sel:databaseInput:UpdateDatabase' :: DatabaseInput
databaseInput = DatabaseInput
a} :: UpdateDatabase)

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

instance Prelude.Hashable UpdateDatabase where
  hashWithSalt :: Int -> UpdateDatabase -> Int
hashWithSalt Int
_salt UpdateDatabase' {Maybe Text
Text
DatabaseInput
databaseInput :: DatabaseInput
name :: Text
catalogId :: Maybe Text
$sel:databaseInput:UpdateDatabase' :: UpdateDatabase -> DatabaseInput
$sel:name:UpdateDatabase' :: UpdateDatabase -> Text
$sel:catalogId:UpdateDatabase' :: UpdateDatabase -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
catalogId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` DatabaseInput
databaseInput

instance Prelude.NFData UpdateDatabase where
  rnf :: UpdateDatabase -> ()
rnf UpdateDatabase' {Maybe Text
Text
DatabaseInput
databaseInput :: DatabaseInput
name :: Text
catalogId :: Maybe Text
$sel:databaseInput:UpdateDatabase' :: UpdateDatabase -> DatabaseInput
$sel:name:UpdateDatabase' :: UpdateDatabase -> Text
$sel:catalogId:UpdateDatabase' :: UpdateDatabase -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
catalogId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf DatabaseInput
databaseInput

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

instance Data.ToJSON UpdateDatabase where
  toJSON :: UpdateDatabase -> Value
toJSON UpdateDatabase' {Maybe Text
Text
DatabaseInput
databaseInput :: DatabaseInput
name :: Text
catalogId :: Maybe Text
$sel:databaseInput:UpdateDatabase' :: UpdateDatabase -> DatabaseInput
$sel:name:UpdateDatabase' :: UpdateDatabase -> Text
$sel:catalogId:UpdateDatabase' :: UpdateDatabase -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CatalogId" 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
catalogId,
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"DatabaseInput" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= DatabaseInput
databaseInput)
          ]
      )

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

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

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

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

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

instance Prelude.NFData UpdateDatabaseResponse where
  rnf :: UpdateDatabaseResponse -> ()
rnf UpdateDatabaseResponse' {Int
httpStatus :: Int
$sel:httpStatus:UpdateDatabaseResponse' :: UpdateDatabaseResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus