{-# 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.RedshiftData.ListTables
-- 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)
--
-- List the tables in a database. If neither @SchemaPattern@ nor
-- @TablePattern@ are specified, then all tables in the database are
-- returned. A token is returned to page through the table list. Depending
-- on the authorization method, use one of the following combinations of
-- request parameters:
--
-- -   Secrets Manager - specify the Amazon Resource Name (ARN) of the
--     secret, the database name, and the cluster identifier that matches
--     the cluster in the secret.
--
-- -   Temporary credentials - specify the cluster identifier, the database
--     name, and the database user name. Permission to call the
--     @redshift:GetClusterCredentials@ operation is required to use this
--     method.
--
-- This operation returns paginated results.
module Amazonka.RedshiftData.ListTables
  ( -- * Creating a Request
    ListTables (..),
    newListTables,

    -- * Request Lenses
    listTables_dbUser,
    listTables_connectedDatabase,
    listTables_nextToken,
    listTables_secretArn,
    listTables_tablePattern,
    listTables_maxResults,
    listTables_schemaPattern,
    listTables_clusterIdentifier,
    listTables_database,

    -- * Destructuring the Response
    ListTablesResponse (..),
    newListTablesResponse,

    -- * Response Lenses
    listTablesResponse_nextToken,
    listTablesResponse_tables,
    listTablesResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.RedshiftData.Types
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newListTables' smart constructor.
data ListTables = ListTables'
  { -- | The database user name. This parameter is required when authenticating
    -- using temporary credentials.
    ListTables -> Maybe Text
dbUser :: Prelude.Maybe Prelude.Text,
    -- | A database name. The connected database is specified when you connect
    -- with your authentication credentials.
    ListTables -> Maybe Text
connectedDatabase :: Prelude.Maybe Prelude.Text,
    -- | A value that indicates the starting point for the next set of response
    -- records in a subsequent request. If a value is returned in a response,
    -- you can retrieve the next set of records by providing this returned
    -- NextToken value in the next NextToken parameter and retrying the
    -- command. If the NextToken field is empty, all response records have been
    -- retrieved for the request.
    ListTables -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The name or ARN of the secret that enables access to the database. This
    -- parameter is required when authenticating using Secrets Manager.
    ListTables -> Maybe Text
secretArn :: Prelude.Maybe Prelude.Text,
    -- | A pattern to filter results by table name. Within a table pattern, \"%\"
    -- means match any substring of 0 or more characters and \"_\" means match
    -- any one character. Only table name entries matching the search pattern
    -- are returned. If @TablePattern@ is not specified, then all tables that
    -- match @SchemaPattern@are returned. If neither @SchemaPattern@ or
    -- @TablePattern@ are specified, then all tables are returned.
    ListTables -> Maybe Text
tablePattern :: Prelude.Maybe Prelude.Text,
    -- | The maximum number of tables to return in the response. If more tables
    -- exist than fit in one response, then @NextToken@ is returned to page
    -- through the results.
    ListTables -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | A pattern to filter results by schema name. Within a schema pattern,
    -- \"%\" means match any substring of 0 or more characters and \"_\" means
    -- match any one character. Only schema name entries matching the search
    -- pattern are returned. If @SchemaPattern@ is not specified, then all
    -- tables that match @TablePattern@ are returned. If neither
    -- @SchemaPattern@ or @TablePattern@ are specified, then all tables are
    -- returned.
    ListTables -> Maybe Text
schemaPattern :: Prelude.Maybe Prelude.Text,
    -- | The cluster identifier. This parameter is required when authenticating
    -- using either Secrets Manager or temporary credentials.
    ListTables -> Text
clusterIdentifier :: Prelude.Text,
    -- | The name of the database that contains the tables to list. If
    -- @ConnectedDatabase@ is not specified, this is also the database to
    -- connect to with your authentication credentials.
    ListTables -> Text
database :: Prelude.Text
  }
  deriving (ListTables -> ListTables -> Bool
(ListTables -> ListTables -> Bool)
-> (ListTables -> ListTables -> Bool) -> Eq ListTables
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListTables -> ListTables -> Bool
$c/= :: ListTables -> ListTables -> Bool
== :: ListTables -> ListTables -> Bool
$c== :: ListTables -> ListTables -> Bool
Prelude.Eq, ReadPrec [ListTables]
ReadPrec ListTables
Int -> ReadS ListTables
ReadS [ListTables]
(Int -> ReadS ListTables)
-> ReadS [ListTables]
-> ReadPrec ListTables
-> ReadPrec [ListTables]
-> Read ListTables
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListTables]
$creadListPrec :: ReadPrec [ListTables]
readPrec :: ReadPrec ListTables
$creadPrec :: ReadPrec ListTables
readList :: ReadS [ListTables]
$creadList :: ReadS [ListTables]
readsPrec :: Int -> ReadS ListTables
$creadsPrec :: Int -> ReadS ListTables
Prelude.Read, Int -> ListTables -> ShowS
[ListTables] -> ShowS
ListTables -> String
(Int -> ListTables -> ShowS)
-> (ListTables -> String)
-> ([ListTables] -> ShowS)
-> Show ListTables
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListTables] -> ShowS
$cshowList :: [ListTables] -> ShowS
show :: ListTables -> String
$cshow :: ListTables -> String
showsPrec :: Int -> ListTables -> ShowS
$cshowsPrec :: Int -> ListTables -> ShowS
Prelude.Show, (forall x. ListTables -> Rep ListTables x)
-> (forall x. Rep ListTables x -> ListTables) -> Generic ListTables
forall x. Rep ListTables x -> ListTables
forall x. ListTables -> Rep ListTables x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListTables x -> ListTables
$cfrom :: forall x. ListTables -> Rep ListTables x
Prelude.Generic)

