1package apimanagement
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// APIVersionSetClient is the apiManagement Client
19type APIVersionSetClient struct {
20	BaseClient
21}
22
23// NewAPIVersionSetClient creates an instance of the APIVersionSetClient client.
24func NewAPIVersionSetClient(subscriptionID string) APIVersionSetClient {
25	return NewAPIVersionSetClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewAPIVersionSetClientWithBaseURI creates an instance of the APIVersionSetClient client using a custom endpoint.
29// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewAPIVersionSetClientWithBaseURI(baseURI string, subscriptionID string) APIVersionSetClient {
31	return APIVersionSetClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CreateOrUpdate creates or Updates a Api Version Set.
35// Parameters:
36// resourceGroupName - the name of the resource group.
37// serviceName - the name of the API Management service.
38// versionSetID - api Version Set identifier. Must be unique in the current API Management service instance.
39// parameters - create or update parameters.
40// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
41func (client APIVersionSetClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, versionSetID string, parameters APIVersionSetContract, ifMatch string) (result APIVersionSetContract, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/APIVersionSetClient.CreateOrUpdate")
44		defer func() {
45			sc := -1
46			if result.Response.Response != nil {
47				sc = result.Response.Response.StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	if err := validation.Validate([]validation.Validation{
53		{TargetValue: serviceName,
54			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
55				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
56				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
57		{TargetValue: versionSetID,
58			Constraints: []validation.Constraint{{Target: "versionSetID", Name: validation.MaxLength, Rule: 80, Chain: nil},
59				{Target: "versionSetID", Name: validation.MinLength, Rule: 1, Chain: nil},
60				{Target: "versionSetID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
61		{TargetValue: parameters,
62			Constraints: []validation.Constraint{{Target: "parameters.APIVersionSetContractProperties", Name: validation.Null, Rule: false,
63				Chain: []validation.Constraint{{Target: "parameters.APIVersionSetContractProperties.DisplayName", Name: validation.Null, Rule: true,
64					Chain: []validation.Constraint{{Target: "parameters.APIVersionSetContractProperties.DisplayName", Name: validation.MaxLength, Rule: 100, Chain: nil},
65						{Target: "parameters.APIVersionSetContractProperties.DisplayName", Name: validation.MinLength, Rule: 1, Chain: nil},
66					}},
67				}}}}}); err != nil {
68		return result, validation.NewError("apimanagement.APIVersionSetClient", "CreateOrUpdate", err.Error())
69	}
70
71	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, versionSetID, parameters, ifMatch)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "CreateOrUpdate", nil, "Failure preparing request")
74		return
75	}
76
77	resp, err := client.CreateOrUpdateSender(req)
78	if err != nil {
79		result.Response = autorest.Response{Response: resp}
80		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "CreateOrUpdate", resp, "Failure sending request")
81		return
82	}
83
84	result, err = client.CreateOrUpdateResponder(resp)
85	if err != nil {
86		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "CreateOrUpdate", resp, "Failure responding to request")
87		return
88	}
89
90	return
91}
92
93// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
94func (client APIVersionSetClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, versionSetID string, parameters APIVersionSetContract, ifMatch string) (*http.Request, error) {
95	pathParameters := map[string]interface{}{
96		"resourceGroupName": autorest.Encode("path", resourceGroupName),
97		"serviceName":       autorest.Encode("path", serviceName),
98		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
99		"versionSetId":      autorest.Encode("path", versionSetID),
100	}
101
102	const APIVersion = "2018-06-01-preview"
103	queryParameters := map[string]interface{}{
104		"api-version": APIVersion,
105	}
106
107	preparer := autorest.CreatePreparer(
108		autorest.AsContentType("application/json; charset=utf-8"),
109		autorest.AsPut(),
110		autorest.WithBaseURL(client.BaseURI),
111		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/api-version-sets/{versionSetId}", pathParameters),
112		autorest.WithJSON(parameters),
113		autorest.WithQueryParameters(queryParameters))
114	if len(ifMatch) > 0 {
115		preparer = autorest.DecoratePreparer(preparer,
116			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
117	}
118	return preparer.Prepare((&http.Request{}).WithContext(ctx))
119}
120
121// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
122// http.Response Body if it receives an error.
123func (client APIVersionSetClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
124	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
125}
126
127// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
128// closes the http.Response Body.
129func (client APIVersionSetClient) CreateOrUpdateResponder(resp *http.Response) (result APIVersionSetContract, err error) {
130	err = autorest.Respond(
131		resp,
132		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
133		autorest.ByUnmarshallingJSON(&result),
134		autorest.ByClosing())
135	result.Response = autorest.Response{Response: resp}
136	return
137}
138
139// Delete deletes specific Api Version Set.
140// Parameters:
141// resourceGroupName - the name of the resource group.
142// serviceName - the name of the API Management service.
143// versionSetID - api Version Set identifier. Must be unique in the current API Management service instance.
144// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
145// request or it should be * for unconditional update.
146func (client APIVersionSetClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, versionSetID string, ifMatch string) (result autorest.Response, err error) {
147	if tracing.IsEnabled() {
148		ctx = tracing.StartSpan(ctx, fqdn+"/APIVersionSetClient.Delete")
149		defer func() {
150			sc := -1
151			if result.Response != nil {
152				sc = result.Response.StatusCode
153			}
154			tracing.EndSpan(ctx, sc, err)
155		}()
156	}
157	if err := validation.Validate([]validation.Validation{
158		{TargetValue: serviceName,
159			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
160				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
161				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
162		{TargetValue: versionSetID,
163			Constraints: []validation.Constraint{{Target: "versionSetID", Name: validation.MaxLength, Rule: 80, Chain: nil},
164				{Target: "versionSetID", Name: validation.MinLength, Rule: 1, Chain: nil},
165				{Target: "versionSetID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
166		return result, validation.NewError("apimanagement.APIVersionSetClient", "Delete", err.Error())
167	}
168
169	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, versionSetID, ifMatch)
170	if err != nil {
171		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "Delete", nil, "Failure preparing request")
172		return
173	}
174
175	resp, err := client.DeleteSender(req)
176	if err != nil {
177		result.Response = resp
178		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "Delete", resp, "Failure sending request")
179		return
180	}
181
182	result, err = client.DeleteResponder(resp)
183	if err != nil {
184		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "Delete", resp, "Failure responding to request")
185		return
186	}
187
188	return
189}
190
191// DeletePreparer prepares the Delete request.
192func (client APIVersionSetClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, versionSetID string, ifMatch string) (*http.Request, error) {
193	pathParameters := map[string]interface{}{
194		"resourceGroupName": autorest.Encode("path", resourceGroupName),
195		"serviceName":       autorest.Encode("path", serviceName),
196		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
197		"versionSetId":      autorest.Encode("path", versionSetID),
198	}
199
200	const APIVersion = "2018-06-01-preview"
201	queryParameters := map[string]interface{}{
202		"api-version": APIVersion,
203	}
204
205	preparer := autorest.CreatePreparer(
206		autorest.AsDelete(),
207		autorest.WithBaseURL(client.BaseURI),
208		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/api-version-sets/{versionSetId}", pathParameters),
209		autorest.WithQueryParameters(queryParameters),
210		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
211	return preparer.Prepare((&http.Request{}).WithContext(ctx))
212}
213
214// DeleteSender sends the Delete request. The method will close the
215// http.Response Body if it receives an error.
216func (client APIVersionSetClient) DeleteSender(req *http.Request) (*http.Response, error) {
217	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
218}
219
220// DeleteResponder handles the response to the Delete request. The method always
221// closes the http.Response Body.
222func (client APIVersionSetClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
223	err = autorest.Respond(
224		resp,
225		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
226		autorest.ByClosing())
227	result.Response = resp
228	return
229}
230
231// Get gets the details of the Api Version Set specified by its identifier.
232// Parameters:
233// resourceGroupName - the name of the resource group.
234// serviceName - the name of the API Management service.
235// versionSetID - api Version Set identifier. Must be unique in the current API Management service instance.
236func (client APIVersionSetClient) Get(ctx context.Context, resourceGroupName string, serviceName string, versionSetID string) (result APIVersionSetContract, err error) {
237	if tracing.IsEnabled() {
238		ctx = tracing.StartSpan(ctx, fqdn+"/APIVersionSetClient.Get")
239		defer func() {
240			sc := -1
241			if result.Response.Response != nil {
242				sc = result.Response.Response.StatusCode
243			}
244			tracing.EndSpan(ctx, sc, err)
245		}()
246	}
247	if err := validation.Validate([]validation.Validation{
248		{TargetValue: serviceName,
249			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
250				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
251				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
252		{TargetValue: versionSetID,
253			Constraints: []validation.Constraint{{Target: "versionSetID", Name: validation.MaxLength, Rule: 80, Chain: nil},
254				{Target: "versionSetID", Name: validation.MinLength, Rule: 1, Chain: nil},
255				{Target: "versionSetID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
256		return result, validation.NewError("apimanagement.APIVersionSetClient", "Get", err.Error())
257	}
258
259	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, versionSetID)
260	if err != nil {
261		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "Get", nil, "Failure preparing request")
262		return
263	}
264
265	resp, err := client.GetSender(req)
266	if err != nil {
267		result.Response = autorest.Response{Response: resp}
268		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "Get", resp, "Failure sending request")
269		return
270	}
271
272	result, err = client.GetResponder(resp)
273	if err != nil {
274		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "Get", resp, "Failure responding to request")
275		return
276	}
277
278	return
279}
280
281// GetPreparer prepares the Get request.
282func (client APIVersionSetClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, versionSetID string) (*http.Request, error) {
283	pathParameters := map[string]interface{}{
284		"resourceGroupName": autorest.Encode("path", resourceGroupName),
285		"serviceName":       autorest.Encode("path", serviceName),
286		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
287		"versionSetId":      autorest.Encode("path", versionSetID),
288	}
289
290	const APIVersion = "2018-06-01-preview"
291	queryParameters := map[string]interface{}{
292		"api-version": APIVersion,
293	}
294
295	preparer := autorest.CreatePreparer(
296		autorest.AsGet(),
297		autorest.WithBaseURL(client.BaseURI),
298		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/api-version-sets/{versionSetId}", pathParameters),
299		autorest.WithQueryParameters(queryParameters))
300	return preparer.Prepare((&http.Request{}).WithContext(ctx))
301}
302
303// GetSender sends the Get request. The method will close the
304// http.Response Body if it receives an error.
305func (client APIVersionSetClient) GetSender(req *http.Request) (*http.Response, error) {
306	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
307}
308
309// GetResponder handles the response to the Get request. The method always
310// closes the http.Response Body.
311func (client APIVersionSetClient) GetResponder(resp *http.Response) (result APIVersionSetContract, err error) {
312	err = autorest.Respond(
313		resp,
314		azure.WithErrorUnlessStatusCode(http.StatusOK),
315		autorest.ByUnmarshallingJSON(&result),
316		autorest.ByClosing())
317	result.Response = autorest.Response{Response: resp}
318	return
319}
320
321// GetEntityTag gets the entity state (Etag) version of the Api Version Set specified by its identifier.
322// Parameters:
323// resourceGroupName - the name of the resource group.
324// serviceName - the name of the API Management service.
325// versionSetID - api Version Set identifier. Must be unique in the current API Management service instance.
326func (client APIVersionSetClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, versionSetID string) (result autorest.Response, err error) {
327	if tracing.IsEnabled() {
328		ctx = tracing.StartSpan(ctx, fqdn+"/APIVersionSetClient.GetEntityTag")
329		defer func() {
330			sc := -1
331			if result.Response != nil {
332				sc = result.Response.StatusCode
333			}
334			tracing.EndSpan(ctx, sc, err)
335		}()
336	}
337	if err := validation.Validate([]validation.Validation{
338		{TargetValue: serviceName,
339			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
340				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
341				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
342		{TargetValue: versionSetID,
343			Constraints: []validation.Constraint{{Target: "versionSetID", Name: validation.MaxLength, Rule: 80, Chain: nil},
344				{Target: "versionSetID", Name: validation.MinLength, Rule: 1, Chain: nil},
345				{Target: "versionSetID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
346		return result, validation.NewError("apimanagement.APIVersionSetClient", "GetEntityTag", err.Error())
347	}
348
349	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, versionSetID)
350	if err != nil {
351		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "GetEntityTag", nil, "Failure preparing request")
352		return
353	}
354
355	resp, err := client.GetEntityTagSender(req)
356	if err != nil {
357		result.Response = resp
358		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "GetEntityTag", resp, "Failure sending request")
359		return
360	}
361
362	result, err = client.GetEntityTagResponder(resp)
363	if err != nil {
364		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "GetEntityTag", resp, "Failure responding to request")
365		return
366	}
367
368	return
369}
370
371// GetEntityTagPreparer prepares the GetEntityTag request.
372func (client APIVersionSetClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, versionSetID string) (*http.Request, error) {
373	pathParameters := map[string]interface{}{
374		"resourceGroupName": autorest.Encode("path", resourceGroupName),
375		"serviceName":       autorest.Encode("path", serviceName),
376		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
377		"versionSetId":      autorest.Encode("path", versionSetID),
378	}
379
380	const APIVersion = "2018-06-01-preview"
381	queryParameters := map[string]interface{}{
382		"api-version": APIVersion,
383	}
384
385	preparer := autorest.CreatePreparer(
386		autorest.AsHead(),
387		autorest.WithBaseURL(client.BaseURI),
388		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/api-version-sets/{versionSetId}", pathParameters),
389		autorest.WithQueryParameters(queryParameters))
390	return preparer.Prepare((&http.Request{}).WithContext(ctx))
391}
392
393// GetEntityTagSender sends the GetEntityTag request. The method will close the
394// http.Response Body if it receives an error.
395func (client APIVersionSetClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
396	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
397}
398
399// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
400// closes the http.Response Body.
401func (client APIVersionSetClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
402	err = autorest.Respond(
403		resp,
404		azure.WithErrorUnlessStatusCode(http.StatusOK),
405		autorest.ByClosing())
406	result.Response = resp
407	return
408}
409
410// ListByService lists a collection of API Version Sets in the specified service instance.
411// Parameters:
412// resourceGroupName - the name of the resource group.
413// serviceName - the name of the API Management service.
414// filter - | Field       | Supported operators    | Supported functions               |
415// |-------------|------------------------|-----------------------------------|
416// top - number of records to return.
417// skip - number of records to skip.
418func (client APIVersionSetClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result APIVersionSetCollectionPage, err error) {
419	if tracing.IsEnabled() {
420		ctx = tracing.StartSpan(ctx, fqdn+"/APIVersionSetClient.ListByService")
421		defer func() {
422			sc := -1
423			if result.avsc.Response.Response != nil {
424				sc = result.avsc.Response.Response.StatusCode
425			}
426			tracing.EndSpan(ctx, sc, err)
427		}()
428	}
429	if err := validation.Validate([]validation.Validation{
430		{TargetValue: serviceName,
431			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
432				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
433				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
434		{TargetValue: top,
435			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
436				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
437		{TargetValue: skip,
438			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
439				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
440		return result, validation.NewError("apimanagement.APIVersionSetClient", "ListByService", err.Error())
441	}
442
443	result.fn = client.listByServiceNextResults
444	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
445	if err != nil {
446		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "ListByService", nil, "Failure preparing request")
447		return
448	}
449
450	resp, err := client.ListByServiceSender(req)
451	if err != nil {
452		result.avsc.Response = autorest.Response{Response: resp}
453		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "ListByService", resp, "Failure sending request")
454		return
455	}
456
457	result.avsc, err = client.ListByServiceResponder(resp)
458	if err != nil {
459		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "ListByService", resp, "Failure responding to request")
460		return
461	}
462	if result.avsc.hasNextLink() && result.avsc.IsEmpty() {
463		err = result.NextWithContext(ctx)
464		return
465	}
466
467	return
468}
469
470// ListByServicePreparer prepares the ListByService request.
471func (client APIVersionSetClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
472	pathParameters := map[string]interface{}{
473		"resourceGroupName": autorest.Encode("path", resourceGroupName),
474		"serviceName":       autorest.Encode("path", serviceName),
475		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
476	}
477
478	const APIVersion = "2018-06-01-preview"
479	queryParameters := map[string]interface{}{
480		"api-version": APIVersion,
481	}
482	if len(filter) > 0 {
483		queryParameters["$filter"] = autorest.Encode("query", filter)
484	}
485	if top != nil {
486		queryParameters["$top"] = autorest.Encode("query", *top)
487	}
488	if skip != nil {
489		queryParameters["$skip"] = autorest.Encode("query", *skip)
490	}
491
492	preparer := autorest.CreatePreparer(
493		autorest.AsGet(),
494		autorest.WithBaseURL(client.BaseURI),
495		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/api-version-sets", pathParameters),
496		autorest.WithQueryParameters(queryParameters))
497	return preparer.Prepare((&http.Request{}).WithContext(ctx))
498}
499
500// ListByServiceSender sends the ListByService request. The method will close the
501// http.Response Body if it receives an error.
502func (client APIVersionSetClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
503	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
504}
505
506// ListByServiceResponder handles the response to the ListByService request. The method always
507// closes the http.Response Body.
508func (client APIVersionSetClient) ListByServiceResponder(resp *http.Response) (result APIVersionSetCollection, err error) {
509	err = autorest.Respond(
510		resp,
511		azure.WithErrorUnlessStatusCode(http.StatusOK),
512		autorest.ByUnmarshallingJSON(&result),
513		autorest.ByClosing())
514	result.Response = autorest.Response{Response: resp}
515	return
516}
517
518// listByServiceNextResults retrieves the next set of results, if any.
519func (client APIVersionSetClient) listByServiceNextResults(ctx context.Context, lastResults APIVersionSetCollection) (result APIVersionSetCollection, err error) {
520	req, err := lastResults.aPIVersionSetCollectionPreparer(ctx)
521	if err != nil {
522		return result, autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "listByServiceNextResults", nil, "Failure preparing next results request")
523	}
524	if req == nil {
525		return
526	}
527	resp, err := client.ListByServiceSender(req)
528	if err != nil {
529		result.Response = autorest.Response{Response: resp}
530		return result, autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "listByServiceNextResults", resp, "Failure sending next results request")
531	}
532	result, err = client.ListByServiceResponder(resp)
533	if err != nil {
534		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "listByServiceNextResults", resp, "Failure responding to next results request")
535	}
536	return
537}
538
539// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
540func (client APIVersionSetClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result APIVersionSetCollectionIterator, err error) {
541	if tracing.IsEnabled() {
542		ctx = tracing.StartSpan(ctx, fqdn+"/APIVersionSetClient.ListByService")
543		defer func() {
544			sc := -1
545			if result.Response().Response.Response != nil {
546				sc = result.page.Response().Response.Response.StatusCode
547			}
548			tracing.EndSpan(ctx, sc, err)
549		}()
550	}
551	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip)
552	return
553}
554
555// Update updates the details of the Api VersionSet specified by its identifier.
556// Parameters:
557// resourceGroupName - the name of the resource group.
558// serviceName - the name of the API Management service.
559// versionSetID - api Version Set identifier. Must be unique in the current API Management service instance.
560// parameters - update parameters.
561// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
562// request or it should be * for unconditional update.
563func (client APIVersionSetClient) Update(ctx context.Context, resourceGroupName string, serviceName string, versionSetID string, parameters APIVersionSetUpdateParameters, ifMatch string) (result autorest.Response, err error) {
564	if tracing.IsEnabled() {
565		ctx = tracing.StartSpan(ctx, fqdn+"/APIVersionSetClient.Update")
566		defer func() {
567			sc := -1
568			if result.Response != nil {
569				sc = result.Response.StatusCode
570			}
571			tracing.EndSpan(ctx, sc, err)
572		}()
573	}
574	if err := validation.Validate([]validation.Validation{
575		{TargetValue: serviceName,
576			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
577				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
578				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
579		{TargetValue: versionSetID,
580			Constraints: []validation.Constraint{{Target: "versionSetID", Name: validation.MaxLength, Rule: 80, Chain: nil},
581				{Target: "versionSetID", Name: validation.MinLength, Rule: 1, Chain: nil},
582				{Target: "versionSetID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
583		return result, validation.NewError("apimanagement.APIVersionSetClient", "Update", err.Error())
584	}
585
586	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, versionSetID, parameters, ifMatch)
587	if err != nil {
588		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "Update", nil, "Failure preparing request")
589		return
590	}
591
592	resp, err := client.UpdateSender(req)
593	if err != nil {
594		result.Response = resp
595		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "Update", resp, "Failure sending request")
596		return
597	}
598
599	result, err = client.UpdateResponder(resp)
600	if err != nil {
601		err = autorest.NewErrorWithError(err, "apimanagement.APIVersionSetClient", "Update", resp, "Failure responding to request")
602		return
603	}
604
605	return
606}
607
608// UpdatePreparer prepares the Update request.
609func (client APIVersionSetClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, versionSetID string, parameters APIVersionSetUpdateParameters, ifMatch string) (*http.Request, error) {
610	pathParameters := map[string]interface{}{
611		"resourceGroupName": autorest.Encode("path", resourceGroupName),
612		"serviceName":       autorest.Encode("path", serviceName),
613		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
614		"versionSetId":      autorest.Encode("path", versionSetID),
615	}
616
617	const APIVersion = "2018-06-01-preview"
618	queryParameters := map[string]interface{}{
619		"api-version": APIVersion,
620	}
621
622	preparer := autorest.CreatePreparer(
623		autorest.AsContentType("application/json; charset=utf-8"),
624		autorest.AsPatch(),
625		autorest.WithBaseURL(client.BaseURI),
626		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/api-version-sets/{versionSetId}", pathParameters),
627		autorest.WithJSON(parameters),
628		autorest.WithQueryParameters(queryParameters),
629		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
630	return preparer.Prepare((&http.Request{}).WithContext(ctx))
631}
632
633// UpdateSender sends the Update request. The method will close the
634// http.Response Body if it receives an error.
635func (client APIVersionSetClient) UpdateSender(req *http.Request) (*http.Response, error) {
636	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
637}
638
639// UpdateResponder handles the response to the Update request. The method always
640// closes the http.Response Body.
641func (client APIVersionSetClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
642	err = autorest.Respond(
643		resp,
644		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
645		autorest.ByClosing())
646	result.Response = resp
647	return
648}
649