{-# 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.IoT.ListStreams
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Lists all of the streams in your Amazon Web Services account.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions ListStreams>
-- action.
--
-- This operation returns paginated results.
module Amazonka.IoT.ListStreams
  ( -- * Creating a Request
    ListStreams (..),
    newListStreams,

    -- * Request Lenses
    listStreams_ascendingOrder,
    listStreams_maxResults,
    listStreams_nextToken,

    -- * Destructuring the Response
    ListStreamsResponse (..),
    newListStreamsResponse,

    -- * Response Lenses
    listStreamsResponse_nextToken,
    listStreamsResponse_streams,
    listStreamsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListStreams' smart constructor.
data ListStreams = ListStreams'
  { -- | Set to true to return the list of streams in ascending order.
    ListStreams -> Maybe Bool
ascendingOrder :: Prelude.Maybe Prelude.Bool,
    -- | The maximum number of results to return at a time.
    ListStreams -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | A token used to get the next set of results.
    ListStreams -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListStreams -> ListStreams -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListStreams -> ListStreams -> Bool
$c/= :: ListStreams -> ListStreams -> Bool
== :: ListStreams -> ListStreams -> Bool
$c== :: ListStreams -> ListStreams -> Bool
Prelude.Eq, ReadPrec [ListStreams]
ReadPrec ListStreams
Int -> ReadS ListStreams
ReadS [ListStreams]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListStreams]
$creadListPrec :: ReadPrec [ListStreams]
readPrec :: ReadPrec ListStreams
$creadPrec :: ReadPrec ListStreams
readList :: ReadS [ListStreams]
$creadList :: ReadS [ListStreams]
readsPrec :: Int -> ReadS ListStreams
$creadsPrec :: Int -> ReadS ListStreams
Prelude.Read, Int -> ListStreams -> ShowS
[ListStreams] -> ShowS
ListStreams -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListStreams] -> ShowS
$cshowList :: [ListStreams] -> ShowS
show :: ListStreams -> String
$cshow :: ListStreams -> String
showsPrec :: Int -> ListStreams -> ShowS
$cshowsPrec :: Int -> ListStreams -> ShowS
Prelude.Show, forall x. Rep ListStreams x -> ListStreams
forall x. ListStreams -> Rep ListStreams x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListStreams x -> ListStreams
$cfrom :: forall x. ListStreams -> Rep ListStreams x
Prelude.Generic)

-- |
-- Create a value of 'ListStreams' 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:
--
-- 'ascendingOrder', 'listStreams_ascendingOrder' - Set to true to return the list of streams in ascending order.
--
-- 'maxResults', 'listStreams_maxResults' - The maximum number of results to return at a time.
--
-- 'nextToken', 'listStreams_nextToken' - A token used to get the next set of results.
newListStreams ::
  ListStreams
newListStreams :: ListStreams
newListStreams =
  ListStreams'
    { $sel:ascendingOrder:ListStreams' :: Maybe Bool
ascendingOrder = forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:ListStreams' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListStreams' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | Set to true to return the list of streams in ascending order.
listStreams_ascendingOrder :: Lens.Lens' ListStreams (Prelude.Maybe Prelude.Bool)
listStreams_ascendingOrder :: Lens' ListStreams (Maybe Bool)
listStreams_ascendingOrder = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListStreams' {Maybe Bool
ascendingOrder :: Maybe Bool
$sel:ascendingOrder:ListStreams' :: ListStreams -> Maybe Bool
ascendingOrder} -> Maybe Bool
ascendingOrder) (\s :: ListStreams
s@ListStreams' {} Maybe Bool
a -> ListStreams
s {$sel:ascendingOrder:ListStreams' :: Maybe Bool
ascendingOrder = Maybe Bool
a} :: ListStreams)

