{-# 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.IVS.ListStreamSessions
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets a summary of current and previous streams for a specified channel
-- in your account, in the AWS region where the API request is processed.
module Amazonka.IVS.ListStreamSessions
  ( -- * Creating a Request
    ListStreamSessions (..),
    newListStreamSessions,

    -- * Request Lenses
    listStreamSessions_maxResults,
    listStreamSessions_nextToken,
    listStreamSessions_channelArn,

    -- * Destructuring the Response
    ListStreamSessionsResponse (..),
    newListStreamSessionsResponse,

    -- * Response Lenses
    listStreamSessionsResponse_nextToken,
    listStreamSessionsResponse_httpStatus,
    listStreamSessionsResponse_streamSessions,
  )
where

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

-- | /See:/ 'newListStreamSessions' smart constructor.
data ListStreamSessions = ListStreamSessions'
  { -- | Maximum number of streams to return. Default: 100.
    ListStreamSessions -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The first stream to retrieve. This is used for pagination; see the
    -- @nextToken@ response field.
    ListStreamSessions -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | Channel ARN used to filter the list.
    ListStreamSessions -> Text
channelArn :: Prelude.Text
  }
  deriving (ListStreamSessions -> ListStreamSessions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListStreamSessions -> ListStreamSessions -> Bool
$c/= :: ListStreamSessions -> ListStreamSessions -> Bool
== :: ListStreamSessions -> ListStreamSessions -> Bool
$c== :: ListStreamSessions -> ListStreamSessions -> Bool
Prelude.Eq, ReadPrec [ListStreamSessions]
ReadPrec ListStreamSessions
Int -> ReadS ListStreamSessions
ReadS [ListStreamSessions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListStreamSessions]
$creadListPrec :: ReadPrec [ListStreamSessions]
readPrec :: ReadPrec ListStreamSessions
$creadPrec :: ReadPrec ListStreamSessions
readList :: ReadS [ListStreamSessions]
$creadList :: ReadS [ListStreamSessions]
readsPrec :: Int -> ReadS ListStreamSessions
$creadsPrec :: Int -> ReadS ListStreamSessions
Prelude.Read, Int -> ListStreamSessions -> ShowS
[ListStreamSessions] -> ShowS
ListStreamSessions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListStreamSessions] -> ShowS
$cshowList :: [ListStreamSessions] -> ShowS
show :: ListStreamSessions -> String
$cshow :: ListStreamSessions -> String
showsPrec :: Int -> ListStreamSessions -> ShowS
$cshowsPrec :: Int -> ListStreamSessions -> ShowS
Prelude.Show, forall x. Rep ListStreamSessions x -> ListStreamSessions
forall x. ListStreamSessions -> Rep ListStreamSessions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListStreamSessions x -> ListStreamSessions
$cfrom :: forall x. ListStreamSessions -> Rep ListStreamSessions x
Prelude.Generic)

-- |
-- Create a value of 'ListStreamSessions' 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', 'listStreamSessions_maxResults' - Maximum number of streams to return. Default: 100.
--
-- 'nextToken', 'listStreamSessions_nextToken' - The first stream to retrieve. This is used for pagination; see the
-- @nextToken@ response field.
--
-- 'channelArn', 'listStreamSessions_channelArn' - Channel ARN used to filter the list.
newListStreamSessions ::
  -- | 'channelArn'
  Prelude.Text ->
  ListStreamSessions
newListStreamSessions :: Text -> ListStreamSessions
newListStreamSessions Text
pChannelArn_ =
  ListStreamSessions'
    { $sel:maxResults:ListStreamSessions' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListStreamSessions' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:channelArn:ListStreamSessions' :: Text
channelArn = Text
pChannelArn_
    }

-- | Maximum number of streams to return. Default: 100.
listStreamSessions_maxResults :: Lens.Lens' ListStreamSessions (Prelude.Maybe Prelude.Natural)
listStreamSessions_maxResults :: Lens' ListStreamSessions (Maybe Natural)
listStreamSessions_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListStreamSessions' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListStreamSessions' :: ListStreamSessions -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListStreamSessions
s@ListStreamSessions' {} Maybe Natural
a -> ListStreamSessions
s {$sel:maxResults:ListStreamSessions' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListStreamSessions)

-- | The first stream to retrieve. This is used for pagination; see the
-- @nextToken@ response field.
listStreamSessions_nextToken :: Lens.Lens' ListStreamSessions (Prelude.Maybe Prelude.Text)
listStreamSessions_nextToken :: Lens' ListStreamSessions (Maybe Text)
listStreamSessions_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListStreamSessions' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListStreamSessions' :: ListStreamSessions -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListStreamSessions
s@ListStreamSessions' {} Maybe Text
a -> ListStreamSessions
s {$sel:nextToken:ListStreamSessions' :: Maybe Text
nextToken = Maybe Text
a} :: ListStreamSessions)

