1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package robomaker
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/robomaker/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists worlds.
16func (c *Client) ListWorlds(ctx context.Context, params *ListWorldsInput, optFns ...func(*Options)) (*ListWorldsOutput, error) {
17	if params == nil {
18		params = &ListWorldsInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListWorlds", params, optFns, addOperationListWorldsMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListWorldsOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListWorldsInput struct {
32
33	// Optional filters to limit results. You can use status.
34	Filters []types.Filter
35
36	// When this parameter is used, ListWorlds only returns maxResults results in a
37	// single page along with a nextToken response element. The remaining results of
38	// the initial request can be seen by sending another ListWorlds request with the
39	// returned nextToken value. This value can be between 1 and 100. If this parameter
40	// is not used, then ListWorlds returns up to 100 results and a nextToken value if
41	// applicable.
42	MaxResults *int32
43
44	// If the previous paginated request did not return all of the remaining results,
45	// the response object's nextToken parameter value is set to a token. To retrieve
46	// the next set of results, call ListWorlds again and assign that token to the
47	// request object's nextToken parameter. If there are no remaining results, the
48	// previous response object's NextToken parameter is set to null.
49	NextToken *string
50}
51
52type ListWorldsOutput struct {
53
54	// If the previous paginated request did not return all of the remaining results,
55	// the response object's nextToken parameter value is set to a token. To retrieve
56	// the next set of results, call ListWorlds again and assign that token to the
57	// request object's nextToken parameter. If there are no remaining results, the
58	// previous response object's NextToken parameter is set to null.
59	NextToken *string
60
61	// Summary information for worlds.
62	WorldSummaries []types.WorldSummary
63
64	// Metadata pertaining to the operation's result.
65	ResultMetadata middleware.Metadata
66}
67
68func addOperationListWorldsMiddlewares(stack *middleware.Stack, options Options) (err error) {
69	err = stack.Serialize.Add(&awsRestjson1_serializeOpListWorlds{}, middleware.After)
70	if err != nil {
71		return err
72	}
73	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListWorlds{}, middleware.After)
74	if err != nil {
75		return err
76	}
77	if err = addSetLoggerMiddleware(stack, options); err != nil {
78		return err
79	}
80	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
81		return err
82	}
83	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
84		return err
85	}
86	if err = addResolveEndpointMiddleware(stack, options); err != nil {
87		return err
88	}
89	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
90		return err
91	}
92	if err = addRetryMiddlewares(stack, options); err != nil {
93		return err
94	}
95	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
96		return err
97	}
98	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
99		return err
100	}
101	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
102		return err
103	}
104	if err = addClientUserAgent(stack); err != nil {
105		return err
106	}
107	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
108		return err
109	}
110	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
111		return err
112	}
113	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListWorlds(options.Region), middleware.Before); err != nil {
114		return err
115	}
116	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
117		return err
118	}
119	if err = addResponseErrorMiddleware(stack); err != nil {
120		return err
121	}
122	if err = addRequestResponseLogging(stack, options); err != nil {
123		return err
124	}
125	return nil
126}
127
128// ListWorldsAPIClient is a client that implements the ListWorlds operation.
129type ListWorldsAPIClient interface {
130	ListWorlds(context.Context, *ListWorldsInput, ...func(*Options)) (*ListWorldsOutput, error)
131}
132
133var _ ListWorldsAPIClient = (*Client)(nil)
134
135// ListWorldsPaginatorOptions is the paginator options for ListWorlds
136type ListWorldsPaginatorOptions struct {
137	// When this parameter is used, ListWorlds only returns maxResults results in a
138	// single page along with a nextToken response element. The remaining results of
139	// the initial request can be seen by sending another ListWorlds request with the
140	// returned nextToken value. This value can be between 1 and 100. If this parameter
141	// is not used, then ListWorlds returns up to 100 results and a nextToken value if
142	// applicable.
143	Limit int32
144
145	// Set to true if pagination should stop if the service returns a pagination token
146	// that matches the most recent token provided to the service.
147	StopOnDuplicateToken bool
148}
149
150// ListWorldsPaginator is a paginator for ListWorlds
151type ListWorldsPaginator struct {
152	options   ListWorldsPaginatorOptions
153	client    ListWorldsAPIClient
154	params    *ListWorldsInput
155	nextToken *string
156	firstPage bool
157}
158
159// NewListWorldsPaginator returns a new ListWorldsPaginator
160func NewListWorldsPaginator(client ListWorldsAPIClient, params *ListWorldsInput, optFns ...func(*ListWorldsPaginatorOptions)) *ListWorldsPaginator {
161	options := ListWorldsPaginatorOptions{}
162	if params.MaxResults != nil {
163		options.Limit = *params.MaxResults
164	}
165
166	for _, fn := range optFns {
167		fn(&options)
168	}
169
170	if params == nil {
171		params = &ListWorldsInput{}
172	}
173
174	return &ListWorldsPaginator{
175		options:   options,
176		client:    client,
177		params:    params,
178		firstPage: true,
179	}
180}
181
182// HasMorePages returns a boolean indicating whether more pages are available
183func (p *ListWorldsPaginator) HasMorePages() bool {
184	return p.firstPage || p.nextToken != nil
185}
186
187// NextPage retrieves the next ListWorlds page.
188func (p *ListWorldsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListWorldsOutput, error) {
189	if !p.HasMorePages() {
190		return nil, fmt.Errorf("no more pages available")
191	}
192
193	params := *p.params
194	params.NextToken = p.nextToken
195
196	var limit *int32
197	if p.options.Limit > 0 {
198		limit = &p.options.Limit
199	}
200	params.MaxResults = limit
201
202	result, err := p.client.ListWorlds(ctx, &params, optFns...)
203	if err != nil {
204		return nil, err
205	}
206	p.firstPage = false
207
208	prevToken := p.nextToken
209	p.nextToken = result.NextToken
210
211	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
212		p.nextToken = nil
213	}
214
215	return result, nil
216}
217
218func newServiceMetadataMiddleware_opListWorlds(region string) *awsmiddleware.RegisterServiceMetadata {
219	return &awsmiddleware.RegisterServiceMetadata{
220		Region:        region,
221		ServiceID:     ServiceID,
222		SigningName:   "robomaker",
223		OperationName: "ListWorlds",
224	}
225}
226