{-# 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.RedshiftServerLess.ListNamespaces
-- 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 a list of specified namespaces.
--
-- This operation returns paginated results.
module Amazonka.RedshiftServerLess.ListNamespaces
  ( -- * Creating a Request
    ListNamespaces (..),
    newListNamespaces,

    -- * Request Lenses
    listNamespaces_maxResults,
    listNamespaces_nextToken,

    -- * Destructuring the Response
    ListNamespacesResponse (..),
    newListNamespacesResponse,

    -- * Response Lenses
    listNamespacesResponse_nextToken,
    listNamespacesResponse_httpStatus,
    listNamespacesResponse_namespaces,
  )
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 Amazonka.RedshiftServerLess.Types
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newListNamespaces' smart constructor.
data ListNamespaces = ListNamespaces'
  { -- | An optional parameter that specifies the maximum number of results to
    -- return. You can use @nextToken@ to display the next page of results.
    ListNamespaces -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | If your initial @ListNamespaces@ operation returns a @nextToken@, you
    -- can include the returned @nextToken@ in following @ListNamespaces@
    -- operations, which returns results in the next page.
    ListNamespaces -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListNamespaces -> ListNamespaces -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListNamespaces -> ListNamespaces -> Bool
$c/= :: ListNamespaces -> ListNamespaces -> Bool
== :: ListNamespaces -> ListNamespaces -> Bool
$c== :: ListNamespaces -> ListNamespaces -> Bool
Prelude.Eq, ReadPrec [ListNamespaces]
ReadPrec ListNamespaces
Int -> ReadS ListNamespaces
ReadS [ListNamespaces]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListNamespaces]
$creadListPrec :: ReadPrec [ListNamespaces]
readPrec :: ReadPrec ListNamespaces
$creadPrec :: ReadPrec ListNamespaces
readList :: ReadS [ListNamespaces]
$creadList :: ReadS [ListNamespaces]
readsPrec :: Int -> ReadS ListNamespaces
$creadsPrec :: Int -> ReadS ListNamespaces
Prelude.Read, Int -> ListNamespaces -> ShowS
[ListNamespaces] -> ShowS
ListNamespaces -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListNamespaces] -> ShowS
$cshowList :: [ListNamespaces] -> ShowS
show :: ListNamespaces -> String
$cshow :: ListNamespaces -> String
showsPrec :: Int -> ListNamespaces -> ShowS
$cshowsPrec :: Int -> ListNamespaces -> ShowS
Prelude.Show, forall x. Rep ListNamespaces x -> ListNamespaces
forall x. ListNamespaces -> Rep ListNamespaces x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListNamespaces x -> ListNamespaces
$cfrom :: forall x. ListNamespaces -> Rep ListNamespaces x
Prelude.Generic)

-- |
-- Create a value of 'ListNamespaces' 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', 'listNamespaces_maxResults' - An optional parameter that specifies the maximum number of results to
-- return. You can use @nextToken@ to display the next page of results.
--
-- 'nextToken', 'listNamespaces_nextToken' - If your initial @ListNamespaces@ operation returns a @nextToken@, you
-- can include the returned @nextToken@ in following @ListNamespaces@
-- operations, which returns results in the next page.
newListNamespaces ::
  ListNamespaces
newListNamespaces :: ListNamespaces
newListNamespaces =
  ListNamespaces'
    { $sel:maxResults:ListNamespaces' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListNamespaces' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | An optional parameter that specifies the maximum number of results to
-- return. You can use @nextToken@ to display the next page of results.
listNamespaces_maxResults :: Lens.Lens' ListNamespaces (Prelude.Maybe Prelude.Natural)
listNamespaces_maxResults :: Lens' ListNamespaces (Maybe Natural)
listNamespaces_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListNamespaces' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListNamespaces' :: ListNamespaces -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListNamespaces
s@ListNamespaces' {} Maybe Natural
a -> ListNamespaces
s {$sel:maxResults:ListNamespaces' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListNamespaces)

-- | If your initial @ListNamespaces@ operation returns a @nextToken@, you
-- can include the returned @nextToken@ in following @ListNamespaces@
-- operations, which returns results in the next page.
listNamespaces_nextToken :: Lens.Lens' ListNamespaces (Prelude.Maybe Prelude.Text)
listNamespaces_nextToken :: Lens' ListNamespaces (Maybe Text)
listNamespaces_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListNamespaces' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListNamespaces' :: ListNamespaces -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListNamespaces
s@ListNamespaces' {} Maybe Text
a -> ListNamespaces
s {$sel:nextToken:ListNamespaces' :: Maybe Text
nextToken = Maybe Text
a} :: ListNamespaces)

instance Core.AWSPager ListNamespaces where
  page :: ListNamespaces
-> AWSResponse ListNamespaces -> Maybe ListNamespaces
page ListNamespaces
rq AWSResponse ListNamespaces
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListNamespaces
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListNamespacesResponse (Maybe Text)
listNamespacesResponse_nextToken
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        (AWSResponse ListNamespaces
rs forall s a. s -> Getting a s a -> a
Lens.^. Lens' ListNamespacesResponse [Namespace]
listNamespacesResponse_namespaces) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListNamespaces
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListNamespaces (Maybe Text)
listNamespaces_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListNamespaces
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListNamespacesResponse (Maybe Text)
listNamespacesResponse_nextToken
          forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest ListNamespaces where
  type
    AWSResponse ListNamespaces =
      ListNamespacesResponse
  request :: (Service -> Service) -> ListNamespaces -> Request ListNamespaces
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 ListNamespaces
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListNamespaces)))
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 Text -> Int -> [Namespace] -> ListNamespacesResponse
ListNamespacesResponse'
            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