-- | The maximum number of results to return at a time.
listStreams_maxResults :: Lens.Lens' ListStreams (Prelude.Maybe Prelude.Natural)
listStreams_maxResults :: Lens' ListStreams (Maybe Natural)
listStreams_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListStreams' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListStreams' :: ListStreams -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListStreams
s@ListStreams' {} Maybe Natural
a -> ListStreams
s {$sel:maxResults:ListStreams' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListStreams)

-- | A token used to get the next set of results.
listStreams_nextToken :: Lens.Lens' ListStreams (Prelude.Maybe Prelude.Text)
listStreams_nextToken :: Lens' ListStreams (Maybe Text)
listStreams_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListStreams' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListStreams' :: ListStreams -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListStreams
s@ListStreams' {} Maybe Text
a -> ListStreams
s {$sel:nextToken:ListStreams' :: Maybe Text
nextToken = Maybe Text
a} :: ListStreams)

instance Core.AWSPager ListStreams where
  page :: ListStreams -> AWSResponse ListStreams -> Maybe ListStreams
page ListStreams
rq AWSResponse ListStreams
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListStreams
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListStreamsResponse (Maybe Text)
listStreamsResponse_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 ListStreams
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListStreamsResponse (Maybe [StreamSummary])
listStreamsResponse_streams
            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.$ ListStreams
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListStreams (Maybe Text)
listStreams_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListStreams
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListStreamsResponse (Maybe Text)
listStreamsResponse_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 ListStreams where
  type AWSResponse ListStreams = ListStreamsResponse
  request :: (Service -> Service) -> ListStreams -> Request ListStreams
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 ListStreams
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListStreams)))
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 -> Maybe [StreamSummary] -> Int -> ListStreamsResponse
ListStreamsResponse'
            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.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"streams" 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.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable ListStreams where
  hashWithSalt :: Int -> ListStreams -> Int
hashWithSalt Int
_salt ListStreams' {Maybe Bool
Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
ascendingOrder :: Maybe Bool
$sel:nextToken:ListStreams' :: ListStreams -> Maybe Text
$sel:maxResults:ListStreams' :: ListStreams -> Maybe Natural
$sel:ascendingOrder:ListStreams' :: ListStreams -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
ascendingOrder
      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 ListStreams where
  rnf :: ListStreams -> ()
rnf ListStreams' {Maybe Bool
Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
ascendingOrder :: Maybe Bool
$sel:nextToken:ListStreams' :: ListStreams -> Maybe Text
$sel:maxResults:ListStreams' :: ListStreams -> Maybe Natural
$sel:ascendingOrder:ListStreams' :: ListStreams -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
ascendingOrder
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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 ListStreams where
  toHeaders :: ListStreams -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

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

instance Data.ToQuery ListStreams where
  toQuery :: ListStreams -> QueryString
toQuery ListStreams' {Maybe Bool
Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
ascendingOrder :: Maybe Bool
$sel:nextToken:ListStreams' :: ListStreams -> Maybe Text
$sel:maxResults:ListStreams' :: ListStreams -> Maybe Natural
$sel:ascendingOrder:ListStreams' :: ListStreams -> Maybe Bool
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"isAscendingOrder" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Bool
ascendingOrder,
        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:/ 'newListStreamsResponse' smart constructor.
