1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package devicefarm
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/devicefarm/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Gets the current status and future status of all offerings purchased by an AWS
16// account. The response indicates how many offerings are currently available and
17// the offerings that will be available in the next period. The API returns a
18// NotEligible error if the user is not permitted to invoke the operation. If you
19// must be able to invoke this operation, contact aws-devicefarm-support@amazon.com
20// (mailto:aws-devicefarm-support@amazon.com).
21func (c *Client) GetOfferingStatus(ctx context.Context, params *GetOfferingStatusInput, optFns ...func(*Options)) (*GetOfferingStatusOutput, error) {
22	if params == nil {
23		params = &GetOfferingStatusInput{}
24	}
25
26	result, metadata, err := c.invokeOperation(ctx, "GetOfferingStatus", params, optFns, addOperationGetOfferingStatusMiddlewares)
27	if err != nil {
28		return nil, err
29	}
30
31	out := result.(*GetOfferingStatusOutput)
32	out.ResultMetadata = metadata
33	return out, nil
34}
35
36// Represents the request to retrieve the offering status for the specified
37// customer or account.
38type GetOfferingStatusInput struct {
39
40	// An identifier that was returned from the previous call to this operation, which
41	// can be used to return the next set of items in the list.
42	NextToken *string
43}
44
45// Returns the status result for a device offering.
46type GetOfferingStatusOutput struct {
47
48	// When specified, gets the offering status for the current period.
49	Current map[string]types.OfferingStatus
50
51	// When specified, gets the offering status for the next period.
52	NextPeriod map[string]types.OfferingStatus
53
54	// An identifier that was returned from the previous call to this operation, which
55	// can be used to return the next set of items in the list.
56	NextToken *string
57
58	// Metadata pertaining to the operation's result.
59	ResultMetadata middleware.Metadata
60}
61
62func addOperationGetOfferingStatusMiddlewares(stack *middleware.Stack, options Options) (err error) {
63	err = stack.Serialize.Add(&awsAwsjson11_serializeOpGetOfferingStatus{}, middleware.After)
64	if err != nil {
65		return err
66	}
67	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpGetOfferingStatus{}, middleware.After)
68	if err != nil {
69		return err
70	}
71	if err = addSetLoggerMiddleware(stack, options); err != nil {
72		return err
73	}
74	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
75		return err
76	}
77	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
78		return err
79	}
80	if err = addResolveEndpointMiddleware(stack, options); err != nil {
81		return err
82	}
83	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
84		return err
85	}
86	if err = addRetryMiddlewares(stack, options); err != nil {
87		return err
88	}
89	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
90		return err
91	}
92	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
93		return err
94	}
95	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
96		return err
97	}
98	if err = addClientUserAgent(stack); err != nil {
99		return err
100	}
101	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
102		return err
103	}
104	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
105		return err
106	}
107	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetOfferingStatus(options.Region), middleware.Before); err != nil {
108		return err
109	}
110	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
111		return err
112	}
113	if err = addResponseErrorMiddleware(stack); err != nil {
114		return err
115	}
116	if err = addRequestResponseLogging(stack, options); err != nil {
117		return err
118	}
119	return nil
120}
121
122// GetOfferingStatusAPIClient is a client that implements the GetOfferingStatus
123// operation.
124type GetOfferingStatusAPIClient interface {
125	GetOfferingStatus(context.Context, *GetOfferingStatusInput, ...func(*Options)) (*GetOfferingStatusOutput, error)
126}
127
128var _ GetOfferingStatusAPIClient = (*Client)(nil)
129
130// GetOfferingStatusPaginatorOptions is the paginator options for GetOfferingStatus
131type GetOfferingStatusPaginatorOptions struct {
132	// Set to true if pagination should stop if the service returns a pagination token
133	// that matches the most recent token provided to the service.
134	StopOnDuplicateToken bool
135}
136
137// GetOfferingStatusPaginator is a paginator for GetOfferingStatus
138type GetOfferingStatusPaginator struct {
139	options   GetOfferingStatusPaginatorOptions
140	client    GetOfferingStatusAPIClient
141	params    *GetOfferingStatusInput
142	nextToken *string
143	firstPage bool
144}
145
146// NewGetOfferingStatusPaginator returns a new GetOfferingStatusPaginator
147func NewGetOfferingStatusPaginator(client GetOfferingStatusAPIClient, params *GetOfferingStatusInput, optFns ...func(*GetOfferingStatusPaginatorOptions)) *GetOfferingStatusPaginator {
148	if params == nil {
149		params = &GetOfferingStatusInput{}
150	}
151
152	options := GetOfferingStatusPaginatorOptions{}
153
154	for _, fn := range optFns {
155		fn(&options)
156	}
157
158	return &GetOfferingStatusPaginator{
159		options:   options,
160		client:    client,
161		params:    params,
162		firstPage: true,
163	}
164}
165
166// HasMorePages returns a boolean indicating whether more pages are available
167func (p *GetOfferingStatusPaginator) HasMorePages() bool {
168	return p.firstPage || p.nextToken != nil
169}
170
171// NextPage retrieves the next GetOfferingStatus page.
172func (p *GetOfferingStatusPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*GetOfferingStatusOutput, error) {
173	if !p.HasMorePages() {
174		return nil, fmt.Errorf("no more pages available")
175	}
176
177	params := *p.params
178	params.NextToken = p.nextToken
179
180	result, err := p.client.GetOfferingStatus(ctx, &params, optFns...)
181	if err != nil {
182		return nil, err
183	}
184	p.firstPage = false
185
186	prevToken := p.nextToken
187	p.nextToken = result.NextToken
188
189	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
190		p.nextToken = nil
191	}
192
193	return result, nil
194}
195
196func newServiceMetadataMiddleware_opGetOfferingStatus(region string) *awsmiddleware.RegisterServiceMetadata {
197	return &awsmiddleware.RegisterServiceMetadata{
198		Region:        region,
199		ServiceID:     ServiceID,
200		SigningName:   "devicefarm",
201		OperationName: "GetOfferingStatus",
202	}
203}
204