-- |
-- Create a value of 'ListTables' 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:
--
-- 'dbUser', 'listTables_dbUser' - The database user name. This parameter is required when authenticating
-- using temporary credentials.
--
-- 'connectedDatabase', 'listTables_connectedDatabase' - A database name. The connected database is specified when you connect
-- with your authentication credentials.
--
-- 'nextToken', 'listTables_nextToken' - A value that indicates the starting point for the next set of response
-- records in a subsequent request. If a value is returned in a response,
-- you can retrieve the next set of records by providing this returned
-- NextToken value in the next NextToken parameter and retrying the
-- command. If the NextToken field is empty, all response records have been
-- retrieved for the request.
--
-- 'secretArn', 'listTables_secretArn' - The name or ARN of the secret that enables access to the database. This
-- parameter is required when authenticating using Secrets Manager.
--
-- 'tablePattern', 'listTables_tablePattern' - A pattern to filter results by table name. Within a table pattern, \"%\"
-- means match any substring of 0 or more characters and \"_\" means match
-- any one character. Only table name entries matching the search pattern
-- are returned. If @TablePattern@ is not specified, then all tables that
-- match @SchemaPattern@are returned. If neither @SchemaPattern@ or
-- @TablePattern@ are specified, then all tables are returned.
--
-- 'maxResults', 'listTables_maxResults' - The maximum number of tables to return in the response. If more tables
-- exist than fit in one response, then @NextToken@ is returned to page
-- through the results.
--
-- 'schemaPattern', 'listTables_schemaPattern' - A pattern to filter results by schema name. Within a schema pattern,
-- \"%\" means match any substring of 0 or more characters and \"_\" means
-- match any one character. Only schema name entries matching the search
-- pattern are returned. If @SchemaPattern@ is not specified, then all
-- tables that match @TablePattern@ are returned. If neither
-- @SchemaPattern@ or @TablePattern@ are specified, then all tables are
-- returned.
--
-- 'clusterIdentifier', 'listTables_clusterIdentifier' - The cluster identifier. This parameter is required when authenticating
-- using either Secrets Manager or temporary credentials.
--
-- 'database', 'listTables_database' - The name of the database that contains the tables to list. If
-- @ConnectedDatabase@ is not specified, this is also the database to
-- connect to with your authentication credentials.
newListTables ::
  -- | 'clusterIdentifier'
  Prelude.Text ->
  -- | 'database'
  Prelude.Text ->
  ListTables
newListTables :: Text -> Text -> ListTables
newListTables Text
pClusterIdentifier_ Text
pDatabase_ =
  ListTables' :: Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Natural