-- | Channel ARN used to filter the list.
listStreamSessions_channelArn :: Lens.Lens' ListStreamSessions Prelude.Text
listStreamSessions_channelArn :: Lens' ListStreamSessions Text
listStreamSessions_channelArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListStreamSessions' {Text
channelArn :: Text
$sel:channelArn:ListStreamSessions' :: ListStreamSessions -> Text
channelArn} -> Text
channelArn) (\s :: ListStreamSessions
s@ListStreamSessions' {} Text
a -> ListStreamSessions
s {$sel:channelArn:ListStreamSessions' :: Text
channelArn = Text
a} :: ListStreamSessions)

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

instance Prelude.Hashable ListStreamSessions where
  hashWithSalt :: Int -> ListStreamSessions -> Int
hashWithSalt Int
_salt ListStreamSessions' {Maybe Natural
Maybe Text
Text
channelArn :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:channelArn:ListStreamSessions' :: ListStreamSessions -> Text
$sel:nextToken:ListStreamSessions' :: ListStreamSessions -> Maybe Text
$sel:maxResults:ListStreamSessions' :: ListStreamSessions -> 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
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
channelArn

instance Prelude.NFData ListStreamSessions where
  rnf :: ListStreamSessions -> ()
rnf ListStreamSessions' {Maybe Natural
Maybe Text
Text
channelArn :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:channelArn:ListStreamSessions' :: ListStreamSessions -> Text
$sel:nextToken:ListStreamSessions' :: ListStreamSessions -> Maybe Text
$sel:maxResults:ListStreamSessions' :: ListStreamSessions -> 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
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
channelArn

instance Data.ToHeaders ListStreamSessions where
  toHeaders :: ListStreamSessions -> 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.ToJSON ListStreamSessions where
  toJSON :: ListStreamSessions -> Value
toJSON ListStreamSessions' {Maybe Natural
Maybe Text
Text
channelArn :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:channelArn:ListStreamSessions' :: ListStreamSessions -> Text
$sel:nextToken:ListStreamSessions' :: ListStreamSessions -> Maybe Text
$sel:maxResults:ListStreamSessions' :: ListStreamSessions -> 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,
            forall a. a -> Maybe a
Prelude.Just (Key
"channelArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
channelArn)
          ]
      )

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

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

-- | /See:/ 'newListStreamSessionsResponse' smart constructor.
data ListStreamSessionsResponse = ListStreamSessionsResponse'
  { -- | If there are more streams than @maxResults@, use @nextToken@ in the
    -- request to get the next set.
    ListStreamSessionsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListStreamSessionsResponse -> Int
httpStatus :: Prelude.Int,
    -- | List of stream sessions.
    ListStreamSessionsResponse -> [StreamSessionSummary]
streamSessions :: [StreamSessionSummary]
  }
  deriving (ListStreamSessionsResponse -> ListStreamSessionsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListStreamSessionsResponse -> ListStreamSessionsResponse -> Bool
$c/= :: ListStreamSessionsResponse -> ListStreamSessionsResponse -> Bool
== :: ListStreamSessionsResponse -> ListStreamSessionsResponse -> Bool
$c== :: ListStreamSessionsResponse -> ListStreamSessionsResponse -> Bool
Prelude.Eq, ReadPrec [ListStreamSessionsResponse]
ReadPrec ListStreamSessionsResponse
Int -> ReadS ListStreamSessionsResponse
ReadS [ListStreamSessionsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListStreamSessionsResponse]
$creadListPrec :: ReadPrec [ListStreamSessionsResponse]
readPrec :: ReadPrec ListStreamSessionsResponse
$creadPrec :: ReadPrec ListStreamSessionsResponse
readList :: ReadS [ListStreamSessionsResponse]
$creadList :: ReadS [ListStreamSessionsResponse]
readsPrec :: Int -> ReadS ListStreamSessionsResponse
$creadsPrec :: Int -> ReadS ListStreamSessionsResponse
Prelude.Read, Int -> ListStreamSessionsResponse -> ShowS
[ListStreamSessionsResponse] -> ShowS
ListStreamSessionsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListStreamSessionsResponse] -> ShowS
$cshowList :: [ListStreamSessionsResponse] -> ShowS
show :: ListStreamSessionsResponse -> String
$cshow :: ListStreamSessionsResponse -> String
showsPrec :: Int -> ListStreamSessionsResponse -> ShowS
$cshowsPrec :: Int -> ListStreamSessionsResponse -> ShowS
Prelude.Show, forall x.
Rep ListStreamSessionsResponse x -> ListStreamSessionsResponse
forall x.
ListStreamSessionsResponse -> Rep ListStreamSessionsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListStreamSessionsResponse x -> ListStreamSessionsResponse
$cfrom :: forall x.
ListStreamSessionsResponse -> Rep ListStreamSessionsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListStreamSessionsResponse' 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', 'listStreamSessionsResponse_nextToken' - If there are more streams than @maxResults@, use @nextToken@ in the
-- request to get the next set.
--
-- 'httpStatus', 'listStreamSessionsResponse_httpStatus' - The response's http status code.
--
-- 'streamSessions', 'listStreamSessionsResponse_streamSessions' - List of stream sessions.
newListStreamSessionsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListStreamSessionsResponse
newListStreamSessionsResponse :: Int -> ListStreamSessionsResponse
newListStreamSessionsResponse Int
pHttpStatus_ =
  ListStreamSessionsResponse'
    { $sel:nextToken:ListStreamSessionsResponse' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListStreamSessionsResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:streamSessions:ListStreamSessionsResponse' :: [StreamSessionSummary]
streamSessions = forall a. Monoid a => a
Prelude.mempty
    }

-- | If there are more streams than @maxResults@, use @nextToken@ in the
-- request to get the next set.
listStreamSessionsResponse_nextToken :: Lens.Lens' ListStreamSessionsResponse (Prelude.Maybe Prelude.Text)
listStreamSessionsResponse_nextToken :: Lens' ListStreamSessionsResponse (Maybe Text)
listStreamSessionsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListStreamSessionsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListStreamSessionsResponse' :: ListStreamSessionsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListStreamSessionsResponse
s@ListStreamSessionsResponse' {} Maybe Text
a -> ListStreamSessionsResponse
s {$sel:nextToken:ListStreamSessionsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListStreamSessionsResponse)

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

-- | List of stream sessions.
listStreamSessionsResponse_streamSessions :: Lens.Lens' ListStreamSessionsResponse [StreamSessionSummary]
listStreamSessionsResponse_streamSessions :: Lens' ListStreamSessionsResponse [StreamSessionSummary]
listStreamSessionsResponse_streamSessions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListStreamSessionsResponse' {[StreamSessionSummary]
streamSessions :: [StreamSessionSummary]
$sel:streamSessions:ListStreamSessionsResponse' :: ListStreamSessionsResponse -> [StreamSessionSummary]
streamSessions} -> [StreamSessionSummary]
streamSessions) (\s :: ListStreamSessionsResponse
s@ListStreamSessionsResponse' {} [StreamSessionSummary]
a -> ListStreamSessionsResponse
s {$sel:streamSessions:ListStreamSessionsResponse' :: [StreamSessionSummary]
streamSessions = [StreamSessionSummary]
a} :: ListStreamSessionsResponse) 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 ListStreamSessionsResponse where
  rnf :: ListStreamSessionsResponse -> ()
rnf ListStreamSessionsResponse' {Int
[StreamSessionSummary]
Maybe Text
streamSessions :: [StreamSessionSummary]
httpStatus :: Int
nextToken :: Maybe Text
$sel:streamSessions:ListStreamSessionsResponse' :: ListStreamSessionsResponse -> [StreamSessionSummary]
$sel:httpStatus:ListStreamSessionsResponse' :: ListStreamSessionsResponse -> Int
$sel:nextToken:ListStreamSessionsResponse' :: ListStreamSessionsResponse -> 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 [StreamSessionSummary]
streamSessions