{-# 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.Athena.GetDatabase
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns a database object for the specified database and data catalog.
module Amazonka.Athena.GetDatabase
  ( -- * Creating a Request
    GetDatabase (..),
    newGetDatabase,

    -- * Request Lenses
    getDatabase_catalogName,
    getDatabase_databaseName,

    -- * Destructuring the Response
    GetDatabaseResponse (..),
    newGetDatabaseResponse,

    -- * Response Lenses
    getDatabaseResponse_database,
    getDatabaseResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetDatabase' smart constructor.
data GetDatabase = GetDatabase'
  { -- | The name of the data catalog that contains the database to return.
    GetDatabase -> Text
catalogName :: Prelude.Text,
    -- | The name of the database to return.
    GetDatabase -> Text
databaseName :: Prelude.Text
  }
  deriving (GetDatabase -> GetDatabase -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDatabase -> GetDatabase -> Bool
$c/= :: GetDatabase -> GetDatabase -> Bool
== :: GetDatabase -> GetDatabase -> Bool
$c== :: GetDatabase -> GetDatabase -> Bool
Prelude.Eq, ReadPrec [GetDatabase]
ReadPrec GetDatabase
Int -> ReadS GetDatabase
ReadS [GetDatabase]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetDatabase]
$creadListPrec :: ReadPrec [GetDatabase]
readPrec :: ReadPrec GetDatabase
$creadPrec :: ReadPrec GetDatabase
readList :: ReadS [GetDatabase]
$creadList :: ReadS [GetDatabase]
readsPrec :: Int -> ReadS GetDatabase
$creadsPrec :: Int -> ReadS GetDatabase
Prelude.Read, Int -> GetDatabase -> ShowS
[GetDatabase] -> ShowS
GetDatabase -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDatabase] -> ShowS
$cshowList :: [GetDatabase] -> ShowS
show :: GetDatabase -> String
$cshow :: GetDatabase -> String
showsPrec :: Int -> GetDatabase -> ShowS
$cshowsPrec :: Int -> GetDatabase -> ShowS
Prelude.Show, forall x. Rep GetDatabase x -> GetDatabase
forall x. GetDatabase -> Rep GetDatabase x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetDatabase x -> GetDatabase
$cfrom :: forall x. GetDatabase -> Rep GetDatabase x
Prelude.Generic)

-- |
-- Create a value of 'GetDatabase' 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:
--
-- 'catalogName', 'getDatabase_catalogName' - The name of the data catalog that contains the database to return.
--
-- 'databaseName', 'getDatabase_databaseName' - The name of the database to return.
newGetDatabase ::
  -- | 'catalogName'
  Prelude.Text ->
  -- | 'databaseName'
  Prelude.Text ->
  GetDatabase
newGetDatabase :: Text -> Text -> GetDatabase
newGetDatabase Text
pCatalogName_ Text
pDatabaseName_ =
  GetDatabase'
    { $sel:catalogName:GetDatabase' :: Text
catalogName = Text
pCatalogName_,
      $sel:databaseName:GetDatabase' :: Text
databaseName = Text
pDatabaseName_
    }

-- | The name of the data catalog that contains the database to return.
getDatabase_catalogName :: Lens.Lens' GetDatabase Prelude.Text
getDatabase_catalogName :: Lens' GetDatabase Text
getDatabase_catalogName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDatabase' {Text
catalogName :: Text
$sel:catalogName:GetDatabase' :: GetDatabase -> Text
catalogName} -> Text
catalogName) (\s :: GetDatabase
s@GetDatabase' {} Text
a -> GetDatabase
s {$sel:catalogName:GetDatabase' :: Text
catalogName = Text
a} :: GetDatabase)

-- | The name of the database to return.
getDatabase_databaseName :: Lens.Lens' GetDatabase Prelude.Text
getDatabase_databaseName :: Lens' GetDatabase Text
getDatabase_databaseName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDatabase' {Text
databaseName :: Text
$sel:databaseName:GetDatabase' :: GetDatabase -> Text
databaseName} -> Text
databaseName) (\s :: GetDatabase
s@GetDatabase' {} Text
a -> GetDatabase
s {$sel:databaseName:GetDatabase' :: Text
databaseName = Text
a} :: GetDatabase)

instance Core.AWSRequest GetDatabase where
  type AWSResponse GetDatabase = GetDatabaseResponse
  request :: (Service -> Service) -> GetDatabase -> Request GetDatabase
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 GetDatabase
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetDatabase)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Database -> Int -> GetDatabaseResponse
GetDatabaseResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Database")
            forall (f :: * -> *) a b. Applicative f => 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 GetDatabase where
  hashWithSalt :: Int -> GetDatabase -> Int
hashWithSalt Int
_salt GetDatabase' {Text
databaseName :: Text
catalogName :: Text
$sel:databaseName:GetDatabase' :: GetDatabase -> Text
$sel:catalogName:GetDatabase' :: GetDatabase -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
catalogName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
databaseName

instance Prelude.NFData GetDatabase where
  rnf :: GetDatabase -> ()
rnf GetDatabase' {Text
databaseName :: Text
catalogName :: Text
$sel:databaseName:GetDatabase' :: GetDatabase -> Text
$sel:catalogName:GetDatabase' :: GetDatabase -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
catalogName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
databaseName

instance Data.ToHeaders GetDatabase where
  toHeaders :: GetDatabase -> 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
"AmazonAthena.GetDatabase" :: 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 GetDatabase where
  toJSON :: GetDatabase -> Value
toJSON GetDatabase' {Text
databaseName :: Text
catalogName :: Text
$sel:databaseName:GetDatabase' :: GetDatabase -> Text
$sel:catalogName:GetDatabase' :: GetDatabase -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"CatalogName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
catalogName),
            forall a. a -> Maybe a
Prelude.Just (Key
"DatabaseName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
databaseName)
          ]
      )

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

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

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

-- |
-- Create a value of 'GetDatabaseResponse' 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:
--
-- 'database', 'getDatabaseResponse_database' - The database returned.
--
-- 'httpStatus', 'getDatabaseResponse_httpStatus' - The response's http status code.
newGetDatabaseResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetDatabaseResponse
newGetDatabaseResponse :: Int -> GetDatabaseResponse
newGetDatabaseResponse Int
pHttpStatus_ =
  GetDatabaseResponse'
    { $sel:database:GetDatabaseResponse' :: Maybe Database
database = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetDatabaseResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The database returned.
getDatabaseResponse_database :: Lens.Lens' GetDatabaseResponse (Prelude.Maybe Database)
getDatabaseResponse_database :: Lens' GetDatabaseResponse (Maybe Database)
getDatabaseResponse_database = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDatabaseResponse' {Maybe Database
database :: Maybe Database
$sel:database:GetDatabaseResponse' :: GetDatabaseResponse -> Maybe Database
database} -> Maybe Database
database) (\s :: GetDatabaseResponse
s@GetDatabaseResponse' {} Maybe Database
a -> GetDatabaseResponse
s {$sel:database:GetDatabaseResponse' :: Maybe Database
database = Maybe Database
a} :: GetDatabaseResponse)

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

instance Prelude.NFData GetDatabaseResponse where
  rnf :: GetDatabaseResponse -> ()
rnf GetDatabaseResponse' {Int
Maybe Database
httpStatus :: Int
database :: Maybe Database
$sel:httpStatus:GetDatabaseResponse' :: GetDatabaseResponse -> Int
$sel:database:GetDatabaseResponse' :: GetDatabaseResponse -> Maybe Database
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Database
database
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus