1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package connect
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/connect/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Provides information about the contact flows for the specified Amazon Connect
16// instance. You can also create and update contact flows using the Amazon Connect
17// Flow language
18// (https://docs.aws.amazon.com/connect/latest/adminguide/flow-language.html). For
19// more information about contact flows, see Contact Flows
20// (https://docs.aws.amazon.com/connect/latest/adminguide/concepts-contact-flows.html)
21// in the Amazon Connect Administrator Guide.
22func (c *Client) ListContactFlows(ctx context.Context, params *ListContactFlowsInput, optFns ...func(*Options)) (*ListContactFlowsOutput, error) {
23	if params == nil {
24		params = &ListContactFlowsInput{}
25	}
26
27	result, metadata, err := c.invokeOperation(ctx, "ListContactFlows", params, optFns, addOperationListContactFlowsMiddlewares)
28	if err != nil {
29		return nil, err
30	}
31
32	out := result.(*ListContactFlowsOutput)
33	out.ResultMetadata = metadata
34	return out, nil
35}
36
37type ListContactFlowsInput struct {
38
39	// The identifier of the Amazon Connect instance.
40	//
41	// This member is required.
42	InstanceId *string
43
44	// The type of contact flow.
45	ContactFlowTypes []types.ContactFlowType
46
47	// The maximum number of results to return per page.
48	MaxResults int32
49
50	// The token for the next set of results. Use the value returned in the previous
51	// response in the next request to retrieve the next set of results.
52	NextToken *string
53}
54
55type ListContactFlowsOutput struct {
56
57	// Information about the contact flows.
58	ContactFlowSummaryList []types.ContactFlowSummary
59
60	// If there are additional results, this is the token for the next set of results.
61	NextToken *string
62
63	// Metadata pertaining to the operation's result.
64	ResultMetadata middleware.Metadata
65}
66
67func addOperationListContactFlowsMiddlewares(stack *middleware.Stack, options Options) (err error) {
68	err = stack.Serialize.Add(&awsRestjson1_serializeOpListContactFlows{}, middleware.After)
69	if err != nil {
70		return err
71	}
72	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListContactFlows{}, 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 = addOpListContactFlowsValidationMiddleware(stack); err != nil {
113		return err
114	}
115	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListContactFlows(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// ListContactFlowsAPIClient is a client that implements the ListContactFlows
131// operation.
132type ListContactFlowsAPIClient interface {
133	ListContactFlows(context.Context, *ListContactFlowsInput, ...func(*Options)) (*ListContactFlowsOutput, error)
134}
135
136var _ ListContactFlowsAPIClient = (*Client)(nil)
137
138// ListContactFlowsPaginatorOptions is the paginator options for ListContactFlows
139type ListContactFlowsPaginatorOptions struct {
140	// The maximum number of results to return per page.
141	Limit int32
142
143	// Set to true if pagination should stop if the service returns a pagination token
144	// that matches the most recent token provided to the service.
145	StopOnDuplicateToken bool
146}
147
148// ListContactFlowsPaginator is a paginator for ListContactFlows
149type ListContactFlowsPaginator struct {
150	options   ListContactFlowsPaginatorOptions
151	client    ListContactFlowsAPIClient
152	params    *ListContactFlowsInput
153	nextToken *string
154	firstPage bool
155}
156
157// NewListContactFlowsPaginator returns a new ListContactFlowsPaginator
158func NewListContactFlowsPaginator(client ListContactFlowsAPIClient, params *ListContactFlowsInput, optFns ...func(*ListContactFlowsPaginatorOptions)) *ListContactFlowsPaginator {
159	if params == nil {
160		params = &ListContactFlowsInput{}
161	}
162
163	options := ListContactFlowsPaginatorOptions{}
164	if params.MaxResults != 0 {
165		options.Limit = params.MaxResults
166	}
167
168	for _, fn := range optFns {
169		fn(&options)
170	}
171
172	return &ListContactFlowsPaginator{
173		options:   options,
174		client:    client,
175		params:    params,
176		firstPage: true,
177	}
178}
179
180// HasMorePages returns a boolean indicating whether more pages are available
181func (p *ListContactFlowsPaginator) HasMorePages() bool {
182	return p.firstPage || p.nextToken != nil
183}
184
185// NextPage retrieves the next ListContactFlows page.
186func (p *ListContactFlowsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListContactFlowsOutput, error) {
187	if !p.HasMorePages() {
188		return nil, fmt.Errorf("no more pages available")
189	}
190
191	params := *p.params
192	params.NextToken = p.nextToken
193
194	params.MaxResults = p.options.Limit
195
196	result, err := p.client.ListContactFlows(ctx, &params, optFns...)
197	if err != nil {
198		return nil, err
199	}
200	p.firstPage = false
201
202	prevToken := p.nextToken
203	p.nextToken = result.NextToken
204
205	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
206		p.nextToken = nil
207	}
208
209	return result, nil
210}
211
212func newServiceMetadataMiddleware_opListContactFlows(region string) *awsmiddleware.RegisterServiceMetadata {
213	return &awsmiddleware.RegisterServiceMetadata{
214		Region:        region,
215		ServiceID:     ServiceID,
216		SigningName:   "connect",
217		OperationName: "ListContactFlows",
218	}
219}
220