1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package servicecatalog
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/servicecatalog/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists all portfolios that the specified product is associated with.
16func (c *Client) ListPortfoliosForProduct(ctx context.Context, params *ListPortfoliosForProductInput, optFns ...func(*Options)) (*ListPortfoliosForProductOutput, error) {
17	if params == nil {
18		params = &ListPortfoliosForProductInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListPortfoliosForProduct", params, optFns, c.addOperationListPortfoliosForProductMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListPortfoliosForProductOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListPortfoliosForProductInput struct {
32
33	// The product identifier.
34	//
35	// This member is required.
36	ProductId *string
37
38	// The language code.
39	//
40	// * en - English (default)
41	//
42	// * jp - Japanese
43	//
44	// * zh - Chinese
45	AcceptLanguage *string
46
47	// The maximum number of items to return with this call.
48	PageSize int32
49
50	// The page token for the next set of results. To retrieve the first set of
51	// results, use null.
52	PageToken *string
53
54	noSmithyDocumentSerde
55}
56
57type ListPortfoliosForProductOutput struct {
58
59	// The page token to use to retrieve the next set of results. If there are no
60	// additional results, this value is null.
61	NextPageToken *string
62
63	// Information about the portfolios.
64	PortfolioDetails []types.PortfolioDetail
65
66	// Metadata pertaining to the operation's result.
67	ResultMetadata middleware.Metadata
68
69	noSmithyDocumentSerde
70}
71
72func (c *Client) addOperationListPortfoliosForProductMiddlewares(stack *middleware.Stack, options Options) (err error) {
73	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListPortfoliosForProduct{}, middleware.After)
74	if err != nil {
75		return err
76	}
77	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListPortfoliosForProduct{}, middleware.After)
78	if err != nil {
79		return err
80	}
81	if err = addSetLoggerMiddleware(stack, options); err != nil {
82		return err
83	}
84	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
85		return err
86	}
87	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
88		return err
89	}
90	if err = addResolveEndpointMiddleware(stack, options); err != nil {
91		return err
92	}
93	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
94		return err
95	}
96	if err = addRetryMiddlewares(stack, options); err != nil {
97		return err
98	}
99	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
100		return err
101	}
102	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
103		return err
104	}
105	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
106		return err
107	}
108	if err = addClientUserAgent(stack); err != nil {
109		return err
110	}
111	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
112		return err
113	}
114	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
115		return err
116	}
117	if err = addOpListPortfoliosForProductValidationMiddleware(stack); err != nil {
118		return err
119	}
120	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListPortfoliosForProduct(options.Region), middleware.Before); err != nil {
121		return err
122	}
123	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
124		return err
125	}
126	if err = addResponseErrorMiddleware(stack); err != nil {
127		return err
128	}
129	if err = addRequestResponseLogging(stack, options); err != nil {
130		return err
131	}
132	return nil
133}
134
135// ListPortfoliosForProductAPIClient is a client that implements the
136// ListPortfoliosForProduct operation.
137type ListPortfoliosForProductAPIClient interface {
138	ListPortfoliosForProduct(context.Context, *ListPortfoliosForProductInput, ...func(*Options)) (*ListPortfoliosForProductOutput, error)
139}
140
141var _ ListPortfoliosForProductAPIClient = (*Client)(nil)
142
143// ListPortfoliosForProductPaginatorOptions is the paginator options for
144// ListPortfoliosForProduct
145type ListPortfoliosForProductPaginatorOptions struct {
146	// The maximum number of items to return with this call.
147	Limit int32
148
149	// Set to true if pagination should stop if the service returns a pagination token
150	// that matches the most recent token provided to the service.
151	StopOnDuplicateToken bool
152}
153
154// ListPortfoliosForProductPaginator is a paginator for ListPortfoliosForProduct
155type ListPortfoliosForProductPaginator struct {
156	options   ListPortfoliosForProductPaginatorOptions
157	client    ListPortfoliosForProductAPIClient
158	params    *ListPortfoliosForProductInput
159	nextToken *string
160	firstPage bool
161}
162
163// NewListPortfoliosForProductPaginator returns a new
164// ListPortfoliosForProductPaginator
165func NewListPortfoliosForProductPaginator(client ListPortfoliosForProductAPIClient, params *ListPortfoliosForProductInput, optFns ...func(*ListPortfoliosForProductPaginatorOptions)) *ListPortfoliosForProductPaginator {
166	if params == nil {
167		params = &ListPortfoliosForProductInput{}
168	}
169
170	options := ListPortfoliosForProductPaginatorOptions{}
171	if params.PageSize != 0 {
172		options.Limit = params.PageSize
173	}
174
175	for _, fn := range optFns {
176		fn(&options)
177	}
178
179	return &ListPortfoliosForProductPaginator{
180		options:   options,
181		client:    client,
182		params:    params,
183		firstPage: true,
184	}
185}
186
187// HasMorePages returns a boolean indicating whether more pages are available
188func (p *ListPortfoliosForProductPaginator) HasMorePages() bool {
189	return p.firstPage || p.nextToken != nil
190}
191
192// NextPage retrieves the next ListPortfoliosForProduct page.
193func (p *ListPortfoliosForProductPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListPortfoliosForProductOutput, error) {
194	if !p.HasMorePages() {
195		return nil, fmt.Errorf("no more pages available")
196	}
197
198	params := *p.params
199	params.PageToken = p.nextToken
200
201	params.PageSize = p.options.Limit
202
203	result, err := p.client.ListPortfoliosForProduct(ctx, &params, optFns...)
204	if err != nil {
205		return nil, err
206	}
207	p.firstPage = false
208
209	prevToken := p.nextToken
210	p.nextToken = result.NextPageToken
211
212	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
213		p.nextToken = nil
214	}
215
216	return result, nil
217}
218
219func newServiceMetadataMiddleware_opListPortfoliosForProduct(region string) *awsmiddleware.RegisterServiceMetadata {
220	return &awsmiddleware.RegisterServiceMetadata{
221		Region:        region,
222		ServiceID:     ServiceID,
223		SigningName:   "servicecatalog",
224		OperationName: "ListPortfoliosForProduct",
225	}
226}
227