-> Maybe Text
-> Text
-> Text
-> ListTables
ListTables'
    { $sel:dbUser:ListTables' :: Maybe Text
dbUser = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:connectedDatabase:ListTables' :: Maybe Text
connectedDatabase = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListTables' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:secretArn:ListTables' :: Maybe Text
secretArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tablePattern:ListTables' :: Maybe Text
tablePattern = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:ListTables' :: Maybe Natural
maxResults = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:schemaPattern:ListTables' :: Maybe Text
schemaPattern = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:clusterIdentifier:ListTables' :: Text
clusterIdentifier = Text
pClusterIdentifier_,
      $sel:database:ListTables' :: Text
database = Text
pDatabase_
    }

-- | The database user name. This parameter is required when authenticating
-- using temporary credentials.
listTables_dbUser :: Lens.Lens' ListTables (Prelude.Maybe Prelude.Text)
listTables_dbUser :: (Maybe Text -> f (Maybe Text)) -> ListTables -> f ListTables
listTables_dbUser = (ListTables -> Maybe Text)
-> (ListTables -> Maybe Text -> ListTables)
-> Lens ListTables ListTables (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTables' {Maybe Text
dbUser :: Maybe Text
$sel:dbUser:ListTables' :: ListTables -> Maybe Text
dbUser} -> Maybe Text
dbUser) (\s :: ListTables
s@ListTables' {} Maybe Text
a -> ListTables
s {$sel:dbUser:ListTables' :: Maybe Text
dbUser = Maybe Text
a} :: ListTables)

-- | A database name. The connected database is specified when you connect
-- with your authentication credentials.
listTables_connectedDatabase :: Lens.Lens' ListTables (Prelude.Maybe Prelude.Text)
listTables_connectedDatabase :: (Maybe Text -> f (Maybe Text)) -> ListTables -> f ListTables
listTables_connectedDatabase = (ListTables -> Maybe Text)
-> (ListTables -> Maybe Text -> ListTables)
-> Lens ListTables ListTables (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTables' {Maybe Text
connectedDatabase :: Maybe Text
$sel:connectedDatabase:ListTables' :: ListTables -> Maybe Text
connectedDatabase} -> Maybe Text
connectedDatabase) (\s :: ListTables
s@ListTables' {} Maybe Text
a -> ListTables
s {$sel:connectedDatabase:ListTables' :: Maybe Text
connectedDatabase = Maybe Text
a} :: ListTables)

-- | A value that indicates the starting point for the next set of response
-- records in a subsequent request. If a value is returned in a response,
-- you can retrieve the next set of records by providing this returned
-- NextToken value in the next NextToken parameter and retrying the
-- command. If the NextToken field is empty, all response records have been
-- retrieved for the request.
listTables_nextToken :: Lens.Lens' ListTables (Prelude.Maybe Prelude.Text)
listTables_nextToken :: (Maybe Text -> f (Maybe Text)) -> ListTables -> f ListTables
listTables_nextToken = (ListTables -> Maybe Text)
-> (ListTables -> Maybe Text -> ListTables)
-> Lens ListTables ListTables (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTables' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListTables' :: ListTables -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListTables
s@ListTables' {} Maybe Text
a -> ListTables
s {$sel:nextToken:ListTables' :: Maybe Text
nextToken = Maybe Text
a} :: ListTables)

-- | The name or ARN of the secret that enables access to the database. This
-- parameter is required when authenticating using Secrets Manager.
listTables_secretArn :: Lens.Lens' ListTables (Prelude.Maybe Prelude.Text)
listTables_secretArn :: (Maybe Text -> f (Maybe Text)) -> ListTables -> f ListTables
listTables_secretArn = (ListTables -> Maybe Text)
-> (ListTables -> Maybe Text -> ListTables)
-> Lens ListTables ListTables (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTables' {Maybe Text
secretArn :: Maybe Text
$sel:secretArn:ListTables' :: ListTables -> Maybe Text
secretArn} -> Maybe Text
secretArn) (\s :: ListTables
s@ListTables' {} Maybe Text
a -> ListTables
s {$sel:secretArn:ListTables' :: Maybe Text
secretArn = Maybe Text
a} :: ListTables)

