1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package comprehend
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/comprehend/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Gets a list of sentiment detection jobs that you have submitted.
16func (c *Client) ListSentimentDetectionJobs(ctx context.Context, params *ListSentimentDetectionJobsInput, optFns ...func(*Options)) (*ListSentimentDetectionJobsOutput, error) {
17	if params == nil {
18		params = &ListSentimentDetectionJobsInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListSentimentDetectionJobs", params, optFns, addOperationListSentimentDetectionJobsMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListSentimentDetectionJobsOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListSentimentDetectionJobsInput struct {
32
33	// Filters the jobs that are returned. You can filter jobs on their name, status,
34	// or the date and time that they were submitted. You can only set one filter at a
35	// time.
36	Filter *types.SentimentDetectionJobFilter
37
38	// The maximum number of results to return in each page. The default is 100.
39	MaxResults *int32
40
41	// Identifies the next page of results to return.
42	NextToken *string
43}
44
45type ListSentimentDetectionJobsOutput struct {
46
47	// Identifies the next page of results to return.
48	NextToken *string
49
50	// A list containing the properties of each job that is returned.
51	SentimentDetectionJobPropertiesList []types.SentimentDetectionJobProperties
52
53	// Metadata pertaining to the operation's result.
54	ResultMetadata middleware.Metadata
55}
56
57func addOperationListSentimentDetectionJobsMiddlewares(stack *middleware.Stack, options Options) (err error) {
58	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListSentimentDetectionJobs{}, middleware.After)
59	if err != nil {
60		return err
61	}
62	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListSentimentDetectionJobs{}, middleware.After)
63	if err != nil {
64		return err
65	}
66	if err = addSetLoggerMiddleware(stack, options); err != nil {
67		return err
68	}
69	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
70		return err
71	}
72	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
73		return err
74	}
75	if err = addResolveEndpointMiddleware(stack, options); err != nil {
76		return err
77	}
78	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
79		return err
80	}
81	if err = addRetryMiddlewares(stack, options); err != nil {
82		return err
83	}
84	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
85		return err
86	}
87	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
88		return err
89	}
90	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
91		return err
92	}
93	if err = addClientUserAgent(stack); err != nil {
94		return err
95	}
96	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
97		return err
98	}
99	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
100		return err
101	}
102	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListSentimentDetectionJobs(options.Region), middleware.Before); err != nil {
103		return err
104	}
105	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
106		return err
107	}
108	if err = addResponseErrorMiddleware(stack); err != nil {
109		return err
110	}
111	if err = addRequestResponseLogging(stack, options); err != nil {
112		return err
113	}
114	return nil
115}
116
117// ListSentimentDetectionJobsAPIClient is a client that implements the
118// ListSentimentDetectionJobs operation.
119type ListSentimentDetectionJobsAPIClient interface {
120	ListSentimentDetectionJobs(context.Context, *ListSentimentDetectionJobsInput, ...func(*Options)) (*ListSentimentDetectionJobsOutput, error)
121}
122
123var _ ListSentimentDetectionJobsAPIClient = (*Client)(nil)
124
125// ListSentimentDetectionJobsPaginatorOptions is the paginator options for
126// ListSentimentDetectionJobs
127type ListSentimentDetectionJobsPaginatorOptions struct {
128	// The maximum number of results to return in each page. The default is 100.
129	Limit int32
130
131	// Set to true if pagination should stop if the service returns a pagination token
132	// that matches the most recent token provided to the service.
133	StopOnDuplicateToken bool
134}
135
136// ListSentimentDetectionJobsPaginator is a paginator for
137// ListSentimentDetectionJobs
138type ListSentimentDetectionJobsPaginator struct {
139	options   ListSentimentDetectionJobsPaginatorOptions
140	client    ListSentimentDetectionJobsAPIClient
141	params    *ListSentimentDetectionJobsInput
142	nextToken *string
143	firstPage bool
144}
145
146// NewListSentimentDetectionJobsPaginator returns a new
147// ListSentimentDetectionJobsPaginator
148func NewListSentimentDetectionJobsPaginator(client ListSentimentDetectionJobsAPIClient, params *ListSentimentDetectionJobsInput, optFns ...func(*ListSentimentDetectionJobsPaginatorOptions)) *ListSentimentDetectionJobsPaginator {
149	if params == nil {
150		params = &ListSentimentDetectionJobsInput{}
151	}
152
153	options := ListSentimentDetectionJobsPaginatorOptions{}
154	if params.MaxResults != nil {
155		options.Limit = *params.MaxResults
156	}
157
158	for _, fn := range optFns {
159		fn(&options)
160	}
161
162	return &ListSentimentDetectionJobsPaginator{
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 *ListSentimentDetectionJobsPaginator) HasMorePages() bool {
172	return p.firstPage || p.nextToken != nil
173}
174
175// NextPage retrieves the next ListSentimentDetectionJobs page.
176func (p *ListSentimentDetectionJobsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListSentimentDetectionJobsOutput, 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.ListSentimentDetectionJobs(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_opListSentimentDetectionJobs(region string) *awsmiddleware.RegisterServiceMetadata {
207	return &awsmiddleware.RegisterServiceMetadata{
208		Region:        region,
209		ServiceID:     ServiceID,
210		SigningName:   "comprehend",
211		OperationName: "ListSentimentDetectionJobs",
212	}
213}
214