{-# 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.ListDatabases
-- 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 list of your Timestream databases.
-- <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.list-db.html code sample>
-- for details.
module Amazonka.TimeStreamWrite.ListDatabases
  ( -- * Creating a Request
    ListDatabases (..),
    newListDatabases,

    -- * Request Lenses
    listDatabases_maxResults,
    listDatabases_nextToken,

    -- * Destructuring the Response
    ListDatabasesResponse (..),
    newListDatabasesResponse,

    -- * Response Lenses
    listDatabasesResponse_databases,
    listDatabasesResponse_nextToken,
    listDatabasesResponse_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:/ 'newListDatabases' smart constructor.
data ListDatabases = ListDatabases'
  { -- | The total number of items to return in the output. If the total number
    -- of items available is more than the value specified, a NextToken is
    -- provided in the output. To resume pagination, provide the NextToken
    -- value as argument of a subsequent API invocation.
    ListDatabases -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The pagination token. To resume pagination, provide the NextToken value
    -- as argument of a subsequent API invocation.
    ListDatabases -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListDatabases -> ListDatabases -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListDatabases -> ListDatabases -> Bool
$c/= :: ListDatabases -> ListDatabases -> Bool
== :: ListDatabases -> ListDatabases -> Bool
$c== :: ListDatabases -> ListDatabases -> Bool
Prelude.Eq, ReadPrec [ListDatabases]
ReadPrec ListDatabases
Int -> ReadS ListDatabases
ReadS [ListDatabases]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListDatabases]
$creadListPrec :: ReadPrec [ListDatabases]
readPrec :: ReadPrec ListDatabases
$creadPrec :: ReadPrec ListDatabases
readList :: ReadS [ListDatabases]
$creadList :: ReadS [ListDatabases]
readsPrec :: Int -> ReadS ListDatabases
$creadsPrec :: Int -> ReadS ListDatabases
Prelude.Read, Int -> ListDatabases -> ShowS
[ListDatabases] -> ShowS
ListDatabases -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListDatabases] -> ShowS
$cshowList :: [ListDatabases] -> ShowS
show :: ListDatabases -> String
$cshow :: ListDatabases -> String
showsPrec :: Int -> ListDatabases -> ShowS
$cshowsPrec :: Int -> ListDatabases -> ShowS
Prelude.Show, forall x. Rep ListDatabases x -> ListDatabases
forall x. ListDatabases -> Rep ListDatabases x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListDatabases x -> ListDatabases
$cfrom :: forall x. ListDatabases -> Rep ListDatabases x
Prelude.Generic)

-- |
-- Create a value of 'ListDatabases' 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:
--
-- 'maxResults', 'listDatabases_maxResults' - The total number of items to return in the output. If the total number
-- of items available is more than the value specified, a NextToken is
-- provided in the output. To resume pagination, provide the NextToken
-- value as argument of a subsequent API invocation.
--
-- 'nextToken', 'listDatabases_nextToken' - The pagination token. To resume pagination, provide the NextToken value
-- as argument of a subsequent API invocation.
newListDatabases ::
  ListDatabases
newListDatabases :: ListDatabases
newListDatabases =
  ListDatabases'
    { $sel:maxResults:ListDatabases' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListDatabases' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The total number of items to return in the output. If the total number
-- of items available is more than the value specified, a NextToken is
-- provided in the output. To resume pagination, provide the NextToken
-- value as argument of a subsequent API invocation.
listDatabases_maxResults :: Lens.Lens' ListDatabases (Prelude.Maybe Prelude.Natural)
listDatabases_maxResults :: Lens' ListDatabases (Maybe Natural)
listDatabases_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListDatabases' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListDatabases' :: ListDatabases -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListDatabases
s@ListDatabases' {} Maybe Natural
a -> ListDatabases
s {$sel:maxResults:ListDatabases' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListDatabases)

-- | The pagination token. To resume pagination, provide the NextToken value
-- as argument of a subsequent API invocation.
listDatabases_nextToken :: Lens.Lens' ListDatabases (Prelude.Maybe Prelude.Text)
listDatabases_nextToken :: Lens' ListDatabases (Maybe Text)
listDatabases_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListDatabases' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListDatabases' :: ListDatabases -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListDatabases
s@ListDatabases' {} Maybe Text
a -> ListDatabases
s {$sel:nextToken:ListDatabases' :: Maybe Text
nextToken = Maybe Text
a} :: ListDatabases)

instance Core.AWSRequest ListDatabases where
  type
    AWSResponse ListDatabases =
      ListDatabasesResponse
  request :: (Service -> Service) -> ListDatabases -> Request ListDatabases
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 ListDatabases
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListDatabases)))
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] -> Maybe Text -> Int -> ListDatabasesResponse
ListDatabasesResponse'
            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
"Databases" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"NextToken")
            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 ListDatabases where
  hashWithSalt :: Int -> ListDatabases -> Int
hashWithSalt Int
_salt ListDatabases' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListDatabases' :: ListDatabases -> Maybe Text
$sel:maxResults:ListDatabases' :: ListDatabases -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxResults
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken

instance Prelude.NFData ListDatabases where
  rnf :: ListDatabases -> ()
rnf ListDatabases' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListDatabases' :: ListDatabases -> Maybe Text
$sel:maxResults:ListDatabases' :: ListDatabases -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxResults
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken

instance Data.ToHeaders ListDatabases where
  toHeaders :: ListDatabases -> 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.ListDatabases" ::
                          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 ListDatabases where
  toJSON :: ListDatabases -> Value
toJSON ListDatabases' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListDatabases' :: ListDatabases -> Maybe Text
$sel:maxResults:ListDatabases' :: ListDatabases -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"MaxResults" 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 Natural
maxResults,
            (Key
"NextToken" 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
nextToken
          ]
      )

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

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

-- | /See:/ 'newListDatabasesResponse' smart constructor.
data ListDatabasesResponse = ListDatabasesResponse'
  { -- | A list of database names.
    ListDatabasesResponse -> Maybe [Database]
databases :: Prelude.Maybe [Database],
    -- | The pagination token. This parameter is returned when the response is
    -- truncated.
    ListDatabasesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListDatabasesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListDatabasesResponse -> ListDatabasesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListDatabasesResponse -> ListDatabasesResponse -> Bool
$c/= :: ListDatabasesResponse -> ListDatabasesResponse -> Bool
== :: ListDatabasesResponse -> ListDatabasesResponse -> Bool
$c== :: ListDatabasesResponse -> ListDatabasesResponse -> Bool
Prelude.Eq, ReadPrec [ListDatabasesResponse]
ReadPrec ListDatabasesResponse
Int -> ReadS ListDatabasesResponse
ReadS [ListDatabasesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListDatabasesResponse]
$creadListPrec :: ReadPrec [ListDatabasesResponse]
readPrec :: ReadPrec ListDatabasesResponse
$creadPrec :: ReadPrec ListDatabasesResponse
readList :: ReadS [ListDatabasesResponse]
$creadList :: ReadS [ListDatabasesResponse]
readsPrec :: Int -> ReadS ListDatabasesResponse
$creadsPrec :: Int -> ReadS ListDatabasesResponse
Prelude.Read, Int -> ListDatabasesResponse -> ShowS
[ListDatabasesResponse] -> ShowS
ListDatabasesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListDatabasesResponse] -> ShowS
$cshowList :: [ListDatabasesResponse] -> ShowS
show :: ListDatabasesResponse -> String
$cshow :: ListDatabasesResponse -> String
showsPrec :: Int -> ListDatabasesResponse -> ShowS
$cshowsPrec :: Int -> ListDatabasesResponse -> ShowS
Prelude.Show, forall x. Rep ListDatabasesResponse x -> ListDatabasesResponse
forall x. ListDatabasesResponse -> Rep ListDatabasesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListDatabasesResponse x -> ListDatabasesResponse
$cfrom :: forall x. ListDatabasesResponse -> Rep ListDatabasesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListDatabasesResponse' 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:
--
-- 'databases', 'listDatabasesResponse_databases' - A list of database names.
--
-- 'nextToken', 'listDatabasesResponse_nextToken' - The pagination token. This parameter is returned when the response is
-- truncated.
--
-- 'httpStatus', 'listDatabasesResponse_httpStatus' - The response's http status code.
newListDatabasesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListDatabasesResponse
newListDatabasesResponse :: Int -> ListDatabasesResponse
newListDatabasesResponse Int
pHttpStatus_ =
  ListDatabasesResponse'
    { $sel:databases:ListDatabasesResponse' :: Maybe [Database]
databases = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListDatabasesResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListDatabasesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of database names.
listDatabasesResponse_databases :: Lens.Lens' ListDatabasesResponse (Prelude.Maybe [Database])
listDatabasesResponse_databases :: Lens' ListDatabasesResponse (Maybe [Database])
listDatabasesResponse_databases = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListDatabasesResponse' {Maybe [Database]
databases :: Maybe [Database]
$sel:databases:ListDatabasesResponse' :: ListDatabasesResponse -> Maybe [Database]
databases} -> Maybe [Database]
databases) (\s :: ListDatabasesResponse
s@ListDatabasesResponse' {} Maybe [Database]
a -> ListDatabasesResponse
s {$sel:databases:ListDatabasesResponse' :: Maybe [Database]
databases = Maybe [Database]
a} :: ListDatabasesResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The pagination token. This parameter is returned when the response is
-- truncated.
listDatabasesResponse_nextToken :: Lens.Lens' ListDatabasesResponse (Prelude.Maybe Prelude.Text)
listDatabasesResponse_nextToken :: Lens' ListDatabasesResponse (Maybe Text)
listDatabasesResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListDatabasesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListDatabasesResponse' :: ListDatabasesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListDatabasesResponse
s@ListDatabasesResponse' {} Maybe Text
a -> ListDatabasesResponse
s {$sel:nextToken:ListDatabasesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListDatabasesResponse)

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

instance Prelude.NFData ListDatabasesResponse where
  rnf :: ListDatabasesResponse -> ()
rnf ListDatabasesResponse' {Int
Maybe [Database]
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
databases :: Maybe [Database]
$sel:httpStatus:ListDatabasesResponse' :: ListDatabasesResponse -> Int
$sel:nextToken:ListDatabasesResponse' :: ListDatabasesResponse -> Maybe Text
$sel:databases:ListDatabasesResponse' :: ListDatabasesResponse -> Maybe [Database]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Database]
databases
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus