1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package chime
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/chime/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists the Amazon Chime accounts under the administrator's AWS account. You can
16// filter accounts by account name prefix. To find out which Amazon Chime account a
17// user belongs to, toucan filter by the user's email address, which returns one
18// account result.
19func (c *Client) ListAccounts(ctx context.Context, params *ListAccountsInput, optFns ...func(*Options)) (*ListAccountsOutput, error) {
20	if params == nil {
21		params = &ListAccountsInput{}
22	}
23
24	result, metadata, err := c.invokeOperation(ctx, "ListAccounts", params, optFns, addOperationListAccountsMiddlewares)
25	if err != nil {
26		return nil, err
27	}
28
29	out := result.(*ListAccountsOutput)
30	out.ResultMetadata = metadata
31	return out, nil
32}
33
34type ListAccountsInput struct {
35
36	// The maximum number of results to return in a single call. Defaults to 100.
37	MaxResults *int32
38
39	// Amazon Chime account name prefix with which to filter results.
40	Name *string
41
42	// The token to use to retrieve the next page of results.
43	NextToken *string
44
45	// User email address with which to filter results.
46	UserEmail *string
47}
48
49type ListAccountsOutput struct {
50
51	// List of Amazon Chime accounts and account details.
52	Accounts []types.Account
53
54	// The token to use to retrieve the next page of results.
55	NextToken *string
56
57	// Metadata pertaining to the operation's result.
58	ResultMetadata middleware.Metadata
59}
60
61func addOperationListAccountsMiddlewares(stack *middleware.Stack, options Options) (err error) {
62	err = stack.Serialize.Add(&awsRestjson1_serializeOpListAccounts{}, middleware.After)
63	if err != nil {
64		return err
65	}
66	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListAccounts{}, middleware.After)
67	if err != nil {
68		return err
69	}
70	if err = addSetLoggerMiddleware(stack, options); err != nil {
71		return err
72	}
73	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
74		return err
75	}
76	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
77		return err
78	}
79	if err = addResolveEndpointMiddleware(stack, options); err != nil {
80		return err
81	}
82	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
83		return err
84	}
85	if err = addRetryMiddlewares(stack, options); err != nil {
86		return err
87	}
88	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
89		return err
90	}
91	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
92		return err
93	}
94	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
95		return err
96	}
97	if err = addClientUserAgent(stack); err != nil {
98		return err
99	}
100	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
101		return err
102	}
103	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
104		return err
105	}
106	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListAccounts(options.Region), middleware.Before); err != nil {
107		return err
108	}
109	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
110		return err
111	}
112	if err = addResponseErrorMiddleware(stack); err != nil {
113		return err
114	}
115	if err = addRequestResponseLogging(stack, options); err != nil {
116		return err
117	}
118	return nil
119}
120
121// ListAccountsAPIClient is a client that implements the ListAccounts operation.
122type ListAccountsAPIClient interface {
123	ListAccounts(context.Context, *ListAccountsInput, ...func(*Options)) (*ListAccountsOutput, error)
124}
125
126var _ ListAccountsAPIClient = (*Client)(nil)
127
128// ListAccountsPaginatorOptions is the paginator options for ListAccounts
129type ListAccountsPaginatorOptions struct {
130	// The maximum number of results to return in a single call. Defaults to 100.
131	Limit int32
132
133	// Set to true if pagination should stop if the service returns a pagination token
134	// that matches the most recent token provided to the service.
135	StopOnDuplicateToken bool
136}
137
138// ListAccountsPaginator is a paginator for ListAccounts
139type ListAccountsPaginator struct {
140	options   ListAccountsPaginatorOptions
141	client    ListAccountsAPIClient
142	params    *ListAccountsInput
143	nextToken *string
144	firstPage bool
145}
146
147// NewListAccountsPaginator returns a new ListAccountsPaginator
148func NewListAccountsPaginator(client ListAccountsAPIClient, params *ListAccountsInput, optFns ...func(*ListAccountsPaginatorOptions)) *ListAccountsPaginator {
149	if params == nil {
150		params = &ListAccountsInput{}
151	}
152
153	options := ListAccountsPaginatorOptions{}
154	if params.MaxResults != nil {
155		options.Limit = *params.MaxResults
156	}
157
158	for _, fn := range optFns {
159		fn(&options)
160	}
161
162	return &ListAccountsPaginator{
163		options:   options,
164		client:    client,
165		params:    params,
166		firstPage: true,
167	}
168}
169
170// HasMorePages returns a boolean indicating whether more pages are available
171func (p *ListAccountsPaginator) HasMorePages() bool {
172	return p.firstPage || p.nextToken != nil
173}
174
175// NextPage retrieves the next ListAccounts page.
176func (p *ListAccountsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListAccountsOutput, error) {
177	if !p.HasMorePages() {
178		return nil, fmt.Errorf("no more pages available")
179	}
180
181	params := *p.params
182	params.NextToken = p.nextToken
183
184	var limit *int32
185	if p.options.Limit > 0 {
186		limit = &p.options.Limit
187	}
188	params.MaxResults = limit
189
190	result, err := p.client.ListAccounts(ctx, &params, optFns...)
191	if err != nil {
192		return nil, err
193	}
194	p.firstPage = false
195
196	prevToken := p.nextToken
197	p.nextToken = result.NextToken
198
199	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
200		p.nextToken = nil
201	}
202
203	return result, nil
204}
205
206func newServiceMetadataMiddleware_opListAccounts(region string) *awsmiddleware.RegisterServiceMetadata {
207	return &awsmiddleware.RegisterServiceMetadata{
208		Region:        region,
209		ServiceID:     ServiceID,
210		SigningName:   "chime",
211		OperationName: "ListAccounts",
212	}
213}
214