{-# 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.TimeStreamWrite.DescribeDatabase
-- 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 information about the database, including the database name,
-- time that the database was created, and the total number of tables found
-- within the database.
-- <https://docs.aws.amazon.com/timestream/latest/developerguide/ts-limits.html Service quotas apply>.
-- See
-- <https://docs.aws.amazon.com/timestream/latest/developerguide/code-samples.describe-db.html code sample>
-- for details.
module Amazonka.TimeStreamWrite.DescribeDatabase
  ( -- * Creating a Request
    DescribeDatabase (..),
    newDescribeDatabase,

    -- * Request Lenses
    describeDatabase_databaseName,

    -- * Destructuring the Response
    DescribeDatabaseResponse (..),
    newDescribeDatabaseResponse,

    -- * Response Lenses
    describeDatabaseResponse_database,
    describeDatabaseResponse_httpStatus,
  )
where

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
import Amazonka.TimeStreamWrite.Types

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

-- |
-- Create a value of 'DescribeDatabase' 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:
--
-- 'databaseName', 'describeDatabase_databaseName' - The name of the Timestream database.
newDescribeDatabase ::
  -- | 'databaseName'
  Prelude.Text ->
  DescribeDatabase
newDescribeDatabase :: Text -> DescribeDatabase
newDescribeDatabase Text
pDatabaseName_ =
  DescribeDatabase' {$sel:databaseName:DescribeDatabase' :: Text
databaseName = Text
pDatabaseName_}

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

instance Core.AWSRequest DescribeDatabase where
  type
    AWSResponse DescribeDatabase =
      DescribeDatabaseResponse
  request :: (Service -> Service)
-> DescribeDatabase -> Request DescribeDatabase
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 DescribeDatabase
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DescribeDatabase)))
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 -> DescribeDatabaseResponse
DescribeDatabaseResponse'
            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 DescribeDatabase where
  hashWithSalt :: Int -> DescribeDatabase -> Int
hashWithSalt Int
_salt DescribeDatabase' {Text
databaseName :: Text
$sel:databaseName:DescribeDatabase' :: DescribeDatabase -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
databaseName

instance Prelude.NFData DescribeDatabase where
  rnf :: DescribeDatabase -> ()
rnf DescribeDatabase' {Text
databaseName :: Text
$sel:databaseName:DescribeDatabase' :: DescribeDatabase -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
databaseName

instance Data.ToHeaders DescribeDatabase where
  toHeaders :: DescribeDatabase -> 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
"Timestream_20181101.DescribeDatabase" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON DescribeDatabase where
  toJSON :: DescribeDatabase -> Value
toJSON DescribeDatabase' {Text
databaseName :: Text
$sel:databaseName:DescribeDatabase' :: DescribeDatabase -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [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 DescribeDatabase where
  toPath :: DescribeDatabase -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

-- |
-- Create a value of 'DescribeDatabaseResponse' 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', 'describeDatabaseResponse_database' - The name of the Timestream table.
--
-- 'httpStatus', 'describeDatabaseResponse_httpStatus' - The response's http status code.
newDescribeDatabaseResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeDatabaseResponse
newDescribeDatabaseResponse :: Int -> DescribeDatabaseResponse
newDescribeDatabaseResponse Int
pHttpStatus_ =
  DescribeDatabaseResponse'
    { $sel:database:DescribeDatabaseResponse' :: Maybe Database
database =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeDatabaseResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The name of the Timestream table.
describeDatabaseResponse_database :: Lens.Lens' DescribeDatabaseResponse (Prelude.Maybe Database)
describeDatabaseResponse_database :: Lens' DescribeDatabaseResponse (Maybe Database)
describeDatabaseResponse_database = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeDatabaseResponse' {Maybe Database
database :: Maybe Database
$sel:database:DescribeDatabaseResponse' :: DescribeDatabaseResponse -> Maybe Database
database} -> Maybe Database
database) (\s :: DescribeDatabaseResponse
s@DescribeDatabaseResponse' {} Maybe Database
a -> DescribeDatabaseResponse
s {$sel:database:DescribeDatabaseResponse' :: Maybe Database
database = Maybe Database
a} :: DescribeDatabaseResponse)

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

instance Prelude.NFData DescribeDatabaseResponse where
  rnf :: DescribeDatabaseResponse -> ()
rnf DescribeDatabaseResponse' {Int
Maybe Database
httpStatus :: Int
database :: Maybe Database
$sel:httpStatus:DescribeDatabaseResponse' :: DescribeDatabaseResponse -> Int
$sel:database:DescribeDatabaseResponse' :: DescribeDatabaseResponse -> 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