1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package alexaforbusiness
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/alexaforbusiness/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Searches rooms and lists the ones that meet a set of filter and sort criteria.
16func (c *Client) SearchRooms(ctx context.Context, params *SearchRoomsInput, optFns ...func(*Options)) (*SearchRoomsOutput, error) {
17	if params == nil {
18		params = &SearchRoomsInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "SearchRooms", params, optFns, addOperationSearchRoomsMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*SearchRoomsOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type SearchRoomsInput struct {
32
33	// The filters to use to list a specified set of rooms. The supported filter keys
34	// are RoomName and ProfileName.
35	Filters []types.Filter
36
37	// The maximum number of results to include in the response. If more results exist
38	// than the specified MaxResults value, a token is included in the response so that
39	// the remaining results can be retrieved.
40	MaxResults *int32
41
42	// An optional token returned from a prior request. Use this token for pagination
43	// of results from this action. If this parameter is specified, the response
44	// includes only results beyond the token, up to the value specified by MaxResults.
45	NextToken *string
46
47	// The sort order to use in listing the specified set of rooms. The supported sort
48	// keys are RoomName and ProfileName.
49	SortCriteria []types.Sort
50}
51
52type SearchRoomsOutput struct {
53
54	// The token returned to indicate that there is more data available.
55	NextToken *string
56
57	// The rooms that meet the specified set of filter criteria, in sort order.
58	Rooms []types.RoomData
59
60	// The total number of rooms returned.
61	TotalCount *int32
62
63	// Metadata pertaining to the operation's result.
64	ResultMetadata middleware.Metadata
65}
66
67func addOperationSearchRoomsMiddlewares(stack *middleware.Stack, options Options) (err error) {
68	err = stack.Serialize.Add(&awsAwsjson11_serializeOpSearchRooms{}, middleware.After)
69	if err != nil {
70		return err
71	}
72	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpSearchRooms{}, middleware.After)
73	if err != nil {
74		return err
75	}
76	if err = addSetLoggerMiddleware(stack, options); err != nil {
77		return err
78	}
79	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
80		return err
81	}
82	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
83		return err
84	}
85	if err = addResolveEndpointMiddleware(stack, options); err != nil {
86		return err
87	}
88	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
89		return err
90	}
91	if err = addRetryMiddlewares(stack, options); err != nil {
92		return err
93	}
94	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
95		return err
96	}
97	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
98		return err
99	}
100	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
101		return err
102	}
103	if err = addClientUserAgent(stack); err != nil {
104		return err
105	}
106	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
107		return err
108	}
109	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
110		return err
111	}
112	if err = addOpSearchRoomsValidationMiddleware(stack); err != nil {
113		return err
114	}
115	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opSearchRooms(options.Region), middleware.Before); err != nil {
116		return err
117	}
118	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
119		return err
120	}
121	if err = addResponseErrorMiddleware(stack); err != nil {
122		return err
123	}
124	if err = addRequestResponseLogging(stack, options); err != nil {
125		return err
126	}
127	return nil
128}
129
130// SearchRoomsAPIClient is a client that implements the SearchRooms operation.
131type SearchRoomsAPIClient interface {
132	SearchRooms(context.Context, *SearchRoomsInput, ...func(*Options)) (*SearchRoomsOutput, error)
133}
134
135var _ SearchRoomsAPIClient = (*Client)(nil)
136
137// SearchRoomsPaginatorOptions is the paginator options for SearchRooms
138type SearchRoomsPaginatorOptions struct {
139	// The maximum number of results to include in the response. If more results exist
140	// than the specified MaxResults value, a token is included in the response so that
141	// the remaining results can be retrieved.
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// SearchRoomsPaginator is a paginator for SearchRooms
150type SearchRoomsPaginator struct {
151	options   SearchRoomsPaginatorOptions
152	client    SearchRoomsAPIClient
153	params    *SearchRoomsInput
154	nextToken *string
155	firstPage bool
156}
157
158// NewSearchRoomsPaginator returns a new SearchRoomsPaginator
159func NewSearchRoomsPaginator(client SearchRoomsAPIClient, params *SearchRoomsInput, optFns ...func(*SearchRoomsPaginatorOptions)) *SearchRoomsPaginator {
160	if params == nil {
161		params = &SearchRoomsInput{}
162	}
163
164	options := SearchRoomsPaginatorOptions{}
165	if params.MaxResults != nil {
166		options.Limit = *params.MaxResults
167	}
168
169	for _, fn := range optFns {
170		fn(&options)
171	}
172
173	return &SearchRoomsPaginator{
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 *SearchRoomsPaginator) HasMorePages() bool {
183	return p.firstPage || p.nextToken != nil
184}
185
186// NextPage retrieves the next SearchRooms page.
187func (p *SearchRoomsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*SearchRoomsOutput, 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.SearchRooms(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_opSearchRooms(region string) *awsmiddleware.RegisterServiceMetadata {
218	return &awsmiddleware.RegisterServiceMetadata{
219		Region:        region,
220		ServiceID:     ServiceID,
221		SigningName:   "a4b",
222		OperationName: "SearchRooms",
223	}
224}
225