1package apimanagement
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	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// ProductClient is the apiManagement Client
30type ProductClient struct {
31	BaseClient
32}
33
34// NewProductClient creates an instance of the ProductClient client.
35func NewProductClient(subscriptionID string) ProductClient {
36	return NewProductClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewProductClientWithBaseURI creates an instance of the ProductClient client.
40func NewProductClientWithBaseURI(baseURI string, subscriptionID string) ProductClient {
41	return ProductClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// CreateOrUpdate creates or Updates a product.
45// Parameters:
46// resourceGroupName - the name of the resource group.
47// serviceName - the name of the API Management service.
48// productID - product identifier. Must be unique in the current API Management service instance.
49// parameters - create or update parameters.
50// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
51func (client ProductClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, productID string, parameters ProductContract, ifMatch string) (result ProductContract, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/ProductClient.CreateOrUpdate")
54		defer func() {
55			sc := -1
56			if result.Response.Response != nil {
57				sc = result.Response.Response.StatusCode
58			}
59			tracing.EndSpan(ctx, sc, err)
60		}()
61	}
62	if err := validation.Validate([]validation.Validation{
63		{TargetValue: serviceName,
64			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
65				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
66				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
67		{TargetValue: productID,
68			Constraints: []validation.Constraint{{Target: "productID", Name: validation.MaxLength, Rule: 256, Chain: nil},
69				{Target: "productID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
70		{TargetValue: parameters,
71			Constraints: []validation.Constraint{{Target: "parameters.ProductContractProperties", Name: validation.Null, Rule: false,
72				Chain: []validation.Constraint{{Target: "parameters.ProductContractProperties.DisplayName", Name: validation.Null, Rule: true,
73					Chain: []validation.Constraint{{Target: "parameters.ProductContractProperties.DisplayName", Name: validation.MaxLength, Rule: 300, Chain: nil},
74						{Target: "parameters.ProductContractProperties.DisplayName", Name: validation.MinLength, Rule: 1, Chain: nil},
75					}},
76				}}}}}); err != nil {
77		return result, validation.NewError("apimanagement.ProductClient", "CreateOrUpdate", err.Error())
78	}
79
80	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, productID, parameters, ifMatch)
81	if err != nil {
82		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "CreateOrUpdate", nil, "Failure preparing request")
83		return
84	}
85
86	resp, err := client.CreateOrUpdateSender(req)
87	if err != nil {
88		result.Response = autorest.Response{Response: resp}
89		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "CreateOrUpdate", resp, "Failure sending request")
90		return
91	}
92
93	result, err = client.CreateOrUpdateResponder(resp)
94	if err != nil {
95		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "CreateOrUpdate", resp, "Failure responding to request")
96	}
97
98	return
99}
100
101// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
102func (client ProductClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, productID string, parameters ProductContract, ifMatch string) (*http.Request, error) {
103	pathParameters := map[string]interface{}{
104		"productId":         autorest.Encode("path", productID),
105		"resourceGroupName": autorest.Encode("path", resourceGroupName),
106		"serviceName":       autorest.Encode("path", serviceName),
107		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
108	}
109
110	const APIVersion = "2019-01-01"
111	queryParameters := map[string]interface{}{
112		"api-version": APIVersion,
113	}
114
115	preparer := autorest.CreatePreparer(
116		autorest.AsContentType("application/json; charset=utf-8"),
117		autorest.AsPut(),
118		autorest.WithBaseURL(client.BaseURI),
119		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}", pathParameters),
120		autorest.WithJSON(parameters),
121		autorest.WithQueryParameters(queryParameters))
122	if len(ifMatch) > 0 {
123		preparer = autorest.DecoratePreparer(preparer,
124			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
125	}
126	return preparer.Prepare((&http.Request{}).WithContext(ctx))
127}
128
129// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
130// http.Response Body if it receives an error.
131func (client ProductClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
132	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
133	return autorest.SendWithSender(client, req, sd...)
134}
135
136// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
137// closes the http.Response Body.
138func (client ProductClient) CreateOrUpdateResponder(resp *http.Response) (result ProductContract, err error) {
139	err = autorest.Respond(
140		resp,
141		client.ByInspecting(),
142		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
143		autorest.ByUnmarshallingJSON(&result),
144		autorest.ByClosing())
145	result.Response = autorest.Response{Response: resp}
146	return
147}
148
149// Delete delete product.
150// Parameters:
151// resourceGroupName - the name of the resource group.
152// serviceName - the name of the API Management service.
153// productID - product identifier. Must be unique in the current API Management service instance.
154// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
155// request or it should be * for unconditional update.
156// deleteSubscriptions - delete existing subscriptions associated with the product or not.
157func (client ProductClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, productID string, ifMatch string, deleteSubscriptions *bool) (result autorest.Response, err error) {
158	if tracing.IsEnabled() {
159		ctx = tracing.StartSpan(ctx, fqdn+"/ProductClient.Delete")
160		defer func() {
161			sc := -1
162			if result.Response != nil {
163				sc = result.Response.StatusCode
164			}
165			tracing.EndSpan(ctx, sc, err)
166		}()
167	}
168	if err := validation.Validate([]validation.Validation{
169		{TargetValue: serviceName,
170			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
171				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
172				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
173		{TargetValue: productID,
174			Constraints: []validation.Constraint{{Target: "productID", Name: validation.MaxLength, Rule: 256, Chain: nil},
175				{Target: "productID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
176		return result, validation.NewError("apimanagement.ProductClient", "Delete", err.Error())
177	}
178
179	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, productID, ifMatch, deleteSubscriptions)
180	if err != nil {
181		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "Delete", nil, "Failure preparing request")
182		return
183	}
184
185	resp, err := client.DeleteSender(req)
186	if err != nil {
187		result.Response = resp
188		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "Delete", resp, "Failure sending request")
189		return
190	}
191
192	result, err = client.DeleteResponder(resp)
193	if err != nil {
194		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "Delete", resp, "Failure responding to request")
195	}
196
197	return
198}
199
200// DeletePreparer prepares the Delete request.
201func (client ProductClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, productID string, ifMatch string, deleteSubscriptions *bool) (*http.Request, error) {
202	pathParameters := map[string]interface{}{
203		"productId":         autorest.Encode("path", productID),
204		"resourceGroupName": autorest.Encode("path", resourceGroupName),
205		"serviceName":       autorest.Encode("path", serviceName),
206		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
207	}
208
209	const APIVersion = "2019-01-01"
210	queryParameters := map[string]interface{}{
211		"api-version": APIVersion,
212	}
213	if deleteSubscriptions != nil {
214		queryParameters["deleteSubscriptions"] = autorest.Encode("query", *deleteSubscriptions)
215	}
216
217	preparer := autorest.CreatePreparer(
218		autorest.AsDelete(),
219		autorest.WithBaseURL(client.BaseURI),
220		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}", pathParameters),
221		autorest.WithQueryParameters(queryParameters),
222		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
223	return preparer.Prepare((&http.Request{}).WithContext(ctx))
224}
225
226// DeleteSender sends the Delete request. The method will close the
227// http.Response Body if it receives an error.
228func (client ProductClient) DeleteSender(req *http.Request) (*http.Response, error) {
229	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
230	return autorest.SendWithSender(client, req, sd...)
231}
232
233// DeleteResponder handles the response to the Delete request. The method always
234// closes the http.Response Body.
235func (client ProductClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
236	err = autorest.Respond(
237		resp,
238		client.ByInspecting(),
239		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
240		autorest.ByClosing())
241	result.Response = resp
242	return
243}
244
245// Get gets the details of the product specified by its identifier.
246// Parameters:
247// resourceGroupName - the name of the resource group.
248// serviceName - the name of the API Management service.
249// productID - product identifier. Must be unique in the current API Management service instance.
250func (client ProductClient) Get(ctx context.Context, resourceGroupName string, serviceName string, productID string) (result ProductContract, err error) {
251	if tracing.IsEnabled() {
252		ctx = tracing.StartSpan(ctx, fqdn+"/ProductClient.Get")
253		defer func() {
254			sc := -1
255			if result.Response.Response != nil {
256				sc = result.Response.Response.StatusCode
257			}
258			tracing.EndSpan(ctx, sc, err)
259		}()
260	}
261	if err := validation.Validate([]validation.Validation{
262		{TargetValue: serviceName,
263			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
264				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
265				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
266		{TargetValue: productID,
267			Constraints: []validation.Constraint{{Target: "productID", Name: validation.MaxLength, Rule: 256, Chain: nil},
268				{Target: "productID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
269		return result, validation.NewError("apimanagement.ProductClient", "Get", err.Error())
270	}
271
272	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, productID)
273	if err != nil {
274		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "Get", nil, "Failure preparing request")
275		return
276	}
277
278	resp, err := client.GetSender(req)
279	if err != nil {
280		result.Response = autorest.Response{Response: resp}
281		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "Get", resp, "Failure sending request")
282		return
283	}
284
285	result, err = client.GetResponder(resp)
286	if err != nil {
287		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "Get", resp, "Failure responding to request")
288	}
289
290	return
291}
292
293// GetPreparer prepares the Get request.
294func (client ProductClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, productID string) (*http.Request, error) {
295	pathParameters := map[string]interface{}{
296		"productId":         autorest.Encode("path", productID),
297		"resourceGroupName": autorest.Encode("path", resourceGroupName),
298		"serviceName":       autorest.Encode("path", serviceName),
299		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
300	}
301
302	const APIVersion = "2019-01-01"
303	queryParameters := map[string]interface{}{
304		"api-version": APIVersion,
305	}
306
307	preparer := autorest.CreatePreparer(
308		autorest.AsGet(),
309		autorest.WithBaseURL(client.BaseURI),
310		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}", pathParameters),
311		autorest.WithQueryParameters(queryParameters))
312	return preparer.Prepare((&http.Request{}).WithContext(ctx))
313}
314
315// GetSender sends the Get request. The method will close the
316// http.Response Body if it receives an error.
317func (client ProductClient) GetSender(req *http.Request) (*http.Response, error) {
318	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
319	return autorest.SendWithSender(client, req, sd...)
320}
321
322// GetResponder handles the response to the Get request. The method always
323// closes the http.Response Body.
324func (client ProductClient) GetResponder(resp *http.Response) (result ProductContract, err error) {
325	err = autorest.Respond(
326		resp,
327		client.ByInspecting(),
328		azure.WithErrorUnlessStatusCode(http.StatusOK),
329		autorest.ByUnmarshallingJSON(&result),
330		autorest.ByClosing())
331	result.Response = autorest.Response{Response: resp}
332	return
333}
334
335// GetEntityTag gets the entity state (Etag) version of the product specified by its identifier.
336// Parameters:
337// resourceGroupName - the name of the resource group.
338// serviceName - the name of the API Management service.
339// productID - product identifier. Must be unique in the current API Management service instance.
340func (client ProductClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, productID string) (result autorest.Response, err error) {
341	if tracing.IsEnabled() {
342		ctx = tracing.StartSpan(ctx, fqdn+"/ProductClient.GetEntityTag")
343		defer func() {
344			sc := -1
345			if result.Response != nil {
346				sc = result.Response.StatusCode
347			}
348			tracing.EndSpan(ctx, sc, err)
349		}()
350	}
351	if err := validation.Validate([]validation.Validation{
352		{TargetValue: serviceName,
353			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
354				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
355				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
356		{TargetValue: productID,
357			Constraints: []validation.Constraint{{Target: "productID", Name: validation.MaxLength, Rule: 256, Chain: nil},
358				{Target: "productID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
359		return result, validation.NewError("apimanagement.ProductClient", "GetEntityTag", err.Error())
360	}
361
362	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, productID)
363	if err != nil {
364		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "GetEntityTag", nil, "Failure preparing request")
365		return
366	}
367
368	resp, err := client.GetEntityTagSender(req)
369	if err != nil {
370		result.Response = resp
371		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "GetEntityTag", resp, "Failure sending request")
372		return
373	}
374
375	result, err = client.GetEntityTagResponder(resp)
376	if err != nil {
377		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "GetEntityTag", resp, "Failure responding to request")
378	}
379
380	return
381}
382
383// GetEntityTagPreparer prepares the GetEntityTag request.
384func (client ProductClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, productID string) (*http.Request, error) {
385	pathParameters := map[string]interface{}{
386		"productId":         autorest.Encode("path", productID),
387		"resourceGroupName": autorest.Encode("path", resourceGroupName),
388		"serviceName":       autorest.Encode("path", serviceName),
389		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
390	}
391
392	const APIVersion = "2019-01-01"
393	queryParameters := map[string]interface{}{
394		"api-version": APIVersion,
395	}
396
397	preparer := autorest.CreatePreparer(
398		autorest.AsHead(),
399		autorest.WithBaseURL(client.BaseURI),
400		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}", pathParameters),
401		autorest.WithQueryParameters(queryParameters))
402	return preparer.Prepare((&http.Request{}).WithContext(ctx))
403}
404
405// GetEntityTagSender sends the GetEntityTag request. The method will close the
406// http.Response Body if it receives an error.
407func (client ProductClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
408	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
409	return autorest.SendWithSender(client, req, sd...)
410}
411
412// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
413// closes the http.Response Body.
414func (client ProductClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
415	err = autorest.Respond(
416		resp,
417		client.ByInspecting(),
418		azure.WithErrorUnlessStatusCode(http.StatusOK),
419		autorest.ByClosing())
420	result.Response = resp
421	return
422}
423
424// ListByService lists a collection of products in the specified service instance.
425// Parameters:
426// resourceGroupName - the name of the resource group.
427// serviceName - the name of the API Management service.
428// filter - |   Field     |     Usage     |     Supported operators     |     Supported functions
429// |</br>|-------------|-------------|-------------|-------------|</br>| name | filter | ge, le, eq, ne, gt, lt
430// | substringof, contains, startswith, endswith | </br>| displayName | filter | ge, le, eq, ne, gt, lt |
431// substringof, contains, startswith, endswith | </br>| description | filter | ge, le, eq, ne, gt, lt |
432// substringof, contains, startswith, endswith | </br>| terms | filter | ge, le, eq, ne, gt, lt | substringof,
433// contains, startswith, endswith | </br>| state | filter | eq |     | </br>| groups | expand |     |     |
434// </br>
435// top - number of records to return.
436// skip - number of records to skip.
437// expandGroups - when set to true, the response contains an array of groups that have visibility to the
438// product. The default is false.
439// tags - products which are part of a specific tag.
440func (client ProductClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, expandGroups *bool, tags string) (result ProductCollectionPage, err error) {
441	if tracing.IsEnabled() {
442		ctx = tracing.StartSpan(ctx, fqdn+"/ProductClient.ListByService")
443		defer func() {
444			sc := -1
445			if result.pc.Response.Response != nil {
446				sc = result.pc.Response.Response.StatusCode
447			}
448			tracing.EndSpan(ctx, sc, err)
449		}()
450	}
451	if err := validation.Validate([]validation.Validation{
452		{TargetValue: serviceName,
453			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
454				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
455				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
456		{TargetValue: top,
457			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
458				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
459		{TargetValue: skip,
460			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
461				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
462		return result, validation.NewError("apimanagement.ProductClient", "ListByService", err.Error())
463	}
464
465	result.fn = client.listByServiceNextResults
466	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, filter, top, skip, expandGroups, tags)
467	if err != nil {
468		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "ListByService", nil, "Failure preparing request")
469		return
470	}
471
472	resp, err := client.ListByServiceSender(req)
473	if err != nil {
474		result.pc.Response = autorest.Response{Response: resp}
475		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "ListByService", resp, "Failure sending request")
476		return
477	}
478
479	result.pc, err = client.ListByServiceResponder(resp)
480	if err != nil {
481		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "ListByService", resp, "Failure responding to request")
482	}
483
484	return
485}
486
487// ListByServicePreparer prepares the ListByService request.
488func (client ProductClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, expandGroups *bool, tags string) (*http.Request, error) {
489	pathParameters := map[string]interface{}{
490		"resourceGroupName": autorest.Encode("path", resourceGroupName),
491		"serviceName":       autorest.Encode("path", serviceName),
492		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
493	}
494
495	const APIVersion = "2019-01-01"
496	queryParameters := map[string]interface{}{
497		"api-version": APIVersion,
498	}
499	if len(filter) > 0 {
500		queryParameters["$filter"] = autorest.Encode("query", filter)
501	}
502	if top != nil {
503		queryParameters["$top"] = autorest.Encode("query", *top)
504	}
505	if skip != nil {
506		queryParameters["$skip"] = autorest.Encode("query", *skip)
507	}
508	if expandGroups != nil {
509		queryParameters["expandGroups"] = autorest.Encode("query", *expandGroups)
510	}
511	if len(tags) > 0 {
512		queryParameters["tags"] = autorest.Encode("query", tags)
513	}
514
515	preparer := autorest.CreatePreparer(
516		autorest.AsGet(),
517		autorest.WithBaseURL(client.BaseURI),
518		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products", pathParameters),
519		autorest.WithQueryParameters(queryParameters))
520	return preparer.Prepare((&http.Request{}).WithContext(ctx))
521}
522
523// ListByServiceSender sends the ListByService request. The method will close the
524// http.Response Body if it receives an error.
525func (client ProductClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
526	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
527	return autorest.SendWithSender(client, req, sd...)
528}
529
530// ListByServiceResponder handles the response to the ListByService request. The method always
531// closes the http.Response Body.
532func (client ProductClient) ListByServiceResponder(resp *http.Response) (result ProductCollection, err error) {
533	err = autorest.Respond(
534		resp,
535		client.ByInspecting(),
536		azure.WithErrorUnlessStatusCode(http.StatusOK),
537		autorest.ByUnmarshallingJSON(&result),
538		autorest.ByClosing())
539	result.Response = autorest.Response{Response: resp}
540	return
541}
542
543// listByServiceNextResults retrieves the next set of results, if any.
544func (client ProductClient) listByServiceNextResults(ctx context.Context, lastResults ProductCollection) (result ProductCollection, err error) {
545	req, err := lastResults.productCollectionPreparer(ctx)
546	if err != nil {
547		return result, autorest.NewErrorWithError(err, "apimanagement.ProductClient", "listByServiceNextResults", nil, "Failure preparing next results request")
548	}
549	if req == nil {
550		return
551	}
552	resp, err := client.ListByServiceSender(req)
553	if err != nil {
554		result.Response = autorest.Response{Response: resp}
555		return result, autorest.NewErrorWithError(err, "apimanagement.ProductClient", "listByServiceNextResults", resp, "Failure sending next results request")
556	}
557	result, err = client.ListByServiceResponder(resp)
558	if err != nil {
559		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "listByServiceNextResults", resp, "Failure responding to next results request")
560	}
561	return
562}
563
564// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
565func (client ProductClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, expandGroups *bool, tags string) (result ProductCollectionIterator, err error) {
566	if tracing.IsEnabled() {
567		ctx = tracing.StartSpan(ctx, fqdn+"/ProductClient.ListByService")
568		defer func() {
569			sc := -1
570			if result.Response().Response.Response != nil {
571				sc = result.page.Response().Response.Response.StatusCode
572			}
573			tracing.EndSpan(ctx, sc, err)
574		}()
575	}
576	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip, expandGroups, tags)
577	return
578}
579
580// ListByTags lists a collection of products associated with tags.
581// Parameters:
582// resourceGroupName - the name of the resource group.
583// serviceName - the name of the API Management service.
584// filter - |   Field     |     Usage     |     Supported operators     |     Supported functions
585// |</br>|-------------|-------------|-------------|-------------|</br>| name | filter | ge, le, eq, ne, gt, lt
586// | substringof, contains, startswith, endswith | </br>| displayName | filter | ge, le, eq, ne, gt, lt |
587// substringof, contains, startswith, endswith | </br>| description | filter | ge, le, eq, ne, gt, lt |
588// substringof, contains, startswith, endswith | </br>| terms | filter | ge, le, eq, ne, gt, lt | substringof,
589// contains, startswith, endswith | </br>| state | filter | eq | substringof, contains, startswith, endswith |
590// </br>
591// top - number of records to return.
592// skip - number of records to skip.
593// includeNotTaggedProducts - include not tagged Products.
594func (client ProductClient) ListByTags(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, includeNotTaggedProducts *bool) (result TagResourceCollectionPage, err error) {
595	if tracing.IsEnabled() {
596		ctx = tracing.StartSpan(ctx, fqdn+"/ProductClient.ListByTags")
597		defer func() {
598			sc := -1
599			if result.trc.Response.Response != nil {
600				sc = result.trc.Response.Response.StatusCode
601			}
602			tracing.EndSpan(ctx, sc, err)
603		}()
604	}
605	if err := validation.Validate([]validation.Validation{
606		{TargetValue: serviceName,
607			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
608				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
609				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
610		{TargetValue: top,
611			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
612				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
613		{TargetValue: skip,
614			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
615				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
616		return result, validation.NewError("apimanagement.ProductClient", "ListByTags", err.Error())
617	}
618
619	result.fn = client.listByTagsNextResults
620	req, err := client.ListByTagsPreparer(ctx, resourceGroupName, serviceName, filter, top, skip, includeNotTaggedProducts)
621	if err != nil {
622		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "ListByTags", nil, "Failure preparing request")
623		return
624	}
625
626	resp, err := client.ListByTagsSender(req)
627	if err != nil {
628		result.trc.Response = autorest.Response{Response: resp}
629		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "ListByTags", resp, "Failure sending request")
630		return
631	}
632
633	result.trc, err = client.ListByTagsResponder(resp)
634	if err != nil {
635		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "ListByTags", resp, "Failure responding to request")
636	}
637
638	return
639}
640
641// ListByTagsPreparer prepares the ListByTags request.
642func (client ProductClient) ListByTagsPreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, includeNotTaggedProducts *bool) (*http.Request, error) {
643	pathParameters := map[string]interface{}{
644		"resourceGroupName": autorest.Encode("path", resourceGroupName),
645		"serviceName":       autorest.Encode("path", serviceName),
646		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
647	}
648
649	const APIVersion = "2019-01-01"
650	queryParameters := map[string]interface{}{
651		"api-version": APIVersion,
652	}
653	if len(filter) > 0 {
654		queryParameters["$filter"] = autorest.Encode("query", filter)
655	}
656	if top != nil {
657		queryParameters["$top"] = autorest.Encode("query", *top)
658	}
659	if skip != nil {
660		queryParameters["$skip"] = autorest.Encode("query", *skip)
661	}
662	if includeNotTaggedProducts != nil {
663		queryParameters["includeNotTaggedProducts"] = autorest.Encode("query", *includeNotTaggedProducts)
664	}
665
666	preparer := autorest.CreatePreparer(
667		autorest.AsGet(),
668		autorest.WithBaseURL(client.BaseURI),
669		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/productsByTags", pathParameters),
670		autorest.WithQueryParameters(queryParameters))
671	return preparer.Prepare((&http.Request{}).WithContext(ctx))
672}
673
674// ListByTagsSender sends the ListByTags request. The method will close the
675// http.Response Body if it receives an error.
676func (client ProductClient) ListByTagsSender(req *http.Request) (*http.Response, error) {
677	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
678	return autorest.SendWithSender(client, req, sd...)
679}
680
681// ListByTagsResponder handles the response to the ListByTags request. The method always
682// closes the http.Response Body.
683func (client ProductClient) ListByTagsResponder(resp *http.Response) (result TagResourceCollection, err error) {
684	err = autorest.Respond(
685		resp,
686		client.ByInspecting(),
687		azure.WithErrorUnlessStatusCode(http.StatusOK),
688		autorest.ByUnmarshallingJSON(&result),
689		autorest.ByClosing())
690	result.Response = autorest.Response{Response: resp}
691	return
692}
693
694// listByTagsNextResults retrieves the next set of results, if any.
695func (client ProductClient) listByTagsNextResults(ctx context.Context, lastResults TagResourceCollection) (result TagResourceCollection, err error) {
696	req, err := lastResults.tagResourceCollectionPreparer(ctx)
697	if err != nil {
698		return result, autorest.NewErrorWithError(err, "apimanagement.ProductClient", "listByTagsNextResults", nil, "Failure preparing next results request")
699	}
700	if req == nil {
701		return
702	}
703	resp, err := client.ListByTagsSender(req)
704	if err != nil {
705		result.Response = autorest.Response{Response: resp}
706		return result, autorest.NewErrorWithError(err, "apimanagement.ProductClient", "listByTagsNextResults", resp, "Failure sending next results request")
707	}
708	result, err = client.ListByTagsResponder(resp)
709	if err != nil {
710		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "listByTagsNextResults", resp, "Failure responding to next results request")
711	}
712	return
713}
714
715// ListByTagsComplete enumerates all values, automatically crossing page boundaries as required.
716func (client ProductClient) ListByTagsComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, includeNotTaggedProducts *bool) (result TagResourceCollectionIterator, err error) {
717	if tracing.IsEnabled() {
718		ctx = tracing.StartSpan(ctx, fqdn+"/ProductClient.ListByTags")
719		defer func() {
720			sc := -1
721			if result.Response().Response.Response != nil {
722				sc = result.page.Response().Response.Response.StatusCode
723			}
724			tracing.EndSpan(ctx, sc, err)
725		}()
726	}
727	result.page, err = client.ListByTags(ctx, resourceGroupName, serviceName, filter, top, skip, includeNotTaggedProducts)
728	return
729}
730
731// Update update existing product details.
732// Parameters:
733// resourceGroupName - the name of the resource group.
734// serviceName - the name of the API Management service.
735// productID - product identifier. Must be unique in the current API Management service instance.
736// parameters - update parameters.
737// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
738// request or it should be * for unconditional update.
739func (client ProductClient) Update(ctx context.Context, resourceGroupName string, serviceName string, productID string, parameters ProductUpdateParameters, ifMatch string) (result autorest.Response, err error) {
740	if tracing.IsEnabled() {
741		ctx = tracing.StartSpan(ctx, fqdn+"/ProductClient.Update")
742		defer func() {
743			sc := -1
744			if result.Response != nil {
745				sc = result.Response.StatusCode
746			}
747			tracing.EndSpan(ctx, sc, err)
748		}()
749	}
750	if err := validation.Validate([]validation.Validation{
751		{TargetValue: serviceName,
752			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
753				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
754				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
755		{TargetValue: productID,
756			Constraints: []validation.Constraint{{Target: "productID", Name: validation.MaxLength, Rule: 256, Chain: nil},
757				{Target: "productID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
758		return result, validation.NewError("apimanagement.ProductClient", "Update", err.Error())
759	}
760
761	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, productID, parameters, ifMatch)
762	if err != nil {
763		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "Update", nil, "Failure preparing request")
764		return
765	}
766
767	resp, err := client.UpdateSender(req)
768	if err != nil {
769		result.Response = resp
770		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "Update", resp, "Failure sending request")
771		return
772	}
773
774	result, err = client.UpdateResponder(resp)
775	if err != nil {
776		err = autorest.NewErrorWithError(err, "apimanagement.ProductClient", "Update", resp, "Failure responding to request")
777	}
778
779	return
780}
781
782// UpdatePreparer prepares the Update request.
783func (client ProductClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, productID string, parameters ProductUpdateParameters, ifMatch string) (*http.Request, error) {
784	pathParameters := map[string]interface{}{
785		"productId":         autorest.Encode("path", productID),
786		"resourceGroupName": autorest.Encode("path", resourceGroupName),
787		"serviceName":       autorest.Encode("path", serviceName),
788		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
789	}
790
791	const APIVersion = "2019-01-01"
792	queryParameters := map[string]interface{}{
793		"api-version": APIVersion,
794	}
795
796	preparer := autorest.CreatePreparer(
797		autorest.AsContentType("application/json; charset=utf-8"),
798		autorest.AsPatch(),
799		autorest.WithBaseURL(client.BaseURI),
800		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}", pathParameters),
801		autorest.WithJSON(parameters),
802		autorest.WithQueryParameters(queryParameters),
803		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
804	return preparer.Prepare((&http.Request{}).WithContext(ctx))
805}
806
807// UpdateSender sends the Update request. The method will close the
808// http.Response Body if it receives an error.
809func (client ProductClient) UpdateSender(req *http.Request) (*http.Response, error) {
810	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
811	return autorest.SendWithSender(client, req, sd...)
812}
813
814// UpdateResponder handles the response to the Update request. The method always
815// closes the http.Response Body.
816func (client ProductClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
817	err = autorest.Respond(
818		resp,
819		client.ByInspecting(),
820		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
821		autorest.ByClosing())
822	result.Response = resp
823	return
824}
825