{-# 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.MQ.ListBrokers
-- 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 all brokers.
--
-- This operation returns paginated results.
module Amazonka.MQ.ListBrokers
  ( -- * Creating a Request
    ListBrokers (..),
    newListBrokers,

    -- * Request Lenses
    listBrokers_maxResults,
    listBrokers_nextToken,

    -- * Destructuring the Response
    ListBrokersResponse (..),
    newListBrokersResponse,

    -- * Response Lenses
    listBrokersResponse_brokerSummaries,
    listBrokersResponse_nextToken,
    listBrokersResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListBrokers' smart constructor.
data ListBrokers = ListBrokers'
  { -- | The maximum number of brokers that Amazon MQ can return per page (20 by
    -- default). This value must be an integer from 5 to 100.
    ListBrokers -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The token that specifies the next page of results Amazon MQ should
    -- return. To request the first page, leave nextToken empty.
    ListBrokers -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListBrokers -> ListBrokers -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListBrokers -> ListBrokers -> Bool
$c/= :: ListBrokers -> ListBrokers -> Bool
== :: ListBrokers -> ListBrokers -> Bool
$c== :: ListBrokers -> ListBrokers -> Bool
Prelude.Eq, ReadPrec [ListBrokers]
ReadPrec ListBrokers
Int -> ReadS ListBrokers
ReadS [ListBrokers]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListBrokers]
$creadListPrec :: ReadPrec [ListBrokers]
readPrec :: ReadPrec ListBrokers
$creadPrec :: ReadPrec ListBrokers
readList :: ReadS [ListBrokers]
$creadList :: ReadS [ListBrokers]
readsPrec :: Int -> ReadS ListBrokers
$creadsPrec :: Int -> ReadS ListBrokers
Prelude.Read, Int -> ListBrokers -> ShowS
[ListBrokers] -> ShowS
ListBrokers -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListBrokers] -> ShowS
$cshowList :: [ListBrokers] -> ShowS
show :: ListBrokers -> String
$cshow :: ListBrokers -> String
showsPrec :: Int -> ListBrokers -> ShowS
$cshowsPrec :: Int -> ListBrokers -> ShowS
Prelude.Show, forall x. Rep ListBrokers x -> ListBrokers
forall x. ListBrokers -> Rep ListBrokers x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListBrokers x -> ListBrokers
$cfrom :: forall x. ListBrokers -> Rep ListBrokers x
Prelude.Generic)

-- |
-- Create a value of 'ListBrokers' 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', 'listBrokers_maxResults' - The maximum number of brokers that Amazon MQ can return per page (20 by
-- default). This value must be an integer from 5 to 100.
--
-- 'nextToken', 'listBrokers_nextToken' - The token that specifies the next page of results Amazon MQ should
-- return. To request the first page, leave nextToken empty.
newListBrokers ::
  ListBrokers
newListBrokers :: ListBrokers
newListBrokers =
  ListBrokers'
    { $sel:maxResults:ListBrokers' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListBrokers' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of brokers that Amazon MQ can return per page (20 by
-- default). This value must be an integer from 5 to 100.
listBrokers_maxResults :: Lens.Lens' ListBrokers (Prelude.Maybe Prelude.Natural)
listBrokers_maxResults :: Lens' ListBrokers (Maybe Natural)
listBrokers_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListBrokers' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListBrokers' :: ListBrokers -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListBrokers
s@ListBrokers' {} Maybe Natural
a -> ListBrokers
s {$sel:maxResults:ListBrokers' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListBrokers)

-- | The token that specifies the next page of results Amazon MQ should
-- return. To request the first page, leave nextToken empty.
listBrokers_nextToken :: Lens.Lens' ListBrokers (Prelude.Maybe Prelude.Text)
listBrokers_nextToken :: Lens' ListBrokers (Maybe Text)
listBrokers_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListBrokers' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListBrokers' :: ListBrokers -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListBrokers
s@ListBrokers' {} Maybe Text
a -> ListBrokers
s {$sel:nextToken:ListBrokers' :: Maybe Text
nextToken = Maybe Text
a} :: ListBrokers)

instance Core.AWSPager ListBrokers where
  page :: ListBrokers -> AWSResponse ListBrokers -> Maybe ListBrokers
page ListBrokers
rq AWSResponse ListBrokers
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListBrokers
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListBrokersResponse (Maybe Text)
listBrokersResponse_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 ListBrokers
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListBrokersResponse (Maybe [BrokerSummary])
listBrokersResponse_brokerSummaries
            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
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListBrokers
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListBrokers (Maybe Text)
listBrokers_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListBrokers
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListBrokersResponse (Maybe Text)
listBrokersResponse_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 ListBrokers where
  type AWSResponse ListBrokers = ListBrokersResponse
  request :: (Service -> Service) -> ListBrokers -> Request ListBrokers
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ListBrokers
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListBrokers)))
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 [BrokerSummary] -> Maybe Text -> Int -> ListBrokersResponse
ListBrokersResponse'
            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
"brokerSummaries"
                            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 ListBrokers where
  hashWithSalt :: Int -> ListBrokers -> Int
hashWithSalt Int
_salt ListBrokers' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListBrokers' :: ListBrokers -> Maybe Text
$sel:maxResults:ListBrokers' :: ListBrokers -> 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 ListBrokers where
  rnf :: ListBrokers -> ()
rnf ListBrokers' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListBrokers' :: ListBrokers -> Maybe Text
$sel:maxResults:ListBrokers' :: ListBrokers -> 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 ListBrokers where
  toHeaders :: ListBrokers -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

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

