1package marketplaceordering
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"encoding/json"
23	"github.com/Azure/go-autorest/autorest"
24	"github.com/Azure/go-autorest/autorest/date"
25	"github.com/Azure/go-autorest/autorest/to"
26	"github.com/Azure/go-autorest/tracing"
27	"net/http"
28)
29
30// The package's fully qualified name.
31const fqdn = "github.com/Azure/azure-sdk-for-go/services/marketplaceordering/mgmt/2015-06-01/marketplaceordering"
32
33// AgreementProperties agreement Terms definition
34type AgreementProperties struct {
35	// Publisher - Publisher identifier string of image being deployed.
36	Publisher *string `json:"publisher,omitempty"`
37	// Product - Offer identifier string of image being deployed.
38	Product *string `json:"product,omitempty"`
39	// Plan - Plan identifier string of image being deployed.
40	Plan *string `json:"plan,omitempty"`
41	// LicenseTextLink - Link to HTML with Microsoft and Publisher terms.
42	LicenseTextLink *string `json:"licenseTextLink,omitempty"`
43	// PrivacyPolicyLink - Link to the privacy policy of the publisher.
44	PrivacyPolicyLink *string `json:"privacyPolicyLink,omitempty"`
45	// RetrieveDatetime - Date and time in UTC of when the terms were accepted. This is empty if Accepted is false.
46	RetrieveDatetime *date.Time `json:"retrieveDatetime,omitempty"`
47	// Signature - Terms signature.
48	Signature *string `json:"signature,omitempty"`
49	// Accepted - If any version of the terms have been accepted, otherwise false.
50	Accepted *bool `json:"accepted,omitempty"`
51}
52
53// AgreementTerms terms properties for provided Publisher/Offer/Plan tuple
54type AgreementTerms struct {
55	autorest.Response `json:"-"`
56	// AgreementProperties - Represents the properties of the resource.
57	*AgreementProperties `json:"properties,omitempty"`
58	// ID - READ-ONLY; Resource ID.
59	ID *string `json:"id,omitempty"`
60	// Name - READ-ONLY; Resource name.
61	Name *string `json:"name,omitempty"`
62	// Type - READ-ONLY; Resource type.
63	Type *string `json:"type,omitempty"`
64}
65
66// MarshalJSON is the custom marshaler for AgreementTerms.
67func (at AgreementTerms) MarshalJSON() ([]byte, error) {
68	objectMap := make(map[string]interface{})
69	if at.AgreementProperties != nil {
70		objectMap["properties"] = at.AgreementProperties
71	}
72	return json.Marshal(objectMap)
73}
74
75// UnmarshalJSON is the custom unmarshaler for AgreementTerms struct.
76func (at *AgreementTerms) UnmarshalJSON(body []byte) error {
77	var m map[string]*json.RawMessage
78	err := json.Unmarshal(body, &m)
79	if err != nil {
80		return err
81	}
82	for k, v := range m {
83		switch k {
84		case "properties":
85			if v != nil {
86				var agreementProperties AgreementProperties
87				err = json.Unmarshal(*v, &agreementProperties)
88				if err != nil {
89					return err
90				}
91				at.AgreementProperties = &agreementProperties
92			}
93		case "id":
94			if v != nil {
95				var ID string
96				err = json.Unmarshal(*v, &ID)
97				if err != nil {
98					return err
99				}
100				at.ID = &ID
101			}
102		case "name":
103			if v != nil {
104				var name string
105				err = json.Unmarshal(*v, &name)
106				if err != nil {
107					return err
108				}
109				at.Name = &name
110			}
111		case "type":
112			if v != nil {
113				var typeVar string
114				err = json.Unmarshal(*v, &typeVar)
115				if err != nil {
116					return err
117				}
118				at.Type = &typeVar
119			}
120		}
121	}
122
123	return nil
124}
125
126// ErrorResponse error response indicates Microsoft.MarketplaceOrdering service is not able to process the
127// incoming request. The reason is provided in the error message.
128type ErrorResponse struct {
129	// Error - The details of the error.
130	Error *ErrorResponseError `json:"error,omitempty"`
131}
132
133// ErrorResponseError the details of the error.
134type ErrorResponseError struct {
135	// Code - READ-ONLY; Error code.
136	Code *string `json:"code,omitempty"`
137	// Message - READ-ONLY; Error message indicating why the operation failed.
138	Message *string `json:"message,omitempty"`
139}
140
141// ListAgreementTerms ...
142type ListAgreementTerms struct {
143	autorest.Response `json:"-"`
144	Value             *[]AgreementTerms `json:"value,omitempty"`
145}
146
147// Operation microsoft.MarketplaceOrdering REST API operation
148type Operation struct {
149	// Name - Operation name: {provider}/{resource}/{operation}
150	Name *string `json:"name,omitempty"`
151	// Display - The object that represents the operation.
152	Display *OperationDisplay `json:"display,omitempty"`
153}
154
155// OperationDisplay the object that represents the operation.
156type OperationDisplay struct {
157	// Provider - Service provider: Microsoft.MarketplaceOrdering
158	Provider *string `json:"provider,omitempty"`
159	// Resource - Resource on which the operation is performed: Agreement, virtualmachine, etc.
160	Resource *string `json:"resource,omitempty"`
161	// Operation - Operation type: Get Agreement, Sign Agreement, Cancel Agreement etc.
162	Operation *string `json:"operation,omitempty"`
163}
164
165// OperationListResult result of the request to list MarketplaceOrdering operations. It contains a list of
166// operations and a URL link to get the next set of results.
167type OperationListResult struct {
168	autorest.Response `json:"-"`
169	// Value - List of Microsoft.MarketplaceOrdering operations supported by the Microsoft.MarketplaceOrdering resource provider.
170	Value *[]Operation `json:"value,omitempty"`
171	// NextLink - READ-ONLY; URL to get the next set of operation list results if there are any.
172	NextLink *string `json:"nextLink,omitempty"`
173}
174
175// OperationListResultIterator provides access to a complete listing of Operation values.
176type OperationListResultIterator struct {
177	i    int
178	page OperationListResultPage
179}
180
181// NextWithContext advances to the next value.  If there was an error making
182// the request the iterator does not advance and the error is returned.
183func (iter *OperationListResultIterator) NextWithContext(ctx context.Context) (err error) {
184	if tracing.IsEnabled() {
185		ctx = tracing.StartSpan(ctx, fqdn+"/OperationListResultIterator.NextWithContext")
186		defer func() {
187			sc := -1
188			if iter.Response().Response.Response != nil {
189				sc = iter.Response().Response.Response.StatusCode
190			}
191			tracing.EndSpan(ctx, sc, err)
192		}()
193	}
194	iter.i++
195	if iter.i < len(iter.page.Values()) {
196		return nil
197	}
198	err = iter.page.NextWithContext(ctx)
199	if err != nil {
200		iter.i--
201		return err
202	}
203	iter.i = 0
204	return nil
205}
206
207// Next advances to the next value.  If there was an error making
208// the request the iterator does not advance and the error is returned.
209// Deprecated: Use NextWithContext() instead.
210func (iter *OperationListResultIterator) Next() error {
211	return iter.NextWithContext(context.Background())
212}
213
214// NotDone returns true if the enumeration should be started or is not yet complete.
215func (iter OperationListResultIterator) NotDone() bool {
216	return iter.page.NotDone() && iter.i < len(iter.page.Values())
217}
218
219// Response returns the raw server response from the last page request.
220func (iter OperationListResultIterator) Response() OperationListResult {
221	return iter.page.Response()
222}
223
224// Value returns the current value or a zero-initialized value if the
225// iterator has advanced beyond the end of the collection.
226func (iter OperationListResultIterator) Value() Operation {
227	if !iter.page.NotDone() {
228		return Operation{}
229	}
230	return iter.page.Values()[iter.i]
231}
232
233// Creates a new instance of the OperationListResultIterator type.
234func NewOperationListResultIterator(page OperationListResultPage) OperationListResultIterator {
235	return OperationListResultIterator{page: page}
236}
237
238// IsEmpty returns true if the ListResult contains no values.
239func (olr OperationListResult) IsEmpty() bool {
240	return olr.Value == nil || len(*olr.Value) == 0
241}
242
243// operationListResultPreparer prepares a request to retrieve the next set of results.
244// It returns nil if no more results exist.
245func (olr OperationListResult) operationListResultPreparer(ctx context.Context) (*http.Request, error) {
246	if olr.NextLink == nil || len(to.String(olr.NextLink)) < 1 {
247		return nil, nil
248	}
249	return autorest.Prepare((&http.Request{}).WithContext(ctx),
250		autorest.AsJSON(),
251		autorest.AsGet(),
252		autorest.WithBaseURL(to.String(olr.NextLink)))
253}
254
255// OperationListResultPage contains a page of Operation values.
256type OperationListResultPage struct {
257	fn  func(context.Context, OperationListResult) (OperationListResult, error)
258	olr OperationListResult
259}
260
261// NextWithContext advances to the next page of values.  If there was an error making
262// the request the page does not advance and the error is returned.
263func (page *OperationListResultPage) NextWithContext(ctx context.Context) (err error) {
264	if tracing.IsEnabled() {
265		ctx = tracing.StartSpan(ctx, fqdn+"/OperationListResultPage.NextWithContext")
266		defer func() {
267			sc := -1
268			if page.Response().Response.Response != nil {
269				sc = page.Response().Response.Response.StatusCode
270			}
271			tracing.EndSpan(ctx, sc, err)
272		}()
273	}
274	next, err := page.fn(ctx, page.olr)
275	if err != nil {
276		return err
277	}
278	page.olr = next
279	return nil
280}
281
282// Next advances to the next page of values.  If there was an error making
283// the request the page does not advance and the error is returned.
284// Deprecated: Use NextWithContext() instead.
285func (page *OperationListResultPage) Next() error {
286	return page.NextWithContext(context.Background())
287}
288
289// NotDone returns true if the page enumeration should be started or is not yet complete.
290func (page OperationListResultPage) NotDone() bool {
291	return !page.olr.IsEmpty()
292}
293
294// Response returns the raw server response from the last page request.
295func (page OperationListResultPage) Response() OperationListResult {
296	return page.olr
297}
298
299// Values returns the slice of values for the current page or nil if there are no values.
300func (page OperationListResultPage) Values() []Operation {
301	if page.olr.IsEmpty() {
302		return nil
303	}
304	return *page.olr.Value
305}
306
307// Creates a new instance of the OperationListResultPage type.
308func NewOperationListResultPage(getNextPage func(context.Context, OperationListResult) (OperationListResult, error)) OperationListResultPage {
309	return OperationListResultPage{fn: getNextPage}
310}
311
312// Resource ARM resource.
313type Resource struct {
314	// ID - READ-ONLY; Resource ID.
315	ID *string `json:"id,omitempty"`
316	// Name - READ-ONLY; Resource name.
317	Name *string `json:"name,omitempty"`
318	// Type - READ-ONLY; Resource type.
319	Type *string `json:"type,omitempty"`
320}
321