-- | A pattern to filter results by table name. Within a table pattern, \"%\"
-- means match any substring of 0 or more characters and \"_\" means match
-- any one character. Only table name entries matching the search pattern
-- are returned. If @TablePattern@ is not specified, then all tables that
-- match @SchemaPattern@are returned. If neither @SchemaPattern@ or
-- @TablePattern@ are specified, then all tables are returned.
listTables_tablePattern :: Lens.Lens' ListTables (Prelude.Maybe Prelude.Text)
listTables_tablePattern :: (Maybe Text -> f (Maybe Text)) -> ListTables -> f ListTables
listTables_tablePattern = (ListTables -> Maybe Text)
-> (ListTables -> Maybe Text -> ListTables)
-> Lens ListTables ListTables (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTables' {Maybe Text
tablePattern :: Maybe Text
$sel:tablePattern:ListTables' :: ListTables -> Maybe Text
tablePattern} -> Maybe Text
tablePattern) (\s :: ListTables
s@ListTables' {} Maybe Text
a -> ListTables
s {$sel:tablePattern:ListTables' :: Maybe Text
tablePattern = Maybe Text
a} :: ListTables)

-- | The maximum number of tables to return in the response. If more tables
-- exist than fit in one response, then @NextToken@ is returned to page
-- through the results.
listTables_maxResults :: Lens.Lens' ListTables (Prelude.Maybe Prelude.Natural)
listTables_maxResults :: (Maybe Natural -> f (Maybe Natural)) -> ListTables -> f ListTables
listTables_maxResults = (ListTables -> Maybe Natural)
-> (ListTables -> Maybe Natural -> ListTables)
-> Lens ListTables ListTables (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTables' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListTables' :: ListTables -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListTables
s@ListTables' {} Maybe Natural
a -> ListTables
s {$sel:maxResults:ListTables' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListTables)

-- | A pattern to filter results by schema name. Within a schema pattern,
-- \"%\" means match any substring of 0 or more characters and \"_\" means
-- match any one character. Only schema name entries matching the search
-- pattern are returned. If @SchemaPattern@ is not specified, then all
-- tables that match @TablePattern@ are returned. If neither
-- @SchemaPattern@ or @TablePattern@ are specified, then all tables are
-- returned.
listTables_schemaPattern :: Lens.Lens' ListTables (Prelude.Maybe Prelude.Text)
listTables_schemaPattern :: (Maybe Text -> f (Maybe Text)) -> ListTables -> f ListTables
listTables_schemaPattern = (ListTables -> Maybe Text)
-> (ListTables -> Maybe Text -> ListTables)
-> Lens ListTables ListTables (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTables' {Maybe Text
schemaPattern :: Maybe Text
$sel:schemaPattern:ListTables' :: ListTables -> Maybe Text
schemaPattern} -> Maybe Text
schemaPattern) (\s :: ListTables
s@ListTables' {} Maybe Text
a -> ListTables
s {$sel:schemaPattern:ListTables' :: Maybe Text
schemaPattern = Maybe Text
a} :: ListTables)

-- | The cluster identifier. This parameter is required when authenticating
-- using either Secrets Manager or temporary credentials.
listTables_clusterIdentifier :: Lens.Lens' ListTables Prelude.Text
listTables_clusterIdentifier :: (Text -> f Text) -> ListTables -> f ListTables
listTables_clusterIdentifier = (ListTables -> Text)
-> (ListTables -> Text -> ListTables)
-> Lens ListTables ListTables Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTables' {Text
clusterIdentifier :: Text
$sel:clusterIdentifier:ListTables' :: ListTables -> Text
clusterIdentifier} -> Text
clusterIdentifier) (\s :: ListTables
s@ListTables' {} Text
a -> ListTables
s {$sel:clusterIdentifier:ListTables' :: Text
clusterIdentifier = Text
a} :: ListTables)

-- | The name of the database that contains the tables to list. If
-- @ConnectedDatabase@ is not specified, this is also the database to
-- connect to with your authentication credentials.
listTables_database :: Lens.Lens' ListTables Prelude.Text
listTables_database :: (Text -> f Text) -> ListTables -> f ListTables
listTables_database = (ListTables -> Text)
-> (ListTables -> Text -> ListTables)
-> Lens ListTables ListTables Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTables' {Text
database :: Text
$sel:database:ListTables' :: ListTables -> Text
database} -> Text
database) (\s :: ListTables
s@ListTables' {} Text
a -> ListTables
s {$sel:database:ListTables' :: Text
database = Text
a} :: ListTables)

instance Core.AWSPager ListTables where
  page :: ListTables -> AWSResponse ListTables -> Maybe ListTables
page ListTables
rq AWSResponse ListTables
rs
    | Maybe Text -> Bool
forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListTables
ListTablesResponse
rs
            ListTablesResponse
-> Getting (First Text) ListTablesResponse Text -> Maybe Text
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe Text -> Const (First Text) (Maybe Text))
-> ListTablesResponse -> Const (First Text) ListTablesResponse
Lens' ListTablesResponse (Maybe Text)
listTablesResponse_nextToken ((Maybe Text -> Const (First Text) (Maybe Text))
 -> ListTablesResponse -> Const (First Text) ListTablesResponse)
-> ((Text -> Const (First Text) Text)
    -> Maybe Text -> Const (First Text) (Maybe Text))
-> Getting (First Text) ListTablesResponse Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> Const (First Text) Text)
-> Maybe Text -> Const (First Text) (Maybe Text)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
      Maybe ListTables
forall a. Maybe a
Prelude.Nothing
    | Maybe [TableMember] -> Bool
forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListTables
ListTablesResponse
rs
            ListTablesResponse
-> Getting (First [TableMember]) ListTablesResponse [TableMember]
-> Maybe [TableMember]
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe [TableMember]
 -> Const (First [TableMember]) (Maybe [TableMember]))
-> ListTablesResponse
-> Const (First [TableMember]) ListTablesResponse
Lens' ListTablesResponse (Maybe [TableMember])
listTablesResponse_tables ((Maybe [TableMember]
  -> Const (First [TableMember]) (Maybe [TableMember]))
 -> ListTablesResponse
 -> Const (First [TableMember]) ListTablesResponse)
-> (([TableMember] -> Const (First [TableMember]) [TableMember])
    -> Maybe [TableMember]
    -> Const (First [TableMember]) (Maybe [TableMember]))
-> Getting (First [TableMember]) ListTablesResponse [TableMember]
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([TableMember] -> Const (First [TableMember]) [TableMember])
-> Maybe [TableMember]
-> Const (First [TableMember]) (Maybe [TableMember])
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
      Maybe ListTables
forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
      ListTables -> Maybe ListTables
forall a. a -> Maybe a
Prelude.Just (ListTables -> Maybe ListTables) -> ListTables -> Maybe ListTables
forall a b. (a -> b) -> a -> b
Prelude.$
        ListTables
rq
          ListTables -> (ListTables -> ListTables) -> ListTables
forall a b. a -> (a -> b) -> b
Prelude.& (Maybe Text -> Identity (Maybe Text))
-> ListTables -> Identity ListTables
Lens ListTables ListTables (Maybe Text) (Maybe Text)
listTables_nextToken
          ((Maybe Text -> Identity (Maybe Text))
 -> ListTables -> Identity ListTables)
-> Maybe Text -> ListTables -> ListTables
forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListTables
ListTablesResponse
rs
          ListTablesResponse
-> Getting (First Text) ListTablesResponse Text -> Maybe Text
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe Text -> Const (First Text) (Maybe Text))
-> ListTablesResponse -> Const (First Text) ListTablesResponse
Lens' ListTablesResponse (Maybe Text)
listTablesResponse_nextToken ((Maybe Text -> Const (First Text) (Maybe Text))
 -> ListTablesResponse -> Const (First Text) ListTablesResponse)
-> ((Text -> Const (First Text) Text)
    -> Maybe Text -> Const (First Text) (Maybe Text))
-> Getting (First Text) ListTablesResponse Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> Const (First Text) Text)
-> Maybe Text -> Const (First Text) (Maybe Text)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest ListTables where
  type AWSResponse ListTables = ListTablesResponse
  request :: ListTables -> Request ListTables
request = Service -> ListTables -> Request ListTables
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ListTables
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListTables)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ListTables))
-> Logger
-> Service
-> Proxy ListTables
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListTables)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Maybe [TableMember] -> Int -> ListTablesResponse
ListTablesResponse'
            (Maybe Text -> Maybe [TableMember] -> Int -> ListTablesResponse)
-> Either String (Maybe Text)
-> Either String (Maybe [TableMember] -> Int -> ListTablesResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"NextToken")
            Either String (Maybe [TableMember] -> Int -> ListTablesResponse)
-> Either String (Maybe [TableMember])
-> Either String (Int -> ListTablesResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe (Maybe [TableMember]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Tables" Either String (Maybe (Maybe [TableMember]))
-> Maybe [TableMember] -> Either String (Maybe [TableMember])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [TableMember]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> ListTablesResponse)
-> Either String Int -> Either String ListTablesResponse
forall (f :: * -> *) a b. Applicative f => 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 ListTables

instance Prelude.NFData ListTables

instance Core.ToHeaders ListTables where
  toHeaders :: ListTables -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ListTables -> 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
"RedshiftData.ListTables" :: 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 ListTables where
  toJSON :: ListTables -> Value
toJSON ListTables' {Maybe Natural
Maybe Text
Text
database :: Text
clusterIdentifier :: Text
schemaPattern :: Maybe Text
maxResults :: Maybe Natural
tablePattern :: Maybe Text
secretArn :: Maybe Text
nextToken :: Maybe Text
connectedDatabase :: Maybe Text
dbUser :: Maybe Text
$sel:database:ListTables' :: ListTables -> Text
$sel:clusterIdentifier:ListTables' :: ListTables -> Text
$sel:schemaPattern:ListTables' :: ListTables -> Maybe Text
$sel:maxResults:ListTables' :: ListTables -> Maybe Natural
$sel:tablePattern:ListTables' :: ListTables -> Maybe Text
$sel:secretArn:ListTables' :: ListTables -> Maybe Text
$sel:nextToken:ListTables' :: ListTables -> Maybe Text
$sel:connectedDatabase:ListTables' :: ListTables -> Maybe Text
$sel:dbUser:ListTables' :: ListTables -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"DbUser" 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
dbUser,
            (Text
"ConnectedDatabase" 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
connectedDatabase,
            (Text
"NextToken" 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
nextToken,
            (Text
"SecretArn" 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
secretArn,
            (Text
"TablePattern" 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
tablePattern,
            (Text
"MaxResults" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxResults,
            (Text
"SchemaPattern" 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
schemaPattern,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ClusterIdentifier" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clusterIdentifier),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Database" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
database)
          ]
      )

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

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

-- | /See:/ 'newListTablesResponse' smart constructor.
data ListTablesResponse = ListTablesResponse'
  { -- | A value that indicates the starting point for the next set of response
    -- records in a subsequent request. If a value is returned in a response,
    -- you can retrieve the next set of records by providing this returned
    -- NextToken value in the next NextToken parameter and retrying the
    -- command. If the NextToken field is empty, all response records have been
    -- retrieved for the request.
    ListTablesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The tables that match the request pattern.
    ListTablesResponse -> Maybe [TableMember]
tables :: Prelude.Maybe [TableMember],
    -- | The response's http status code.
    ListTablesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListTablesResponse -> ListTablesResponse -> Bool
(ListTablesResponse -> ListTablesResponse -> Bool)
-> (ListTablesResponse -> ListTablesResponse -> Bool)
-> Eq ListTablesResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListTablesResponse -> ListTablesResponse -> Bool
$c/= :: ListTablesResponse -> ListTablesResponse -> Bool
== :: ListTablesResponse -> ListTablesResponse -> Bool
$c== :: ListTablesResponse -> ListTablesResponse -> Bool
Prelude.Eq, ReadPrec [ListTablesResponse]
ReadPrec ListTablesResponse
Int -> ReadS ListTablesResponse
ReadS [ListTablesResponse]
(Int -> ReadS ListTablesResponse)
-> ReadS [ListTablesResponse]
-> ReadPrec ListTablesResponse
-> ReadPrec [ListTablesResponse]
-> Read ListTablesResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListTablesResponse]
$creadListPrec :: ReadPrec [ListTablesResponse]
readPrec :: ReadPrec ListTablesResponse
$creadPrec :: ReadPrec ListTablesResponse
readList :: ReadS [ListTablesResponse]
$creadList :: ReadS [ListTablesResponse]
readsPrec :: Int -> ReadS ListTablesResponse
$creadsPrec :: Int -> ReadS ListTablesResponse
Prelude.Read, Int -> ListTablesResponse -> ShowS
[ListTablesResponse] -> ShowS
ListTablesResponse -> String
(Int -> ListTablesResponse -> ShowS)
-> (ListTablesResponse -> String)
-> ([ListTablesResponse] -> ShowS)
-> Show ListTablesResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListTablesResponse] -> ShowS
$cshowList :: [ListTablesResponse] -> ShowS
show :: ListTablesResponse -> String
$cshow :: ListTablesResponse -> String
showsPrec :: Int -> ListTablesResponse -> ShowS
$cshowsPrec :: Int -> ListTablesResponse -> ShowS
Prelude.Show, (forall x. ListTablesResponse -> Rep ListTablesResponse x)
-> (forall x. Rep ListTablesResponse x -> ListTablesResponse)
-> Generic ListTablesResponse
forall x. Rep ListTablesResponse x -> ListTablesResponse
forall x. ListTablesResponse -> Rep ListTablesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListTablesResponse x -> ListTablesResponse
$cfrom :: forall x. ListTablesResponse -> Rep ListTablesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListTablesResponse' 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:
--
-- 'nextToken', 'listTablesResponse_nextToken' - A value that indicates the starting point for the next set of response
-- records in a subsequent request. If a value is returned in a response,
-- you can retrieve the next set of records by providing this returned
-- NextToken value in the next NextToken parameter and retrying the
-- command. If the NextToken field is empty, all response records have been
-- retrieved for the request.
--
-- 'tables', 'listTablesResponse_tables' - The tables that match the request pattern.
--
-- 'httpStatus', 'listTablesResponse_httpStatus' - The response's http status code.
newListTablesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListTablesResponse
newListTablesResponse :: Int -> ListTablesResponse
newListTablesResponse Int
pHttpStatus_ =
  ListTablesResponse' :: Maybe Text -> Maybe [TableMember] -> Int -> ListTablesResponse
ListTablesResponse'
    { $sel:nextToken:ListTablesResponse' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tables:ListTablesResponse' :: Maybe [TableMember]
tables = Maybe [TableMember]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListTablesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A value that indicates the starting point for the next set of response
-- records in a subsequent request. If a value is returned in a response,
-- you can retrieve the next set of records by providing this returned
-- NextToken value in the next NextToken parameter and retrying the
-- command. If the NextToken field is empty, all response records have been
-- retrieved for the request.
listTablesResponse_nextToken :: Lens.Lens' ListTablesResponse (Prelude.Maybe Prelude.Text)
listTablesResponse_nextToken :: (Maybe Text -> f (Maybe Text))
-> ListTablesResponse -> f ListTablesResponse
listTablesResponse_nextToken = (ListTablesResponse -> Maybe Text)
-> (ListTablesResponse -> Maybe Text -> ListTablesResponse)
-> Lens' ListTablesResponse (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTablesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListTablesResponse' :: ListTablesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListTablesResponse
s@ListTablesResponse' {} Maybe Text
a -> ListTablesResponse
s {$sel:nextToken:ListTablesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListTablesResponse)

-- | The tables that match the request pattern.
listTablesResponse_tables :: Lens.Lens' ListTablesResponse (Prelude.Maybe [TableMember])
listTablesResponse_tables :: (Maybe [TableMember] -> f (Maybe [TableMember]))
-> ListTablesResponse -> f ListTablesResponse
listTablesResponse_tables = (ListTablesResponse -> Maybe [TableMember])
-> (ListTablesResponse
    -> Maybe [TableMember] -> ListTablesResponse)
-> Lens' ListTablesResponse (Maybe [TableMember])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTablesResponse' {Maybe [TableMember]
tables :: Maybe [TableMember]
$sel:tables:ListTablesResponse' :: ListTablesResponse -> Maybe [TableMember]
tables} -> Maybe [TableMember]
tables) (\s :: ListTablesResponse
s@ListTablesResponse' {} Maybe [TableMember]
a -> ListTablesResponse
s {$sel:tables:ListTablesResponse' :: Maybe [TableMember]
tables = Maybe [TableMember]
a} :: ListTablesResponse) ((Maybe [TableMember] -> f (Maybe [TableMember]))
 -> ListTablesResponse -> f ListTablesResponse)
-> ((Maybe [TableMember] -> f (Maybe [TableMember]))
    -> Maybe [TableMember] -> f (Maybe [TableMember]))
-> (Maybe [TableMember] -> f (Maybe [TableMember]))
-> ListTablesResponse
-> f ListTablesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [TableMember] [TableMember] [TableMember] [TableMember]
-> Iso
     (Maybe [TableMember])
     (Maybe [TableMember])
     (Maybe [TableMember])
     (Maybe [TableMember])
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 AnIso [TableMember] [TableMember] [TableMember] [TableMember]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData ListTablesResponse