instance Data.ToQuery ListBrokers where
  toQuery :: ListBrokers -> QueryString
toQuery ListBrokers' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListBrokers' :: ListBrokers -> Maybe Text
$sel:maxResults:ListBrokers' :: ListBrokers -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"maxResults" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Natural
maxResults,
        ByteString
"nextToken" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
nextToken
      ]

-- | /See:/ 'newListBrokersResponse' smart constructor.
data ListBrokersResponse = ListBrokersResponse'
  { -- | A list of information about all brokers.
    ListBrokersResponse -> Maybe [BrokerSummary]
brokerSummaries :: Prelude.Maybe [BrokerSummary],
    -- | The token that specifies the next page of results Amazon MQ should
    -- return. To request the first page, leave nextToken empty.
    ListBrokersResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListBrokersResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListBrokersResponse -> ListBrokersResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListBrokersResponse -> ListBrokersResponse -> Bool
$c/= :: ListBrokersResponse -> ListBrokersResponse -> Bool
== :: ListBrokersResponse -> ListBrokersResponse -> Bool
$c== :: ListBrokersResponse -> ListBrokersResponse -> Bool
Prelude.Eq, ReadPrec [ListBrokersResponse]
ReadPrec ListBrokersResponse
Int -> ReadS ListBrokersResponse
ReadS [ListBrokersResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListBrokersResponse]
$creadListPrec :: ReadPrec [ListBrokersResponse]
readPrec :: ReadPrec ListBrokersResponse
$creadPrec :: ReadPrec ListBrokersResponse
readList :: ReadS [ListBrokersResponse]
$creadList :: ReadS [ListBrokersResponse]
readsPrec :: Int -> ReadS ListBrokersResponse
$creadsPrec :: Int -> ReadS ListBrokersResponse
Prelude.Read, Int -> ListBrokersResponse -> ShowS
[ListBrokersResponse] -> ShowS
ListBrokersResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListBrokersResponse] -> ShowS
$cshowList :: [ListBrokersResponse] -> ShowS
show :: ListBrokersResponse -> String
$cshow :: ListBrokersResponse -> String
showsPrec :: Int -> ListBrokersResponse -> ShowS
$cshowsPrec :: Int -> ListBrokersResponse -> ShowS
Prelude.Show, forall x. Rep ListBrokersResponse x -> ListBrokersResponse
forall x. ListBrokersResponse -> Rep ListBrokersResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListBrokersResponse x -> ListBrokersResponse
$cfrom :: forall x. ListBrokersResponse -> Rep ListBrokersResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListBrokersResponse' 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:
--
-- 'brokerSummaries', 'listBrokersResponse_brokerSummaries' - A list of information about all brokers.
--
-- 'nextToken', 'listBrokersResponse_nextToken' - The token that specifies the next page of results Amazon MQ should
-- return. To request the first page, leave nextToken empty.
--
-- 'httpStatus', 'listBrokersResponse_httpStatus' - The response's http status code.
newListBrokersResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListBrokersResponse
newListBrokersResponse :: Int -> ListBrokersResponse
newListBrokersResponse Int
pHttpStatus_ =
  ListBrokersResponse'
    { $sel:brokerSummaries:ListBrokersResponse' :: Maybe [BrokerSummary]
brokerSummaries =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListBrokersResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListBrokersResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of information about all brokers.
listBrokersResponse_brokerSummaries :: Lens.Lens' ListBrokersResponse (Prelude.Maybe [BrokerSummary])
listBrokersResponse_brokerSummaries :: Lens' ListBrokersResponse (Maybe [BrokerSummary])
listBrokersResponse_brokerSummaries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListBrokersResponse' {Maybe [BrokerSummary]
brokerSummaries :: Maybe [BrokerSummary]
$sel:brokerSummaries:ListBrokersResponse' :: ListBrokersResponse -> Maybe [BrokerSummary]
brokerSummaries} -> Maybe [BrokerSummary]
brokerSummaries) (\s :: ListBrokersResponse
s@ListBrokersResponse' {} Maybe [BrokerSummary]
a -> ListBrokersResponse
s {$sel:brokerSummaries:ListBrokersResponse' :: Maybe [BrokerSummary]
brokerSummaries = Maybe [BrokerSummary]
a} :: ListBrokersResponse) 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 token that specifies the next page of results Amazon MQ should
-- return. To request the first page, leave nextToken empty.
listBrokersResponse_nextToken :: Lens.Lens' ListBrokersResponse (Prelude.Maybe Prelude.Text)
listBrokersResponse_nextToken :: Lens' ListBrokersResponse (Maybe Text)
listBrokersResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListBrokersResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListBrokersResponse' :: ListBrokersResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListBrokersResponse
s@ListBrokersResponse' {} Maybe Text
a -> ListBrokersResponse
s {$sel:nextToken:ListBrokersResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListBrokersResponse)

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

instance Prelude.NFData ListBrokersResponse where
  rnf :: ListBrokersResponse -> ()
rnf ListBrokersResponse' {Int
Maybe [BrokerSummary]
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
brokerSummaries :: Maybe [BrokerSummary]
$sel:httpStatus:ListBrokersResponse' :: ListBrokersResponse -> Int
$sel:nextToken:ListBrokersResponse' :: ListBrokersResponse -> Maybe Text
$sel:brokerSummaries:ListBrokersResponse' :: ListBrokersResponse -> Maybe [BrokerSummary]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [BrokerSummary]
brokerSummaries
      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