data ListStreamsResponse = ListStreamsResponse'
  { -- | A token used to get the next set of results.
    ListStreamsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | A list of streams.
    ListStreamsResponse -> Maybe [StreamSummary]
streams :: Prelude.Maybe [StreamSummary],
    -- | The response's http status code.
    ListStreamsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListStreamsResponse -> ListStreamsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListStreamsResponse -> ListStreamsResponse -> Bool
$c/= :: ListStreamsResponse -> ListStreamsResponse -> Bool
== :: ListStreamsResponse -> ListStreamsResponse -> Bool
$c== :: ListStreamsResponse -> ListStreamsResponse -> Bool
Prelude.Eq, ReadPrec [ListStreamsResponse]
ReadPrec ListStreamsResponse
Int -> ReadS ListStreamsResponse
ReadS [ListStreamsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListStreamsResponse]
$creadListPrec :: ReadPrec [ListStreamsResponse]
readPrec :: ReadPrec ListStreamsResponse
$creadPrec :: ReadPrec ListStreamsResponse
readList :: ReadS [ListStreamsResponse]
$creadList :: ReadS [ListStreamsResponse]
readsPrec :: Int -> ReadS ListStreamsResponse
$creadsPrec :: Int -> ReadS ListStreamsResponse
Prelude.Read, Int -> ListStreamsResponse -> ShowS
[ListStreamsResponse] -> ShowS
ListStreamsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListStreamsResponse] -> ShowS
$cshowList :: [ListStreamsResponse] -> ShowS
show :: ListStreamsResponse -> String
$cshow :: ListStreamsResponse -> String
showsPrec :: Int -> ListStreamsResponse -> ShowS
$cshowsPrec :: Int -> ListStreamsResponse -> ShowS
Prelude.Show, forall x. Rep ListStreamsResponse x -> ListStreamsResponse
forall x. ListStreamsResponse -> Rep ListStreamsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListStreamsResponse x -> ListStreamsResponse
$cfrom :: forall x. ListStreamsResponse -> Rep ListStreamsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListStreamsResponse' 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', 'listStreamsResponse_nextToken' - A token used to get the next set of results.
--
-- 'streams', 'listStreamsResponse_streams' - A list of streams.
--
-- 'httpStatus', 'listStreamsResponse_httpStatus' - The response's http status code.
newListStreamsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListStreamsResponse
newListStreamsResponse :: Int -> ListStreamsResponse
newListStreamsResponse Int
pHttpStatus_ =
  ListStreamsResponse'
    { $sel:nextToken:ListStreamsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:streams:ListStreamsResponse' :: Maybe [StreamSummary]
streams = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListStreamsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A token used to get the next set of results.
listStreamsResponse_nextToken :: Lens.Lens' ListStreamsResponse (Prelude.Maybe Prelude.Text)
listStreamsResponse_nextToken :: Lens' ListStreamsResponse (Maybe Text)
listStreamsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListStreamsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListStreamsResponse' :: ListStreamsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListStreamsResponse
s@ListStreamsResponse' {} Maybe Text
a -> ListStreamsResponse
s {$sel:nextToken:ListStreamsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListStreamsResponse)

-- | A list of streams.
listStreamsResponse_streams :: Lens.Lens' ListStreamsResponse (Prelude.Maybe [StreamSummary])
listStreamsResponse_streams :: Lens' ListStreamsResponse (Maybe [StreamSummary])
listStreamsResponse_streams = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListStreamsResponse' {Maybe [StreamSummary]
streams :: Maybe [StreamSummary]
$sel:streams:ListStreamsResponse' :: ListStreamsResponse -> Maybe [StreamSummary]
streams} -> Maybe [StreamSummary]
streams) (\s :: ListStreamsResponse
s@ListStreamsResponse' {} Maybe [StreamSummary]
a -> ListStreamsResponse
s {$sel:streams:ListStreamsResponse' :: Maybe [StreamSummary]
streams = Maybe [StreamSummary]
a} :: ListStreamsResponse) 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 response's http status code.
listStreamsResponse_httpStatus :: Lens.Lens' ListStreamsResponse Prelude.Int
listStreamsResponse_httpStatus :: Lens' ListStreamsResponse Int
listStreamsResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListStreamsResponse' {Int
httpStatus :: Int
$sel:httpStatus:ListStreamsResponse' :: ListStreamsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ListStreamsResponse
s@ListStreamsResponse' {} Int
a -> ListStreamsResponse
s {$sel:httpStatus:ListStreamsResponse' :: Int
httpStatus = Int
a} :: ListStreamsResponse)

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