{-# 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-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)
--
-- 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 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:/ '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
(UpdateDatabase -> UpdateDatabase -> Bool)
-> (UpdateDatabase -> UpdateDatabase -> Bool) -> Eq UpdateDatabase
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]
(Int -> ReadS UpdateDatabase)
-> ReadS [UpdateDatabase]
-> ReadPrec UpdateDatabase
-> ReadPrec [UpdateDatabase]
-> Read 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
(Int -> UpdateDatabase -> ShowS)
-> (UpdateDatabase -> String)
-> ([UpdateDatabase] -> ShowS)
-> Show UpdateDatabase
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. UpdateDatabase -> Rep UpdateDatabase x)
-> (forall x. Rep UpdateDatabase x -> UpdateDatabase)
-> Generic UpdateDatabase
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' :: Maybe Text -> Text -> DatabaseInput -> UpdateDatabase
UpdateDatabase'
    { $sel:catalogId:UpdateDatabase' :: Maybe Text
catalogId = Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> UpdateDatabase -> f UpdateDatabase
updateDatabase_catalogId = (UpdateDatabase -> Maybe Text)
-> (UpdateDatabase -> Maybe Text -> UpdateDatabase)
-> Lens UpdateDatabase UpdateDatabase (Maybe Text) (Maybe Text)
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 :: (Text -> f Text) -> UpdateDatabase -> f UpdateDatabase
updateDatabase_name = (UpdateDatabase -> Text)
-> (UpdateDatabase -> Text -> UpdateDatabase)
-> Lens UpdateDatabase UpdateDatabase Text Text
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 :: (DatabaseInput -> f DatabaseInput)
-> UpdateDatabase -> f UpdateDatabase
updateDatabase_databaseInput = (UpdateDatabase -> DatabaseInput)
-> (UpdateDatabase -> DatabaseInput -> UpdateDatabase)
-> Lens UpdateDatabase UpdateDatabase DatabaseInput 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 :: UpdateDatabase -> Request UpdateDatabase
request = Service -> UpdateDatabase -> Request UpdateDatabase
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateDatabase
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateDatabase)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse UpdateDatabase))
-> Logger
-> Service
-> Proxy UpdateDatabase
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateDatabase)))
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 -> UpdateDatabaseResponse
UpdateDatabaseResponse'
            (Int -> UpdateDatabaseResponse)
-> Either String Int -> Either String UpdateDatabaseResponse
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 UpdateDatabase

instance Prelude.NFData UpdateDatabase

instance Core.ToHeaders UpdateDatabase where
  toHeaders :: UpdateDatabase -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateDatabase -> 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.UpdateDatabase" :: 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 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
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),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"DatabaseInput" Text -> DatabaseInput -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= DatabaseInput
databaseInput)
          ]
      )

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

instance Core.ToQuery UpdateDatabase where
  toQuery :: UpdateDatabase -> QueryString
toQuery = QueryString -> UpdateDatabase -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(UpdateDatabaseResponse -> UpdateDatabaseResponse -> Bool)
-> (UpdateDatabaseResponse -> UpdateDatabaseResponse -> Bool)
-> Eq UpdateDatabaseResponse
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]
(Int -> ReadS UpdateDatabaseResponse)
-> ReadS [UpdateDatabaseResponse]
-> ReadPrec UpdateDatabaseResponse
-> ReadPrec [UpdateDatabaseResponse]
-> Read 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
(Int -> UpdateDatabaseResponse -> ShowS)
-> (UpdateDatabaseResponse -> String)
-> ([UpdateDatabaseResponse] -> ShowS)
-> Show UpdateDatabaseResponse
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. UpdateDatabaseResponse -> Rep UpdateDatabaseResponse x)
-> (forall x.
    Rep UpdateDatabaseResponse x -> UpdateDatabaseResponse)
-> Generic UpdateDatabaseResponse
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' :: Int -> UpdateDatabaseResponse
UpdateDatabaseResponse' {$sel:httpStatus:UpdateDatabaseResponse' :: Int
httpStatus = Int
pHttpStatus_}

-- | The response's http status code.
updateDatabaseResponse_httpStatus :: Lens.Lens' UpdateDatabaseResponse Prelude.Int
updateDatabaseResponse_httpStatus :: (Int -> f Int)
-> UpdateDatabaseResponse -> f UpdateDatabaseResponse
updateDatabaseResponse_httpStatus = (UpdateDatabaseResponse -> Int)
-> (UpdateDatabaseResponse -> Int -> UpdateDatabaseResponse)
-> Lens UpdateDatabaseResponse UpdateDatabaseResponse Int Int
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