{-# 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.CreateDatabase
-- 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)
--
-- Creates a new database in a Data Catalog.
module Amazonka.Glue.CreateDatabase
  ( -- * Creating a Request
    CreateDatabase (..),
    newCreateDatabase,

    -- * Request Lenses
    createDatabase_catalogId,
    createDatabase_databaseInput,

    -- * Destructuring the Response
    CreateDatabaseResponse (..),
    newCreateDatabaseResponse,

    -- * Response Lenses
    createDatabaseResponse_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:/ 'newCreateDatabase' smart constructor.
data CreateDatabase = CreateDatabase'
  { -- | The ID of the Data Catalog in which to create the database. If none is
    -- provided, the Amazon Web Services account ID is used by default.
    CreateDatabase -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | The metadata for the database.
    CreateDatabase -> DatabaseInput
databaseInput :: DatabaseInput
  }
  deriving (CreateDatabase -> CreateDatabase -> Bool
(CreateDatabase -> CreateDatabase -> Bool)
-> (CreateDatabase -> CreateDatabase -> Bool) -> Eq CreateDatabase
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateDatabase -> CreateDatabase -> Bool
$c/= :: CreateDatabase -> CreateDatabase -> Bool
== :: CreateDatabase -> CreateDatabase -> Bool
$c== :: CreateDatabase -> CreateDatabase -> Bool
Prelude.Eq, ReadPrec [CreateDatabase]
ReadPrec CreateDatabase
Int -> ReadS CreateDatabase
ReadS [CreateDatabase]
(Int -> ReadS CreateDatabase)
-> ReadS [CreateDatabase]
-> ReadPrec CreateDatabase
-> ReadPrec [CreateDatabase]
-> Read CreateDatabase
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateDatabase]
$creadListPrec :: ReadPrec [CreateDatabase]
readPrec :: ReadPrec CreateDatabase
$creadPrec :: ReadPrec CreateDatabase
readList :: ReadS [CreateDatabase]
$creadList :: ReadS [CreateDatabase]
readsPrec :: Int -> ReadS CreateDatabase
$creadsPrec :: Int -> ReadS CreateDatabase
Prelude.Read, Int -> CreateDatabase -> ShowS
[CreateDatabase] -> ShowS
CreateDatabase -> String
(Int -> CreateDatabase -> ShowS)
-> (CreateDatabase -> String)
-> ([CreateDatabase] -> ShowS)
-> Show CreateDatabase
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateDatabase] -> ShowS
$cshowList :: [CreateDatabase] -> ShowS
show :: CreateDatabase -> String
$cshow :: CreateDatabase -> String
showsPrec :: Int -> CreateDatabase -> ShowS
$cshowsPrec :: Int -> CreateDatabase -> ShowS
Prelude.Show, (forall x. CreateDatabase -> Rep CreateDatabase x)
-> (forall x. Rep CreateDatabase x -> CreateDatabase)
-> Generic CreateDatabase
forall x. Rep CreateDatabase x -> CreateDatabase
forall x. CreateDatabase -> Rep CreateDatabase x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateDatabase x -> CreateDatabase
$cfrom :: forall x. CreateDatabase -> Rep CreateDatabase x
Prelude.Generic)

-- |
-- Create a value of 'CreateDatabase' 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', 'createDatabase_catalogId' - The ID of the Data Catalog in which to create the database. If none is
-- provided, the Amazon Web Services account ID is used by default.
--
-- 'databaseInput', 'createDatabase_databaseInput' - The metadata for the database.
newCreateDatabase ::
  -- | 'databaseInput'
  DatabaseInput ->
  CreateDatabase
newCreateDatabase :: DatabaseInput -> CreateDatabase
newCreateDatabase DatabaseInput
pDatabaseInput_ =
  CreateDatabase' :: Maybe Text -> DatabaseInput -> CreateDatabase
CreateDatabase'
    { $sel:catalogId:CreateDatabase' :: Maybe Text
catalogId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:databaseInput:CreateDatabase' :: DatabaseInput
databaseInput = DatabaseInput
pDatabaseInput_
    }

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

-- | The metadata for the database.
createDatabase_databaseInput :: Lens.Lens' CreateDatabase DatabaseInput
createDatabase_databaseInput :: (DatabaseInput -> f DatabaseInput)
-> CreateDatabase -> f CreateDatabase
createDatabase_databaseInput = (CreateDatabase -> DatabaseInput)
-> (CreateDatabase -> DatabaseInput -> CreateDatabase)
-> Lens CreateDatabase CreateDatabase DatabaseInput DatabaseInput
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDatabase' {DatabaseInput
databaseInput :: DatabaseInput
$sel:databaseInput:CreateDatabase' :: CreateDatabase -> DatabaseInput
databaseInput} -> DatabaseInput
databaseInput) (\s :: CreateDatabase
s@CreateDatabase' {} DatabaseInput
a -> CreateDatabase
s {$sel:databaseInput:CreateDatabase' :: DatabaseInput
databaseInput = DatabaseInput
a} :: CreateDatabase)

instance Core.AWSRequest CreateDatabase where
  type
    AWSResponse CreateDatabase =
      CreateDatabaseResponse
  request :: CreateDatabase -> Request CreateDatabase
request = Service -> CreateDatabase -> Request CreateDatabase
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateDatabase
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateDatabase)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse CreateDatabase))
-> Logger
-> Service
-> Proxy CreateDatabase
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateDatabase)))
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 -> CreateDatabaseResponse
CreateDatabaseResponse'
            (Int -> CreateDatabaseResponse)
-> Either String Int -> Either String CreateDatabaseResponse
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 CreateDatabase

instance Prelude.NFData CreateDatabase

instance Core.ToHeaders CreateDatabase where
  toHeaders :: CreateDatabase -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateDatabase -> 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.CreateDatabase" :: 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 CreateDatabase where
  toJSON :: CreateDatabase -> Value
toJSON CreateDatabase' {Maybe Text
DatabaseInput
databaseInput :: DatabaseInput
catalogId :: Maybe Text
$sel:databaseInput:CreateDatabase' :: CreateDatabase -> DatabaseInput
$sel:catalogId:CreateDatabase' :: CreateDatabase -> 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
"DatabaseInput" Text -> DatabaseInput -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= DatabaseInput
databaseInput)
          ]
      )

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

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

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

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

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

instance Prelude.NFData CreateDatabaseResponse