1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package sagemaker
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/sagemaker/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// List the candidates created for the job.
16func (c *Client) ListCandidatesForAutoMLJob(ctx context.Context, params *ListCandidatesForAutoMLJobInput, optFns ...func(*Options)) (*ListCandidatesForAutoMLJobOutput, error) {
17	if params == nil {
18		params = &ListCandidatesForAutoMLJobInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListCandidatesForAutoMLJob", params, optFns, addOperationListCandidatesForAutoMLJobMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListCandidatesForAutoMLJobOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListCandidatesForAutoMLJobInput struct {
32
33	// List the candidates created for the job by providing the job's name.
34	//
35	// This member is required.
36	AutoMLJobName *string
37
38	// List the candidates for the job and filter by candidate name.
39	CandidateNameEquals *string
40
41	// List the job's candidates up to a specified limit.
42	MaxResults int32
43
44	// If the previous response was truncated, you receive this token. Use it in your
45	// next request to receive the next set of results.
46	NextToken *string
47
48	// The parameter by which to sort the results. The default is Descending.
49	SortBy types.CandidateSortBy
50
51	// The sort order for the results. The default is Ascending.
52	SortOrder types.AutoMLSortOrder
53
54	// List the candidates for the job and filter by status.
55	StatusEquals types.CandidateStatus
56}
57
58type ListCandidatesForAutoMLJobOutput struct {
59
60	// Summaries about the Candidates.
61	//
62	// This member is required.
63	Candidates []types.AutoMLCandidate
64
65	// If the previous response was truncated, you receive this token. Use it in your
66	// next request to receive the next set of results.
67	NextToken *string
68
69	// Metadata pertaining to the operation's result.
70	ResultMetadata middleware.Metadata
71}
72
73func addOperationListCandidatesForAutoMLJobMiddlewares(stack *middleware.Stack, options Options) (err error) {
74	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListCandidatesForAutoMLJob{}, middleware.After)
75	if err != nil {
76		return err
77	}
78	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListCandidatesForAutoMLJob{}, middleware.After)
79	if err != nil {
80		return err
81	}
82	if err = addSetLoggerMiddleware(stack, options); err != nil {
83		return err
84	}
85	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
86		return err
87	}
88	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
89		return err
90	}
91	if err = addResolveEndpointMiddleware(stack, options); err != nil {
92		return err
93	}
94	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
95		return err
96	}
97	if err = addRetryMiddlewares(stack, options); err != nil {
98		return err
99	}
100	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
101		return err
102	}
103	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
104		return err
105	}
106	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
107		return err
108	}
109	if err = addClientUserAgent(stack); err != nil {
110		return err
111	}
112	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
113		return err
114	}
115	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
116		return err
117	}
118	if err = addOpListCandidatesForAutoMLJobValidationMiddleware(stack); err != nil {
119		return err
120	}
121	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListCandidatesForAutoMLJob(options.Region), middleware.Before); err != nil {
122		return err
123	}
124	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
125		return err
126	}
127	if err = addResponseErrorMiddleware(stack); err != nil {
128		return err
129	}
130	if err = addRequestResponseLogging(stack, options); err != nil {
131		return err
132	}
133	return nil
134}
135
136// ListCandidatesForAutoMLJobAPIClient is a client that implements the
137// ListCandidatesForAutoMLJob operation.
138type ListCandidatesForAutoMLJobAPIClient interface {
139	ListCandidatesForAutoMLJob(context.Context, *ListCandidatesForAutoMLJobInput, ...func(*Options)) (*ListCandidatesForAutoMLJobOutput, error)
140}
141
142var _ ListCandidatesForAutoMLJobAPIClient = (*Client)(nil)
143
144// ListCandidatesForAutoMLJobPaginatorOptions is the paginator options for
145// ListCandidatesForAutoMLJob
146type ListCandidatesForAutoMLJobPaginatorOptions struct {
147	// List the job's candidates up to a specified limit.
148	Limit int32
149
150	// Set to true if pagination should stop if the service returns a pagination token
151	// that matches the most recent token provided to the service.
152	StopOnDuplicateToken bool
153}
154
155// ListCandidatesForAutoMLJobPaginator is a paginator for
156// ListCandidatesForAutoMLJob
157type ListCandidatesForAutoMLJobPaginator struct {
158	options   ListCandidatesForAutoMLJobPaginatorOptions
159	client    ListCandidatesForAutoMLJobAPIClient
160	params    *ListCandidatesForAutoMLJobInput
161	nextToken *string
162	firstPage bool
163}
164
165// NewListCandidatesForAutoMLJobPaginator returns a new
166// ListCandidatesForAutoMLJobPaginator
167func NewListCandidatesForAutoMLJobPaginator(client ListCandidatesForAutoMLJobAPIClient, params *ListCandidatesForAutoMLJobInput, optFns ...func(*ListCandidatesForAutoMLJobPaginatorOptions)) *ListCandidatesForAutoMLJobPaginator {
168	if params == nil {
169		params = &ListCandidatesForAutoMLJobInput{}
170	}
171
172	options := ListCandidatesForAutoMLJobPaginatorOptions{}
173	if params.MaxResults != 0 {
174		options.Limit = params.MaxResults
175	}
176
177	for _, fn := range optFns {
178		fn(&options)
179	}
180
181	return &ListCandidatesForAutoMLJobPaginator{
182		options:   options,
183		client:    client,
184		params:    params,
185		firstPage: true,
186	}
187}
188
189// HasMorePages returns a boolean indicating whether more pages are available
190func (p *ListCandidatesForAutoMLJobPaginator) HasMorePages() bool {
191	return p.firstPage || p.nextToken != nil
192}
193
194// NextPage retrieves the next ListCandidatesForAutoMLJob page.
195func (p *ListCandidatesForAutoMLJobPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListCandidatesForAutoMLJobOutput, error) {
196	if !p.HasMorePages() {
197		return nil, fmt.Errorf("no more pages available")
198	}
199
200	params := *p.params
201	params.NextToken = p.nextToken
202
203	params.MaxResults = p.options.Limit
204
205	result, err := p.client.ListCandidatesForAutoMLJob(ctx, &params, optFns...)
206	if err != nil {
207		return nil, err
208	}
209	p.firstPage = false
210
211	prevToken := p.nextToken
212	p.nextToken = result.NextToken
213
214	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
215		p.nextToken = nil
216	}
217
218	return result, nil
219}
220
221func newServiceMetadataMiddleware_opListCandidatesForAutoMLJob(region string) *awsmiddleware.RegisterServiceMetadata {
222	return &awsmiddleware.RegisterServiceMetadata{
223		Region:        region,
224		ServiceID:     ServiceID,
225		SigningName:   "sagemaker",
226		OperationName: "ListCandidatesForAutoMLJob",
227	}
228}
229