"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))
            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
"namespaces" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable ListNamespaces where
  hashWithSalt :: Int -> ListNamespaces -> Int
hashWithSalt Int
_salt ListNamespaces' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListNamespaces' :: ListNamespaces -> Maybe Text
$sel:maxResults:ListNamespaces' :: ListNamespaces -> 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 ListNamespaces where
  rnf :: ListNamespaces -> ()
rnf ListNamespaces' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListNamespaces' :: ListNamespaces -> Maybe Text
$sel:maxResults:ListNamespaces' :: ListNamespaces -> 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 ListNamespaces where
  toHeaders :: ListNamespaces -> 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
"RedshiftServerless.ListNamespaces" ::
                          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 ListNamespaces where
  toJSON :: ListNamespaces -> Value
toJSON ListNamespaces' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListNamespaces' :: ListNamespaces -> Maybe Text
$sel:maxResults:ListNamespaces' :: ListNamespaces -> 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 ListNamespaces where
  toPath :: ListNamespaces -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newListNamespacesResponse' smart constructor.
data ListNamespacesResponse = ListNamespacesResponse'
  { -- | When @nextToken@ is returned, there are more results available. The
    -- value of @nextToken@ is a unique pagination token for each page. Make
    -- the call again using the returned token to retrieve the next page.
    ListNamespacesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListNamespacesResponse -> Int
httpStatus :: Prelude.Int,
    -- | The list of returned namespaces.
    ListNamespacesResponse -> [Namespace]
namespaces :: [Namespace]
  }
  deriving (ListNamespacesResponse -> ListNamespacesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListNamespacesResponse -> ListNamespacesResponse -> Bool
$c/= :: ListNamespacesResponse -> ListNamespacesResponse -> Bool
== :: ListNamespacesResponse -> ListNamespacesResponse -> Bool
$c== :: ListNamespacesResponse -> ListNamespacesResponse -> Bool
Prelude.Eq, Int -> ListNamespacesResponse -> ShowS
[ListNamespacesResponse] -> ShowS
ListNamespacesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListNamespacesResponse] -> ShowS
$cshowList :: [ListNamespacesResponse] -> ShowS
show :: ListNamespacesResponse -> String
$cshow :: ListNamespacesResponse -> String
showsPrec :: Int -> ListNamespacesResponse -> ShowS
$cshowsPrec :: Int -> ListNamespacesResponse -> ShowS
Prelude.Show, forall x. Rep ListNamespacesResponse x -> ListNamespacesResponse
forall x. ListNamespacesResponse -> Rep ListNamespacesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListNamespacesResponse x -> ListNamespacesResponse
$cfrom :: forall x. ListNamespacesResponse -> Rep ListNamespacesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListNamespacesResponse' 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', 'listNamespacesResponse_nextToken' - When @nextToken@ is returned, there are more results available. The
-- value of @nextToken@ is a unique pagination token for each page. Make
-- the call again using the returned token to retrieve the next page.
--
-- 'httpStatus', 'listNamespacesResponse_httpStatus' - The response's http status code.
--
-- 'namespaces', 'listNamespacesResponse_namespaces' - The list of returned namespaces.
newListNamespacesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListNamespacesResponse
newListNamespacesResponse :: Int -> ListNamespacesResponse
newListNamespacesResponse Int
pHttpStatus_ =
  ListNamespacesResponse'
    { $sel:nextToken:ListNamespacesResponse' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListNamespacesResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:namespaces:ListNamespacesResponse' :: [Namespace]
namespaces = forall a. Monoid a => a
Prelude.mempty
    }

-- | When @nextToken@ is returned, there are more results available. The
-- value of @nextToken@ is a unique pagination token for each page. Make
-- the call again using the returned token to retrieve the next page.
listNamespacesResponse_nextToken :: Lens.Lens' ListNamespacesResponse (Prelude.Maybe Prelude.Text)
listNamespacesResponse_nextToken :: Lens' ListNamespacesResponse (Maybe Text)
listNamespacesResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListNamespacesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListNamespacesResponse' :: ListNamespacesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListNamespacesResponse
s@ListNamespacesResponse' {} Maybe Text
a -> ListNamespacesResponse
s {$sel:nextToken:ListNamespacesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListNamespacesResponse)

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

-- | The list of returned namespaces.
listNamespacesResponse_namespaces :: Lens.Lens' ListNamespacesResponse [Namespace]
listNamespacesResponse_namespaces :: Lens' ListNamespacesResponse [Namespace]
listNamespacesResponse_namespaces = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListNamespacesResponse' {[Namespace]
namespaces :: [Namespace]
$sel:namespaces:ListNamespacesResponse' :: ListNamespacesResponse -> [Namespace]
namespaces} -> [Namespace]
namespaces) (\s :: ListNamespacesResponse
s@ListNamespacesResponse' {} [Namespace]
a -> ListNamespacesResponse
s {$sel:namespaces:ListNamespacesResponse' :: [Namespace]
namespaces = [Namespace]
a} :: ListNamespacesResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData ListNamespacesResponse where
  rnf :: ListNamespacesResponse -> ()
rnf ListNamespacesResponse' {Int
[Namespace]
Maybe Text
namespaces :: [Namespace]
httpStatus :: Int
nextToken :: Maybe Text
$sel:namespaces:ListNamespacesResponse' :: ListNamespacesResponse -> [Namespace]
$sel:httpStatus:ListNamespacesResponse' :: ListNamespacesResponse -> Int
$sel:nextToken:ListNamespacesResponse' :: ListNamespacesResponse -> Maybe Text
..} =
    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
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Namespace]
namespaces