1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package medialive
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/medialive/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Retrieve a list of the existing multiplexes.
16func (c *Client) ListMultiplexes(ctx context.Context, params *ListMultiplexesInput, optFns ...func(*Options)) (*ListMultiplexesOutput, error) {
17	if params == nil {
18		params = &ListMultiplexesInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListMultiplexes", params, optFns, addOperationListMultiplexesMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListMultiplexesOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31// Placeholder documentation for ListMultiplexesRequest
32type ListMultiplexesInput struct {
33
34	// The maximum number of items to return.
35	MaxResults int32
36
37	// The token to retrieve the next page of results.
38	NextToken *string
39}
40
41// Placeholder documentation for ListMultiplexesResponse
42type ListMultiplexesOutput struct {
43
44	// List of multiplexes.
45	Multiplexes []types.MultiplexSummary
46
47	// Token for the next ListMultiplexes request.
48	NextToken *string
49
50	// Metadata pertaining to the operation's result.
51	ResultMetadata middleware.Metadata
52}
53
54func addOperationListMultiplexesMiddlewares(stack *middleware.Stack, options Options) (err error) {
55	err = stack.Serialize.Add(&awsRestjson1_serializeOpListMultiplexes{}, middleware.After)
56	if err != nil {
57		return err
58	}
59	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListMultiplexes{}, middleware.After)
60	if err != nil {
61		return err
62	}
63	if err = addSetLoggerMiddleware(stack, options); err != nil {
64		return err
65	}
66	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
67		return err
68	}
69	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
70		return err
71	}
72	if err = addResolveEndpointMiddleware(stack, options); err != nil {
73		return err
74	}
75	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
76		return err
77	}
78	if err = addRetryMiddlewares(stack, options); err != nil {
79		return err
80	}
81	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
82		return err
83	}
84	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
85		return err
86	}
87	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
88		return err
89	}
90	if err = addClientUserAgent(stack); err != nil {
91		return err
92	}
93	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
94		return err
95	}
96	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
97		return err
98	}
99	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListMultiplexes(options.Region), middleware.Before); err != nil {
100		return err
101	}
102	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
103		return err
104	}
105	if err = addResponseErrorMiddleware(stack); err != nil {
106		return err
107	}
108	if err = addRequestResponseLogging(stack, options); err != nil {
109		return err
110	}
111	return nil
112}
113
114// ListMultiplexesAPIClient is a client that implements the ListMultiplexes
115// operation.
116type ListMultiplexesAPIClient interface {
117	ListMultiplexes(context.Context, *ListMultiplexesInput, ...func(*Options)) (*ListMultiplexesOutput, error)
118}
119
120var _ ListMultiplexesAPIClient = (*Client)(nil)
121
122// ListMultiplexesPaginatorOptions is the paginator options for ListMultiplexes
123type ListMultiplexesPaginatorOptions struct {
124	// The maximum number of items to return.
125	Limit int32
126
127	// Set to true if pagination should stop if the service returns a pagination token
128	// that matches the most recent token provided to the service.
129	StopOnDuplicateToken bool
130}
131
132// ListMultiplexesPaginator is a paginator for ListMultiplexes
133type ListMultiplexesPaginator struct {
134	options   ListMultiplexesPaginatorOptions
135	client    ListMultiplexesAPIClient
136	params    *ListMultiplexesInput
137	nextToken *string
138	firstPage bool
139}
140
141// NewListMultiplexesPaginator returns a new ListMultiplexesPaginator
142func NewListMultiplexesPaginator(client ListMultiplexesAPIClient, params *ListMultiplexesInput, optFns ...func(*ListMultiplexesPaginatorOptions)) *ListMultiplexesPaginator {
143	if params == nil {
144		params = &ListMultiplexesInput{}
145	}
146
147	options := ListMultiplexesPaginatorOptions{}
148	if params.MaxResults != 0 {
149		options.Limit = params.MaxResults
150	}
151
152	for _, fn := range optFns {
153		fn(&options)
154	}
155
156	return &ListMultiplexesPaginator{
157		options:   options,
158		client:    client,
159		params:    params,
160		firstPage: true,
161	}
162}
163
164// HasMorePages returns a boolean indicating whether more pages are available
165func (p *ListMultiplexesPaginator) HasMorePages() bool {
166	return p.firstPage || p.nextToken != nil
167}
168
169// NextPage retrieves the next ListMultiplexes page.
170func (p *ListMultiplexesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListMultiplexesOutput, error) {
171	if !p.HasMorePages() {
172		return nil, fmt.Errorf("no more pages available")
173	}
174
175	params := *p.params
176	params.NextToken = p.nextToken
177
178	params.MaxResults = p.options.Limit
179
180	result, err := p.client.ListMultiplexes(ctx, &params, optFns...)
181	if err != nil {
182		return nil, err
183	}
184	p.firstPage = false
185
186	prevToken := p.nextToken
187	p.nextToken = result.NextToken
188
189	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
190		p.nextToken = nil
191	}
192
193	return result, nil
194}
195
196func newServiceMetadataMiddleware_opListMultiplexes(region string) *awsmiddleware.RegisterServiceMetadata {
197	return &awsmiddleware.RegisterServiceMetadata{
198		Region:        region,
199		ServiceID:     ServiceID,
200		SigningName:   "medialive",
201		OperationName: "ListMultiplexes",
202	}
203}
204