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