1// +build go1.13
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// Code generated by Microsoft (R) AutoRest Code Generator.
6// Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
8package armapimanagement
9
10import (
11	"context"
12	"errors"
13	"fmt"
14	"github.com/Azure/azure-sdk-for-go/sdk/armcore"
15	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
16	"net/http"
17	"net/url"
18	"strconv"
19	"strings"
20)
21
22// TagClient contains the methods for the Tag group.
23// Don't use this type directly, use NewTagClient() instead.
24type TagClient struct {
25	con            *armcore.Connection
26	subscriptionID string
27}
28
29// NewTagClient creates a new instance of TagClient with the specified values.
30func NewTagClient(con *armcore.Connection, subscriptionID string) *TagClient {
31	return &TagClient{con: con, subscriptionID: subscriptionID}
32}
33
34// AssignToAPI - Assign tag to the Api.
35// If the operation fails it returns the *ErrorResponse error type.
36func (client *TagClient) AssignToAPI(ctx context.Context, resourceGroupName string, serviceName string, apiID string, tagID string, options *TagAssignToAPIOptions) (TagAssignToAPIResponse, error) {
37	req, err := client.assignToAPICreateRequest(ctx, resourceGroupName, serviceName, apiID, tagID, options)
38	if err != nil {
39		return TagAssignToAPIResponse{}, err
40	}
41	resp, err := client.con.Pipeline().Do(req)
42	if err != nil {
43		return TagAssignToAPIResponse{}, err
44	}
45	if !resp.HasStatusCode(http.StatusOK, http.StatusCreated) {
46		return TagAssignToAPIResponse{}, client.assignToAPIHandleError(resp)
47	}
48	return client.assignToAPIHandleResponse(resp)
49}
50
51// assignToAPICreateRequest creates the AssignToAPI request.
52func (client *TagClient) assignToAPICreateRequest(ctx context.Context, resourceGroupName string, serviceName string, apiID string, tagID string, options *TagAssignToAPIOptions) (*azcore.Request, error) {
53	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tags/{tagId}"
54	if resourceGroupName == "" {
55		return nil, errors.New("parameter resourceGroupName cannot be empty")
56	}
57	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
58	if serviceName == "" {
59		return nil, errors.New("parameter serviceName cannot be empty")
60	}
61	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
62	if apiID == "" {
63		return nil, errors.New("parameter apiID cannot be empty")
64	}
65	urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
66	if tagID == "" {
67		return nil, errors.New("parameter tagID cannot be empty")
68	}
69	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
70	if client.subscriptionID == "" {
71		return nil, errors.New("parameter client.subscriptionID cannot be empty")
72	}
73	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
74	req, err := azcore.NewRequest(ctx, http.MethodPut, azcore.JoinPaths(client.con.Endpoint(), urlPath))
75	if err != nil {
76		return nil, err
77	}
78	req.Telemetry(telemetryInfo)
79	reqQP := req.URL.Query()
80	reqQP.Set("api-version", "2020-12-01")
81	req.URL.RawQuery = reqQP.Encode()
82	req.Header.Set("Accept", "application/json")
83	return req, nil
84}
85
86// assignToAPIHandleResponse handles the AssignToAPI response.
87func (client *TagClient) assignToAPIHandleResponse(resp *azcore.Response) (TagAssignToAPIResponse, error) {
88	result := TagAssignToAPIResponse{RawResponse: resp.Response}
89	if val := resp.Header.Get("ETag"); val != "" {
90		result.ETag = &val
91	}
92	if err := resp.UnmarshalAsJSON(&result.TagContract); err != nil {
93		return TagAssignToAPIResponse{}, err
94	}
95	return result, nil
96}
97
98// assignToAPIHandleError handles the AssignToAPI error response.
99func (client *TagClient) assignToAPIHandleError(resp *azcore.Response) error {
100	body, err := resp.Payload()
101	if err != nil {
102		return azcore.NewResponseError(err, resp.Response)
103	}
104	errType := ErrorResponse{raw: string(body)}
105	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
106		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
107	}
108	return azcore.NewResponseError(&errType, resp.Response)
109}
110
111// AssignToOperation - Assign tag to the Operation.
112// If the operation fails it returns the *ErrorResponse error type.
113func (client *TagClient) AssignToOperation(ctx context.Context, resourceGroupName string, serviceName string, apiID string, operationID string, tagID string, options *TagAssignToOperationOptions) (TagAssignToOperationResponse, error) {
114	req, err := client.assignToOperationCreateRequest(ctx, resourceGroupName, serviceName, apiID, operationID, tagID, options)
115	if err != nil {
116		return TagAssignToOperationResponse{}, err
117	}
118	resp, err := client.con.Pipeline().Do(req)
119	if err != nil {
120		return TagAssignToOperationResponse{}, err
121	}
122	if !resp.HasStatusCode(http.StatusOK, http.StatusCreated) {
123		return TagAssignToOperationResponse{}, client.assignToOperationHandleError(resp)
124	}
125	return client.assignToOperationHandleResponse(resp)
126}
127
128// assignToOperationCreateRequest creates the AssignToOperation request.
129func (client *TagClient) assignToOperationCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, apiID string, operationID string, tagID string, options *TagAssignToOperationOptions) (*azcore.Request, error) {
130	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}/tags/{tagId}"
131	if resourceGroupName == "" {
132		return nil, errors.New("parameter resourceGroupName cannot be empty")
133	}
134	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
135	if serviceName == "" {
136		return nil, errors.New("parameter serviceName cannot be empty")
137	}
138	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
139	if apiID == "" {
140		return nil, errors.New("parameter apiID cannot be empty")
141	}
142	urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
143	if operationID == "" {
144		return nil, errors.New("parameter operationID cannot be empty")
145	}
146	urlPath = strings.ReplaceAll(urlPath, "{operationId}", url.PathEscape(operationID))
147	if tagID == "" {
148		return nil, errors.New("parameter tagID cannot be empty")
149	}
150	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
151	if client.subscriptionID == "" {
152		return nil, errors.New("parameter client.subscriptionID cannot be empty")
153	}
154	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
155	req, err := azcore.NewRequest(ctx, http.MethodPut, azcore.JoinPaths(client.con.Endpoint(), urlPath))
156	if err != nil {
157		return nil, err
158	}
159	req.Telemetry(telemetryInfo)
160	reqQP := req.URL.Query()
161	reqQP.Set("api-version", "2020-12-01")
162	req.URL.RawQuery = reqQP.Encode()
163	req.Header.Set("Accept", "application/json")
164	return req, nil
165}
166
167// assignToOperationHandleResponse handles the AssignToOperation response.
168func (client *TagClient) assignToOperationHandleResponse(resp *azcore.Response) (TagAssignToOperationResponse, error) {
169	result := TagAssignToOperationResponse{RawResponse: resp.Response}
170	if err := resp.UnmarshalAsJSON(&result.TagContract); err != nil {
171		return TagAssignToOperationResponse{}, err
172	}
173	return result, nil
174}
175
176// assignToOperationHandleError handles the AssignToOperation error response.
177func (client *TagClient) assignToOperationHandleError(resp *azcore.Response) error {
178	body, err := resp.Payload()
179	if err != nil {
180		return azcore.NewResponseError(err, resp.Response)
181	}
182	errType := ErrorResponse{raw: string(body)}
183	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
184		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
185	}
186	return azcore.NewResponseError(&errType, resp.Response)
187}
188
189// AssignToProduct - Assign tag to the Product.
190// If the operation fails it returns the *ErrorResponse error type.
191func (client *TagClient) AssignToProduct(ctx context.Context, resourceGroupName string, serviceName string, productID string, tagID string, options *TagAssignToProductOptions) (TagAssignToProductResponse, error) {
192	req, err := client.assignToProductCreateRequest(ctx, resourceGroupName, serviceName, productID, tagID, options)
193	if err != nil {
194		return TagAssignToProductResponse{}, err
195	}
196	resp, err := client.con.Pipeline().Do(req)
197	if err != nil {
198		return TagAssignToProductResponse{}, err
199	}
200	if !resp.HasStatusCode(http.StatusOK, http.StatusCreated) {
201		return TagAssignToProductResponse{}, client.assignToProductHandleError(resp)
202	}
203	return client.assignToProductHandleResponse(resp)
204}
205
206// assignToProductCreateRequest creates the AssignToProduct request.
207func (client *TagClient) assignToProductCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, productID string, tagID string, options *TagAssignToProductOptions) (*azcore.Request, error) {
208	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}/tags/{tagId}"
209	if resourceGroupName == "" {
210		return nil, errors.New("parameter resourceGroupName cannot be empty")
211	}
212	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
213	if serviceName == "" {
214		return nil, errors.New("parameter serviceName cannot be empty")
215	}
216	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
217	if productID == "" {
218		return nil, errors.New("parameter productID cannot be empty")
219	}
220	urlPath = strings.ReplaceAll(urlPath, "{productId}", url.PathEscape(productID))
221	if tagID == "" {
222		return nil, errors.New("parameter tagID cannot be empty")
223	}
224	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
225	if client.subscriptionID == "" {
226		return nil, errors.New("parameter client.subscriptionID cannot be empty")
227	}
228	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
229	req, err := azcore.NewRequest(ctx, http.MethodPut, azcore.JoinPaths(client.con.Endpoint(), urlPath))
230	if err != nil {
231		return nil, err
232	}
233	req.Telemetry(telemetryInfo)
234	reqQP := req.URL.Query()
235	reqQP.Set("api-version", "2020-12-01")
236	req.URL.RawQuery = reqQP.Encode()
237	req.Header.Set("Accept", "application/json")
238	return req, nil
239}
240
241// assignToProductHandleResponse handles the AssignToProduct response.
242func (client *TagClient) assignToProductHandleResponse(resp *azcore.Response) (TagAssignToProductResponse, error) {
243	result := TagAssignToProductResponse{RawResponse: resp.Response}
244	if err := resp.UnmarshalAsJSON(&result.TagContract); err != nil {
245		return TagAssignToProductResponse{}, err
246	}
247	return result, nil
248}
249
250// assignToProductHandleError handles the AssignToProduct error response.
251func (client *TagClient) assignToProductHandleError(resp *azcore.Response) error {
252	body, err := resp.Payload()
253	if err != nil {
254		return azcore.NewResponseError(err, resp.Response)
255	}
256	errType := ErrorResponse{raw: string(body)}
257	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
258		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
259	}
260	return azcore.NewResponseError(&errType, resp.Response)
261}
262
263// CreateOrUpdate - Creates a tag.
264// If the operation fails it returns the *ErrorResponse error type.
265func (client *TagClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, tagID string, parameters TagCreateUpdateParameters, options *TagCreateOrUpdateOptions) (TagCreateOrUpdateResponse, error) {
266	req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, serviceName, tagID, parameters, options)
267	if err != nil {
268		return TagCreateOrUpdateResponse{}, err
269	}
270	resp, err := client.con.Pipeline().Do(req)
271	if err != nil {
272		return TagCreateOrUpdateResponse{}, err
273	}
274	if !resp.HasStatusCode(http.StatusOK, http.StatusCreated) {
275		return TagCreateOrUpdateResponse{}, client.createOrUpdateHandleError(resp)
276	}
277	return client.createOrUpdateHandleResponse(resp)
278}
279
280// createOrUpdateCreateRequest creates the CreateOrUpdate request.
281func (client *TagClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, tagID string, parameters TagCreateUpdateParameters, options *TagCreateOrUpdateOptions) (*azcore.Request, error) {
282	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tags/{tagId}"
283	if resourceGroupName == "" {
284		return nil, errors.New("parameter resourceGroupName cannot be empty")
285	}
286	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
287	if serviceName == "" {
288		return nil, errors.New("parameter serviceName cannot be empty")
289	}
290	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
291	if tagID == "" {
292		return nil, errors.New("parameter tagID cannot be empty")
293	}
294	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
295	if client.subscriptionID == "" {
296		return nil, errors.New("parameter client.subscriptionID cannot be empty")
297	}
298	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
299	req, err := azcore.NewRequest(ctx, http.MethodPut, azcore.JoinPaths(client.con.Endpoint(), urlPath))
300	if err != nil {
301		return nil, err
302	}
303	req.Telemetry(telemetryInfo)
304	reqQP := req.URL.Query()
305	reqQP.Set("api-version", "2020-12-01")
306	req.URL.RawQuery = reqQP.Encode()
307	if options != nil && options.IfMatch != nil {
308		req.Header.Set("If-Match", *options.IfMatch)
309	}
310	req.Header.Set("Accept", "application/json")
311	return req, req.MarshalAsJSON(parameters)
312}
313
314// createOrUpdateHandleResponse handles the CreateOrUpdate response.
315func (client *TagClient) createOrUpdateHandleResponse(resp *azcore.Response) (TagCreateOrUpdateResponse, error) {
316	result := TagCreateOrUpdateResponse{RawResponse: resp.Response}
317	if val := resp.Header.Get("ETag"); val != "" {
318		result.ETag = &val
319	}
320	if err := resp.UnmarshalAsJSON(&result.TagContract); err != nil {
321		return TagCreateOrUpdateResponse{}, err
322	}
323	return result, nil
324}
325
326// createOrUpdateHandleError handles the CreateOrUpdate error response.
327func (client *TagClient) createOrUpdateHandleError(resp *azcore.Response) error {
328	body, err := resp.Payload()
329	if err != nil {
330		return azcore.NewResponseError(err, resp.Response)
331	}
332	errType := ErrorResponse{raw: string(body)}
333	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
334		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
335	}
336	return azcore.NewResponseError(&errType, resp.Response)
337}
338
339// Delete - Deletes specific tag of the API Management service instance.
340// If the operation fails it returns the *ErrorResponse error type.
341func (client *TagClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, tagID string, ifMatch string, options *TagDeleteOptions) (TagDeleteResponse, error) {
342	req, err := client.deleteCreateRequest(ctx, resourceGroupName, serviceName, tagID, ifMatch, options)
343	if err != nil {
344		return TagDeleteResponse{}, err
345	}
346	resp, err := client.con.Pipeline().Do(req)
347	if err != nil {
348		return TagDeleteResponse{}, err
349	}
350	if !resp.HasStatusCode(http.StatusOK, http.StatusNoContent) {
351		return TagDeleteResponse{}, client.deleteHandleError(resp)
352	}
353	return TagDeleteResponse{RawResponse: resp.Response}, nil
354}
355
356// deleteCreateRequest creates the Delete request.
357func (client *TagClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, tagID string, ifMatch string, options *TagDeleteOptions) (*azcore.Request, error) {
358	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tags/{tagId}"
359	if resourceGroupName == "" {
360		return nil, errors.New("parameter resourceGroupName cannot be empty")
361	}
362	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
363	if serviceName == "" {
364		return nil, errors.New("parameter serviceName cannot be empty")
365	}
366	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
367	if tagID == "" {
368		return nil, errors.New("parameter tagID cannot be empty")
369	}
370	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
371	if client.subscriptionID == "" {
372		return nil, errors.New("parameter client.subscriptionID cannot be empty")
373	}
374	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
375	req, err := azcore.NewRequest(ctx, http.MethodDelete, azcore.JoinPaths(client.con.Endpoint(), urlPath))
376	if err != nil {
377		return nil, err
378	}
379	req.Telemetry(telemetryInfo)
380	reqQP := req.URL.Query()
381	reqQP.Set("api-version", "2020-12-01")
382	req.URL.RawQuery = reqQP.Encode()
383	req.Header.Set("If-Match", ifMatch)
384	req.Header.Set("Accept", "application/json")
385	return req, nil
386}
387
388// deleteHandleError handles the Delete error response.
389func (client *TagClient) deleteHandleError(resp *azcore.Response) error {
390	body, err := resp.Payload()
391	if err != nil {
392		return azcore.NewResponseError(err, resp.Response)
393	}
394	errType := ErrorResponse{raw: string(body)}
395	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
396		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
397	}
398	return azcore.NewResponseError(&errType, resp.Response)
399}
400
401// DetachFromAPI - Detach the tag from the Api.
402// If the operation fails it returns the *ErrorResponse error type.
403func (client *TagClient) DetachFromAPI(ctx context.Context, resourceGroupName string, serviceName string, apiID string, tagID string, options *TagDetachFromAPIOptions) (TagDetachFromAPIResponse, error) {
404	req, err := client.detachFromAPICreateRequest(ctx, resourceGroupName, serviceName, apiID, tagID, options)
405	if err != nil {
406		return TagDetachFromAPIResponse{}, err
407	}
408	resp, err := client.con.Pipeline().Do(req)
409	if err != nil {
410		return TagDetachFromAPIResponse{}, err
411	}
412	if !resp.HasStatusCode(http.StatusOK, http.StatusNoContent) {
413		return TagDetachFromAPIResponse{}, client.detachFromAPIHandleError(resp)
414	}
415	return TagDetachFromAPIResponse{RawResponse: resp.Response}, nil
416}
417
418// detachFromAPICreateRequest creates the DetachFromAPI request.
419func (client *TagClient) detachFromAPICreateRequest(ctx context.Context, resourceGroupName string, serviceName string, apiID string, tagID string, options *TagDetachFromAPIOptions) (*azcore.Request, error) {
420	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tags/{tagId}"
421	if resourceGroupName == "" {
422		return nil, errors.New("parameter resourceGroupName cannot be empty")
423	}
424	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
425	if serviceName == "" {
426		return nil, errors.New("parameter serviceName cannot be empty")
427	}
428	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
429	if apiID == "" {
430		return nil, errors.New("parameter apiID cannot be empty")
431	}
432	urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
433	if tagID == "" {
434		return nil, errors.New("parameter tagID cannot be empty")
435	}
436	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
437	if client.subscriptionID == "" {
438		return nil, errors.New("parameter client.subscriptionID cannot be empty")
439	}
440	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
441	req, err := azcore.NewRequest(ctx, http.MethodDelete, azcore.JoinPaths(client.con.Endpoint(), urlPath))
442	if err != nil {
443		return nil, err
444	}
445	req.Telemetry(telemetryInfo)
446	reqQP := req.URL.Query()
447	reqQP.Set("api-version", "2020-12-01")
448	req.URL.RawQuery = reqQP.Encode()
449	req.Header.Set("Accept", "application/json")
450	return req, nil
451}
452
453// detachFromAPIHandleError handles the DetachFromAPI error response.
454func (client *TagClient) detachFromAPIHandleError(resp *azcore.Response) error {
455	body, err := resp.Payload()
456	if err != nil {
457		return azcore.NewResponseError(err, resp.Response)
458	}
459	errType := ErrorResponse{raw: string(body)}
460	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
461		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
462	}
463	return azcore.NewResponseError(&errType, resp.Response)
464}
465
466// DetachFromOperation - Detach the tag from the Operation.
467// If the operation fails it returns the *ErrorResponse error type.
468func (client *TagClient) DetachFromOperation(ctx context.Context, resourceGroupName string, serviceName string, apiID string, operationID string, tagID string, options *TagDetachFromOperationOptions) (TagDetachFromOperationResponse, error) {
469	req, err := client.detachFromOperationCreateRequest(ctx, resourceGroupName, serviceName, apiID, operationID, tagID, options)
470	if err != nil {
471		return TagDetachFromOperationResponse{}, err
472	}
473	resp, err := client.con.Pipeline().Do(req)
474	if err != nil {
475		return TagDetachFromOperationResponse{}, err
476	}
477	if !resp.HasStatusCode(http.StatusOK, http.StatusNoContent) {
478		return TagDetachFromOperationResponse{}, client.detachFromOperationHandleError(resp)
479	}
480	return TagDetachFromOperationResponse{RawResponse: resp.Response}, nil
481}
482
483// detachFromOperationCreateRequest creates the DetachFromOperation request.
484func (client *TagClient) detachFromOperationCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, apiID string, operationID string, tagID string, options *TagDetachFromOperationOptions) (*azcore.Request, error) {
485	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}/tags/{tagId}"
486	if resourceGroupName == "" {
487		return nil, errors.New("parameter resourceGroupName cannot be empty")
488	}
489	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
490	if serviceName == "" {
491		return nil, errors.New("parameter serviceName cannot be empty")
492	}
493	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
494	if apiID == "" {
495		return nil, errors.New("parameter apiID cannot be empty")
496	}
497	urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
498	if operationID == "" {
499		return nil, errors.New("parameter operationID cannot be empty")
500	}
501	urlPath = strings.ReplaceAll(urlPath, "{operationId}", url.PathEscape(operationID))
502	if tagID == "" {
503		return nil, errors.New("parameter tagID cannot be empty")
504	}
505	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
506	if client.subscriptionID == "" {
507		return nil, errors.New("parameter client.subscriptionID cannot be empty")
508	}
509	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
510	req, err := azcore.NewRequest(ctx, http.MethodDelete, azcore.JoinPaths(client.con.Endpoint(), urlPath))
511	if err != nil {
512		return nil, err
513	}
514	req.Telemetry(telemetryInfo)
515	reqQP := req.URL.Query()
516	reqQP.Set("api-version", "2020-12-01")
517	req.URL.RawQuery = reqQP.Encode()
518	req.Header.Set("Accept", "application/json")
519	return req, nil
520}
521
522// detachFromOperationHandleError handles the DetachFromOperation error response.
523func (client *TagClient) detachFromOperationHandleError(resp *azcore.Response) error {
524	body, err := resp.Payload()
525	if err != nil {
526		return azcore.NewResponseError(err, resp.Response)
527	}
528	errType := ErrorResponse{raw: string(body)}
529	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
530		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
531	}
532	return azcore.NewResponseError(&errType, resp.Response)
533}
534
535// DetachFromProduct - Detach the tag from the Product.
536// If the operation fails it returns the *ErrorResponse error type.
537func (client *TagClient) DetachFromProduct(ctx context.Context, resourceGroupName string, serviceName string, productID string, tagID string, options *TagDetachFromProductOptions) (TagDetachFromProductResponse, error) {
538	req, err := client.detachFromProductCreateRequest(ctx, resourceGroupName, serviceName, productID, tagID, options)
539	if err != nil {
540		return TagDetachFromProductResponse{}, err
541	}
542	resp, err := client.con.Pipeline().Do(req)
543	if err != nil {
544		return TagDetachFromProductResponse{}, err
545	}
546	if !resp.HasStatusCode(http.StatusOK, http.StatusNoContent) {
547		return TagDetachFromProductResponse{}, client.detachFromProductHandleError(resp)
548	}
549	return TagDetachFromProductResponse{RawResponse: resp.Response}, nil
550}
551
552// detachFromProductCreateRequest creates the DetachFromProduct request.
553func (client *TagClient) detachFromProductCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, productID string, tagID string, options *TagDetachFromProductOptions) (*azcore.Request, error) {
554	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}/tags/{tagId}"
555	if resourceGroupName == "" {
556		return nil, errors.New("parameter resourceGroupName cannot be empty")
557	}
558	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
559	if serviceName == "" {
560		return nil, errors.New("parameter serviceName cannot be empty")
561	}
562	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
563	if productID == "" {
564		return nil, errors.New("parameter productID cannot be empty")
565	}
566	urlPath = strings.ReplaceAll(urlPath, "{productId}", url.PathEscape(productID))
567	if tagID == "" {
568		return nil, errors.New("parameter tagID cannot be empty")
569	}
570	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
571	if client.subscriptionID == "" {
572		return nil, errors.New("parameter client.subscriptionID cannot be empty")
573	}
574	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
575	req, err := azcore.NewRequest(ctx, http.MethodDelete, azcore.JoinPaths(client.con.Endpoint(), urlPath))
576	if err != nil {
577		return nil, err
578	}
579	req.Telemetry(telemetryInfo)
580	reqQP := req.URL.Query()
581	reqQP.Set("api-version", "2020-12-01")
582	req.URL.RawQuery = reqQP.Encode()
583	req.Header.Set("Accept", "application/json")
584	return req, nil
585}
586
587// detachFromProductHandleError handles the DetachFromProduct error response.
588func (client *TagClient) detachFromProductHandleError(resp *azcore.Response) error {
589	body, err := resp.Payload()
590	if err != nil {
591		return azcore.NewResponseError(err, resp.Response)
592	}
593	errType := ErrorResponse{raw: string(body)}
594	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
595		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
596	}
597	return azcore.NewResponseError(&errType, resp.Response)
598}
599
600// Get - Gets the details of the tag specified by its identifier.
601// If the operation fails it returns the *ErrorResponse error type.
602func (client *TagClient) Get(ctx context.Context, resourceGroupName string, serviceName string, tagID string, options *TagGetOptions) (TagGetResponse, error) {
603	req, err := client.getCreateRequest(ctx, resourceGroupName, serviceName, tagID, options)
604	if err != nil {
605		return TagGetResponse{}, err
606	}
607	resp, err := client.con.Pipeline().Do(req)
608	if err != nil {
609		return TagGetResponse{}, err
610	}
611	if !resp.HasStatusCode(http.StatusOK) {
612		return TagGetResponse{}, client.getHandleError(resp)
613	}
614	return client.getHandleResponse(resp)
615}
616
617// getCreateRequest creates the Get request.
618func (client *TagClient) getCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, tagID string, options *TagGetOptions) (*azcore.Request, error) {
619	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tags/{tagId}"
620	if resourceGroupName == "" {
621		return nil, errors.New("parameter resourceGroupName cannot be empty")
622	}
623	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
624	if serviceName == "" {
625		return nil, errors.New("parameter serviceName cannot be empty")
626	}
627	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
628	if tagID == "" {
629		return nil, errors.New("parameter tagID cannot be empty")
630	}
631	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
632	if client.subscriptionID == "" {
633		return nil, errors.New("parameter client.subscriptionID cannot be empty")
634	}
635	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
636	req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath))
637	if err != nil {
638		return nil, err
639	}
640	req.Telemetry(telemetryInfo)
641	reqQP := req.URL.Query()
642	reqQP.Set("api-version", "2020-12-01")
643	req.URL.RawQuery = reqQP.Encode()
644	req.Header.Set("Accept", "application/json")
645	return req, nil
646}
647
648// getHandleResponse handles the Get response.
649func (client *TagClient) getHandleResponse(resp *azcore.Response) (TagGetResponse, error) {
650	result := TagGetResponse{RawResponse: resp.Response}
651	if val := resp.Header.Get("ETag"); val != "" {
652		result.ETag = &val
653	}
654	if err := resp.UnmarshalAsJSON(&result.TagContract); err != nil {
655		return TagGetResponse{}, err
656	}
657	return result, nil
658}
659
660// getHandleError handles the Get error response.
661func (client *TagClient) getHandleError(resp *azcore.Response) error {
662	body, err := resp.Payload()
663	if err != nil {
664		return azcore.NewResponseError(err, resp.Response)
665	}
666	errType := ErrorResponse{raw: string(body)}
667	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
668		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
669	}
670	return azcore.NewResponseError(&errType, resp.Response)
671}
672
673// GetByAPI - Get tag associated with the API.
674// If the operation fails it returns the *ErrorResponse error type.
675func (client *TagClient) GetByAPI(ctx context.Context, resourceGroupName string, serviceName string, apiID string, tagID string, options *TagGetByAPIOptions) (TagGetByAPIResponse, error) {
676	req, err := client.getByAPICreateRequest(ctx, resourceGroupName, serviceName, apiID, tagID, options)
677	if err != nil {
678		return TagGetByAPIResponse{}, err
679	}
680	resp, err := client.con.Pipeline().Do(req)
681	if err != nil {
682		return TagGetByAPIResponse{}, err
683	}
684	if !resp.HasStatusCode(http.StatusOK) {
685		return TagGetByAPIResponse{}, client.getByAPIHandleError(resp)
686	}
687	return client.getByAPIHandleResponse(resp)
688}
689
690// getByAPICreateRequest creates the GetByAPI request.
691func (client *TagClient) getByAPICreateRequest(ctx context.Context, resourceGroupName string, serviceName string, apiID string, tagID string, options *TagGetByAPIOptions) (*azcore.Request, error) {
692	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tags/{tagId}"
693	if resourceGroupName == "" {
694		return nil, errors.New("parameter resourceGroupName cannot be empty")
695	}
696	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
697	if serviceName == "" {
698		return nil, errors.New("parameter serviceName cannot be empty")
699	}
700	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
701	if apiID == "" {
702		return nil, errors.New("parameter apiID cannot be empty")
703	}
704	urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
705	if tagID == "" {
706		return nil, errors.New("parameter tagID cannot be empty")
707	}
708	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
709	if client.subscriptionID == "" {
710		return nil, errors.New("parameter client.subscriptionID cannot be empty")
711	}
712	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
713	req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath))
714	if err != nil {
715		return nil, err
716	}
717	req.Telemetry(telemetryInfo)
718	reqQP := req.URL.Query()
719	reqQP.Set("api-version", "2020-12-01")
720	req.URL.RawQuery = reqQP.Encode()
721	req.Header.Set("Accept", "application/json")
722	return req, nil
723}
724
725// getByAPIHandleResponse handles the GetByAPI response.
726func (client *TagClient) getByAPIHandleResponse(resp *azcore.Response) (TagGetByAPIResponse, error) {
727	result := TagGetByAPIResponse{RawResponse: resp.Response}
728	if val := resp.Header.Get("ETag"); val != "" {
729		result.ETag = &val
730	}
731	if err := resp.UnmarshalAsJSON(&result.TagContract); err != nil {
732		return TagGetByAPIResponse{}, err
733	}
734	return result, nil
735}
736
737// getByAPIHandleError handles the GetByAPI error response.
738func (client *TagClient) getByAPIHandleError(resp *azcore.Response) error {
739	body, err := resp.Payload()
740	if err != nil {
741		return azcore.NewResponseError(err, resp.Response)
742	}
743	errType := ErrorResponse{raw: string(body)}
744	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
745		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
746	}
747	return azcore.NewResponseError(&errType, resp.Response)
748}
749
750// GetByOperation - Get tag associated with the Operation.
751// If the operation fails it returns the *ErrorResponse error type.
752func (client *TagClient) GetByOperation(ctx context.Context, resourceGroupName string, serviceName string, apiID string, operationID string, tagID string, options *TagGetByOperationOptions) (TagGetByOperationResponse, error) {
753	req, err := client.getByOperationCreateRequest(ctx, resourceGroupName, serviceName, apiID, operationID, tagID, options)
754	if err != nil {
755		return TagGetByOperationResponse{}, err
756	}
757	resp, err := client.con.Pipeline().Do(req)
758	if err != nil {
759		return TagGetByOperationResponse{}, err
760	}
761	if !resp.HasStatusCode(http.StatusOK) {
762		return TagGetByOperationResponse{}, client.getByOperationHandleError(resp)
763	}
764	return client.getByOperationHandleResponse(resp)
765}
766
767// getByOperationCreateRequest creates the GetByOperation request.
768func (client *TagClient) getByOperationCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, apiID string, operationID string, tagID string, options *TagGetByOperationOptions) (*azcore.Request, error) {
769	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}/tags/{tagId}"
770	if resourceGroupName == "" {
771		return nil, errors.New("parameter resourceGroupName cannot be empty")
772	}
773	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
774	if serviceName == "" {
775		return nil, errors.New("parameter serviceName cannot be empty")
776	}
777	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
778	if apiID == "" {
779		return nil, errors.New("parameter apiID cannot be empty")
780	}
781	urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
782	if operationID == "" {
783		return nil, errors.New("parameter operationID cannot be empty")
784	}
785	urlPath = strings.ReplaceAll(urlPath, "{operationId}", url.PathEscape(operationID))
786	if tagID == "" {
787		return nil, errors.New("parameter tagID cannot be empty")
788	}
789	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
790	if client.subscriptionID == "" {
791		return nil, errors.New("parameter client.subscriptionID cannot be empty")
792	}
793	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
794	req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath))
795	if err != nil {
796		return nil, err
797	}
798	req.Telemetry(telemetryInfo)
799	reqQP := req.URL.Query()
800	reqQP.Set("api-version", "2020-12-01")
801	req.URL.RawQuery = reqQP.Encode()
802	req.Header.Set("Accept", "application/json")
803	return req, nil
804}
805
806// getByOperationHandleResponse handles the GetByOperation response.
807func (client *TagClient) getByOperationHandleResponse(resp *azcore.Response) (TagGetByOperationResponse, error) {
808	result := TagGetByOperationResponse{RawResponse: resp.Response}
809	if val := resp.Header.Get("ETag"); val != "" {
810		result.ETag = &val
811	}
812	if err := resp.UnmarshalAsJSON(&result.TagContract); err != nil {
813		return TagGetByOperationResponse{}, err
814	}
815	return result, nil
816}
817
818// getByOperationHandleError handles the GetByOperation error response.
819func (client *TagClient) getByOperationHandleError(resp *azcore.Response) error {
820	body, err := resp.Payload()
821	if err != nil {
822		return azcore.NewResponseError(err, resp.Response)
823	}
824	errType := ErrorResponse{raw: string(body)}
825	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
826		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
827	}
828	return azcore.NewResponseError(&errType, resp.Response)
829}
830
831// GetByProduct - Get tag associated with the Product.
832// If the operation fails it returns the *ErrorResponse error type.
833func (client *TagClient) GetByProduct(ctx context.Context, resourceGroupName string, serviceName string, productID string, tagID string, options *TagGetByProductOptions) (TagGetByProductResponse, error) {
834	req, err := client.getByProductCreateRequest(ctx, resourceGroupName, serviceName, productID, tagID, options)
835	if err != nil {
836		return TagGetByProductResponse{}, err
837	}
838	resp, err := client.con.Pipeline().Do(req)
839	if err != nil {
840		return TagGetByProductResponse{}, err
841	}
842	if !resp.HasStatusCode(http.StatusOK) {
843		return TagGetByProductResponse{}, client.getByProductHandleError(resp)
844	}
845	return client.getByProductHandleResponse(resp)
846}
847
848// getByProductCreateRequest creates the GetByProduct request.
849func (client *TagClient) getByProductCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, productID string, tagID string, options *TagGetByProductOptions) (*azcore.Request, error) {
850	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}/tags/{tagId}"
851	if resourceGroupName == "" {
852		return nil, errors.New("parameter resourceGroupName cannot be empty")
853	}
854	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
855	if serviceName == "" {
856		return nil, errors.New("parameter serviceName cannot be empty")
857	}
858	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
859	if productID == "" {
860		return nil, errors.New("parameter productID cannot be empty")
861	}
862	urlPath = strings.ReplaceAll(urlPath, "{productId}", url.PathEscape(productID))
863	if tagID == "" {
864		return nil, errors.New("parameter tagID cannot be empty")
865	}
866	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
867	if client.subscriptionID == "" {
868		return nil, errors.New("parameter client.subscriptionID cannot be empty")
869	}
870	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
871	req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath))
872	if err != nil {
873		return nil, err
874	}
875	req.Telemetry(telemetryInfo)
876	reqQP := req.URL.Query()
877	reqQP.Set("api-version", "2020-12-01")
878	req.URL.RawQuery = reqQP.Encode()
879	req.Header.Set("Accept", "application/json")
880	return req, nil
881}
882
883// getByProductHandleResponse handles the GetByProduct response.
884func (client *TagClient) getByProductHandleResponse(resp *azcore.Response) (TagGetByProductResponse, error) {
885	result := TagGetByProductResponse{RawResponse: resp.Response}
886	if val := resp.Header.Get("ETag"); val != "" {
887		result.ETag = &val
888	}
889	if err := resp.UnmarshalAsJSON(&result.TagContract); err != nil {
890		return TagGetByProductResponse{}, err
891	}
892	return result, nil
893}
894
895// getByProductHandleError handles the GetByProduct error response.
896func (client *TagClient) getByProductHandleError(resp *azcore.Response) error {
897	body, err := resp.Payload()
898	if err != nil {
899		return azcore.NewResponseError(err, resp.Response)
900	}
901	errType := ErrorResponse{raw: string(body)}
902	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
903		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
904	}
905	return azcore.NewResponseError(&errType, resp.Response)
906}
907
908// GetEntityState - Gets the entity state version of the tag specified by its identifier.
909// If the operation fails it returns the *ErrorResponse error type.
910func (client *TagClient) GetEntityState(ctx context.Context, resourceGroupName string, serviceName string, tagID string, options *TagGetEntityStateOptions) (TagGetEntityStateResponse, error) {
911	req, err := client.getEntityStateCreateRequest(ctx, resourceGroupName, serviceName, tagID, options)
912	if err != nil {
913		return TagGetEntityStateResponse{}, err
914	}
915	resp, err := client.con.Pipeline().Do(req)
916	if err != nil {
917		return TagGetEntityStateResponse{}, err
918	}
919	return client.getEntityStateHandleResponse(resp)
920}
921
922// getEntityStateCreateRequest creates the GetEntityState request.
923func (client *TagClient) getEntityStateCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, tagID string, options *TagGetEntityStateOptions) (*azcore.Request, error) {
924	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tags/{tagId}"
925	if resourceGroupName == "" {
926		return nil, errors.New("parameter resourceGroupName cannot be empty")
927	}
928	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
929	if serviceName == "" {
930		return nil, errors.New("parameter serviceName cannot be empty")
931	}
932	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
933	if tagID == "" {
934		return nil, errors.New("parameter tagID cannot be empty")
935	}
936	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
937	if client.subscriptionID == "" {
938		return nil, errors.New("parameter client.subscriptionID cannot be empty")
939	}
940	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
941	req, err := azcore.NewRequest(ctx, http.MethodHead, azcore.JoinPaths(client.con.Endpoint(), urlPath))
942	if err != nil {
943		return nil, err
944	}
945	req.Telemetry(telemetryInfo)
946	reqQP := req.URL.Query()
947	reqQP.Set("api-version", "2020-12-01")
948	req.URL.RawQuery = reqQP.Encode()
949	req.Header.Set("Accept", "application/json")
950	return req, nil
951}
952
953// getEntityStateHandleResponse handles the GetEntityState response.
954func (client *TagClient) getEntityStateHandleResponse(resp *azcore.Response) (TagGetEntityStateResponse, error) {
955	result := TagGetEntityStateResponse{RawResponse: resp.Response}
956	if val := resp.Header.Get("ETag"); val != "" {
957		result.ETag = &val
958	}
959	if resp.StatusCode >= 200 && resp.StatusCode < 300 {
960		result.Success = true
961	}
962	return result, nil
963}
964
965// GetEntityStateByAPI - Gets the entity state version of the tag specified by its identifier.
966// If the operation fails it returns the *ErrorResponse error type.
967func (client *TagClient) GetEntityStateByAPI(ctx context.Context, resourceGroupName string, serviceName string, apiID string, tagID string, options *TagGetEntityStateByAPIOptions) (TagGetEntityStateByAPIResponse, error) {
968	req, err := client.getEntityStateByAPICreateRequest(ctx, resourceGroupName, serviceName, apiID, tagID, options)
969	if err != nil {
970		return TagGetEntityStateByAPIResponse{}, err
971	}
972	resp, err := client.con.Pipeline().Do(req)
973	if err != nil {
974		return TagGetEntityStateByAPIResponse{}, err
975	}
976	return client.getEntityStateByAPIHandleResponse(resp)
977}
978
979// getEntityStateByAPICreateRequest creates the GetEntityStateByAPI request.
980func (client *TagClient) getEntityStateByAPICreateRequest(ctx context.Context, resourceGroupName string, serviceName string, apiID string, tagID string, options *TagGetEntityStateByAPIOptions) (*azcore.Request, error) {
981	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tags/{tagId}"
982	if resourceGroupName == "" {
983		return nil, errors.New("parameter resourceGroupName cannot be empty")
984	}
985	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
986	if serviceName == "" {
987		return nil, errors.New("parameter serviceName cannot be empty")
988	}
989	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
990	if apiID == "" {
991		return nil, errors.New("parameter apiID cannot be empty")
992	}
993	urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
994	if tagID == "" {
995		return nil, errors.New("parameter tagID cannot be empty")
996	}
997	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
998	if client.subscriptionID == "" {
999		return nil, errors.New("parameter client.subscriptionID cannot be empty")
1000	}
1001	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
1002	req, err := azcore.NewRequest(ctx, http.MethodHead, azcore.JoinPaths(client.con.Endpoint(), urlPath))
1003	if err != nil {
1004		return nil, err
1005	}
1006	req.Telemetry(telemetryInfo)
1007	reqQP := req.URL.Query()
1008	reqQP.Set("api-version", "2020-12-01")
1009	req.URL.RawQuery = reqQP.Encode()
1010	req.Header.Set("Accept", "application/json")
1011	return req, nil
1012}
1013
1014// getEntityStateByAPIHandleResponse handles the GetEntityStateByAPI response.
1015func (client *TagClient) getEntityStateByAPIHandleResponse(resp *azcore.Response) (TagGetEntityStateByAPIResponse, error) {
1016	result := TagGetEntityStateByAPIResponse{RawResponse: resp.Response}
1017	if val := resp.Header.Get("ETag"); val != "" {
1018		result.ETag = &val
1019	}
1020	if resp.StatusCode >= 200 && resp.StatusCode < 300 {
1021		result.Success = true
1022	}
1023	return result, nil
1024}
1025
1026// GetEntityStateByOperation - Gets the entity state version of the tag specified by its identifier.
1027// If the operation fails it returns the *ErrorResponse error type.
1028func (client *TagClient) GetEntityStateByOperation(ctx context.Context, resourceGroupName string, serviceName string, apiID string, operationID string, tagID string, options *TagGetEntityStateByOperationOptions) (TagGetEntityStateByOperationResponse, error) {
1029	req, err := client.getEntityStateByOperationCreateRequest(ctx, resourceGroupName, serviceName, apiID, operationID, tagID, options)
1030	if err != nil {
1031		return TagGetEntityStateByOperationResponse{}, err
1032	}
1033	resp, err := client.con.Pipeline().Do(req)
1034	if err != nil {
1035		return TagGetEntityStateByOperationResponse{}, err
1036	}
1037	return client.getEntityStateByOperationHandleResponse(resp)
1038}
1039
1040// getEntityStateByOperationCreateRequest creates the GetEntityStateByOperation request.
1041func (client *TagClient) getEntityStateByOperationCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, apiID string, operationID string, tagID string, options *TagGetEntityStateByOperationOptions) (*azcore.Request, error) {
1042	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}/tags/{tagId}"
1043	if resourceGroupName == "" {
1044		return nil, errors.New("parameter resourceGroupName cannot be empty")
1045	}
1046	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
1047	if serviceName == "" {
1048		return nil, errors.New("parameter serviceName cannot be empty")
1049	}
1050	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
1051	if apiID == "" {
1052		return nil, errors.New("parameter apiID cannot be empty")
1053	}
1054	urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
1055	if operationID == "" {
1056		return nil, errors.New("parameter operationID cannot be empty")
1057	}
1058	urlPath = strings.ReplaceAll(urlPath, "{operationId}", url.PathEscape(operationID))
1059	if tagID == "" {
1060		return nil, errors.New("parameter tagID cannot be empty")
1061	}
1062	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
1063	if client.subscriptionID == "" {
1064		return nil, errors.New("parameter client.subscriptionID cannot be empty")
1065	}
1066	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
1067	req, err := azcore.NewRequest(ctx, http.MethodHead, azcore.JoinPaths(client.con.Endpoint(), urlPath))
1068	if err != nil {
1069		return nil, err
1070	}
1071	req.Telemetry(telemetryInfo)
1072	reqQP := req.URL.Query()
1073	reqQP.Set("api-version", "2020-12-01")
1074	req.URL.RawQuery = reqQP.Encode()
1075	req.Header.Set("Accept", "application/json")
1076	return req, nil
1077}
1078
1079// getEntityStateByOperationHandleResponse handles the GetEntityStateByOperation response.
1080func (client *TagClient) getEntityStateByOperationHandleResponse(resp *azcore.Response) (TagGetEntityStateByOperationResponse, error) {
1081	result := TagGetEntityStateByOperationResponse{RawResponse: resp.Response}
1082	if val := resp.Header.Get("ETag"); val != "" {
1083		result.ETag = &val
1084	}
1085	if resp.StatusCode >= 200 && resp.StatusCode < 300 {
1086		result.Success = true
1087	}
1088	return result, nil
1089}
1090
1091// GetEntityStateByProduct - Gets the entity state version of the tag specified by its identifier.
1092// If the operation fails it returns the *ErrorResponse error type.
1093func (client *TagClient) GetEntityStateByProduct(ctx context.Context, resourceGroupName string, serviceName string, productID string, tagID string, options *TagGetEntityStateByProductOptions) (TagGetEntityStateByProductResponse, error) {
1094	req, err := client.getEntityStateByProductCreateRequest(ctx, resourceGroupName, serviceName, productID, tagID, options)
1095	if err != nil {
1096		return TagGetEntityStateByProductResponse{}, err
1097	}
1098	resp, err := client.con.Pipeline().Do(req)
1099	if err != nil {
1100		return TagGetEntityStateByProductResponse{}, err
1101	}
1102	return client.getEntityStateByProductHandleResponse(resp)
1103}
1104
1105// getEntityStateByProductCreateRequest creates the GetEntityStateByProduct request.
1106func (client *TagClient) getEntityStateByProductCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, productID string, tagID string, options *TagGetEntityStateByProductOptions) (*azcore.Request, error) {
1107	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}/tags/{tagId}"
1108	if resourceGroupName == "" {
1109		return nil, errors.New("parameter resourceGroupName cannot be empty")
1110	}
1111	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
1112	if serviceName == "" {
1113		return nil, errors.New("parameter serviceName cannot be empty")
1114	}
1115	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
1116	if productID == "" {
1117		return nil, errors.New("parameter productID cannot be empty")
1118	}
1119	urlPath = strings.ReplaceAll(urlPath, "{productId}", url.PathEscape(productID))
1120	if tagID == "" {
1121		return nil, errors.New("parameter tagID cannot be empty")
1122	}
1123	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
1124	if client.subscriptionID == "" {
1125		return nil, errors.New("parameter client.subscriptionID cannot be empty")
1126	}
1127	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
1128	req, err := azcore.NewRequest(ctx, http.MethodHead, azcore.JoinPaths(client.con.Endpoint(), urlPath))
1129	if err != nil {
1130		return nil, err
1131	}
1132	req.Telemetry(telemetryInfo)
1133	reqQP := req.URL.Query()
1134	reqQP.Set("api-version", "2020-12-01")
1135	req.URL.RawQuery = reqQP.Encode()
1136	req.Header.Set("Accept", "application/json")
1137	return req, nil
1138}
1139
1140// getEntityStateByProductHandleResponse handles the GetEntityStateByProduct response.
1141func (client *TagClient) getEntityStateByProductHandleResponse(resp *azcore.Response) (TagGetEntityStateByProductResponse, error) {
1142	result := TagGetEntityStateByProductResponse{RawResponse: resp.Response}
1143	if val := resp.Header.Get("ETag"); val != "" {
1144		result.ETag = &val
1145	}
1146	if resp.StatusCode >= 200 && resp.StatusCode < 300 {
1147		result.Success = true
1148	}
1149	return result, nil
1150}
1151
1152// ListByAPI - Lists all Tags associated with the API.
1153// If the operation fails it returns the *ErrorResponse error type.
1154func (client *TagClient) ListByAPI(resourceGroupName string, serviceName string, apiID string, options *TagListByAPIOptions) TagListByAPIPager {
1155	return &tagListByAPIPager{
1156		client: client,
1157		requester: func(ctx context.Context) (*azcore.Request, error) {
1158			return client.listByAPICreateRequest(ctx, resourceGroupName, serviceName, apiID, options)
1159		},
1160		advancer: func(ctx context.Context, resp TagListByAPIResponse) (*azcore.Request, error) {
1161			return azcore.NewRequest(ctx, http.MethodGet, *resp.TagCollection.NextLink)
1162		},
1163	}
1164}
1165
1166// listByAPICreateRequest creates the ListByAPI request.
1167func (client *TagClient) listByAPICreateRequest(ctx context.Context, resourceGroupName string, serviceName string, apiID string, options *TagListByAPIOptions) (*azcore.Request, error) {
1168	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tags"
1169	if resourceGroupName == "" {
1170		return nil, errors.New("parameter resourceGroupName cannot be empty")
1171	}
1172	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
1173	if serviceName == "" {
1174		return nil, errors.New("parameter serviceName cannot be empty")
1175	}
1176	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
1177	if apiID == "" {
1178		return nil, errors.New("parameter apiID cannot be empty")
1179	}
1180	urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
1181	if client.subscriptionID == "" {
1182		return nil, errors.New("parameter client.subscriptionID cannot be empty")
1183	}
1184	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
1185	req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath))
1186	if err != nil {
1187		return nil, err
1188	}
1189	req.Telemetry(telemetryInfo)
1190	reqQP := req.URL.Query()
1191	if options != nil && options.Filter != nil {
1192		reqQP.Set("$filter", *options.Filter)
1193	}
1194	if options != nil && options.Top != nil {
1195		reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10))
1196	}
1197	if options != nil && options.Skip != nil {
1198		reqQP.Set("$skip", strconv.FormatInt(int64(*options.Skip), 10))
1199	}
1200	reqQP.Set("api-version", "2020-12-01")
1201	req.URL.RawQuery = reqQP.Encode()
1202	req.Header.Set("Accept", "application/json")
1203	return req, nil
1204}
1205
1206// listByAPIHandleResponse handles the ListByAPI response.
1207func (client *TagClient) listByAPIHandleResponse(resp *azcore.Response) (TagListByAPIResponse, error) {
1208	result := TagListByAPIResponse{RawResponse: resp.Response}
1209	if err := resp.UnmarshalAsJSON(&result.TagCollection); err != nil {
1210		return TagListByAPIResponse{}, err
1211	}
1212	return result, nil
1213}
1214
1215// listByAPIHandleError handles the ListByAPI error response.
1216func (client *TagClient) listByAPIHandleError(resp *azcore.Response) error {
1217	body, err := resp.Payload()
1218	if err != nil {
1219		return azcore.NewResponseError(err, resp.Response)
1220	}
1221	errType := ErrorResponse{raw: string(body)}
1222	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
1223		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
1224	}
1225	return azcore.NewResponseError(&errType, resp.Response)
1226}
1227
1228// ListByOperation - Lists all Tags associated with the Operation.
1229// If the operation fails it returns the *ErrorResponse error type.
1230func (client *TagClient) ListByOperation(resourceGroupName string, serviceName string, apiID string, operationID string, options *TagListByOperationOptions) TagListByOperationPager {
1231	return &tagListByOperationPager{
1232		client: client,
1233		requester: func(ctx context.Context) (*azcore.Request, error) {
1234			return client.listByOperationCreateRequest(ctx, resourceGroupName, serviceName, apiID, operationID, options)
1235		},
1236		advancer: func(ctx context.Context, resp TagListByOperationResponse) (*azcore.Request, error) {
1237			return azcore.NewRequest(ctx, http.MethodGet, *resp.TagCollection.NextLink)
1238		},
1239	}
1240}
1241
1242// listByOperationCreateRequest creates the ListByOperation request.
1243func (client *TagClient) listByOperationCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, apiID string, operationID string, options *TagListByOperationOptions) (*azcore.Request, error) {
1244	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}/tags"
1245	if resourceGroupName == "" {
1246		return nil, errors.New("parameter resourceGroupName cannot be empty")
1247	}
1248	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
1249	if serviceName == "" {
1250		return nil, errors.New("parameter serviceName cannot be empty")
1251	}
1252	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
1253	if apiID == "" {
1254		return nil, errors.New("parameter apiID cannot be empty")
1255	}
1256	urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
1257	if operationID == "" {
1258		return nil, errors.New("parameter operationID cannot be empty")
1259	}
1260	urlPath = strings.ReplaceAll(urlPath, "{operationId}", url.PathEscape(operationID))
1261	if client.subscriptionID == "" {
1262		return nil, errors.New("parameter client.subscriptionID cannot be empty")
1263	}
1264	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
1265	req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath))
1266	if err != nil {
1267		return nil, err
1268	}
1269	req.Telemetry(telemetryInfo)
1270	reqQP := req.URL.Query()
1271	if options != nil && options.Filter != nil {
1272		reqQP.Set("$filter", *options.Filter)
1273	}
1274	if options != nil && options.Top != nil {
1275		reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10))
1276	}
1277	if options != nil && options.Skip != nil {
1278		reqQP.Set("$skip", strconv.FormatInt(int64(*options.Skip), 10))
1279	}
1280	reqQP.Set("api-version", "2020-12-01")
1281	req.URL.RawQuery = reqQP.Encode()
1282	req.Header.Set("Accept", "application/json")
1283	return req, nil
1284}
1285
1286// listByOperationHandleResponse handles the ListByOperation response.
1287func (client *TagClient) listByOperationHandleResponse(resp *azcore.Response) (TagListByOperationResponse, error) {
1288	result := TagListByOperationResponse{RawResponse: resp.Response}
1289	if err := resp.UnmarshalAsJSON(&result.TagCollection); err != nil {
1290		return TagListByOperationResponse{}, err
1291	}
1292	return result, nil
1293}
1294
1295// listByOperationHandleError handles the ListByOperation error response.
1296func (client *TagClient) listByOperationHandleError(resp *azcore.Response) error {
1297	body, err := resp.Payload()
1298	if err != nil {
1299		return azcore.NewResponseError(err, resp.Response)
1300	}
1301	errType := ErrorResponse{raw: string(body)}
1302	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
1303		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
1304	}
1305	return azcore.NewResponseError(&errType, resp.Response)
1306}
1307
1308// ListByProduct - Lists all Tags associated with the Product.
1309// If the operation fails it returns the *ErrorResponse error type.
1310func (client *TagClient) ListByProduct(resourceGroupName string, serviceName string, productID string, options *TagListByProductOptions) TagListByProductPager {
1311	return &tagListByProductPager{
1312		client: client,
1313		requester: func(ctx context.Context) (*azcore.Request, error) {
1314			return client.listByProductCreateRequest(ctx, resourceGroupName, serviceName, productID, options)
1315		},
1316		advancer: func(ctx context.Context, resp TagListByProductResponse) (*azcore.Request, error) {
1317			return azcore.NewRequest(ctx, http.MethodGet, *resp.TagCollection.NextLink)
1318		},
1319	}
1320}
1321
1322// listByProductCreateRequest creates the ListByProduct request.
1323func (client *TagClient) listByProductCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, productID string, options *TagListByProductOptions) (*azcore.Request, error) {
1324	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}/tags"
1325	if resourceGroupName == "" {
1326		return nil, errors.New("parameter resourceGroupName cannot be empty")
1327	}
1328	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
1329	if serviceName == "" {
1330		return nil, errors.New("parameter serviceName cannot be empty")
1331	}
1332	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
1333	if productID == "" {
1334		return nil, errors.New("parameter productID cannot be empty")
1335	}
1336	urlPath = strings.ReplaceAll(urlPath, "{productId}", url.PathEscape(productID))
1337	if client.subscriptionID == "" {
1338		return nil, errors.New("parameter client.subscriptionID cannot be empty")
1339	}
1340	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
1341	req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath))
1342	if err != nil {
1343		return nil, err
1344	}
1345	req.Telemetry(telemetryInfo)
1346	reqQP := req.URL.Query()
1347	if options != nil && options.Filter != nil {
1348		reqQP.Set("$filter", *options.Filter)
1349	}
1350	if options != nil && options.Top != nil {
1351		reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10))
1352	}
1353	if options != nil && options.Skip != nil {
1354		reqQP.Set("$skip", strconv.FormatInt(int64(*options.Skip), 10))
1355	}
1356	reqQP.Set("api-version", "2020-12-01")
1357	req.URL.RawQuery = reqQP.Encode()
1358	req.Header.Set("Accept", "application/json")
1359	return req, nil
1360}
1361
1362// listByProductHandleResponse handles the ListByProduct response.
1363func (client *TagClient) listByProductHandleResponse(resp *azcore.Response) (TagListByProductResponse, error) {
1364	result := TagListByProductResponse{RawResponse: resp.Response}
1365	if err := resp.UnmarshalAsJSON(&result.TagCollection); err != nil {
1366		return TagListByProductResponse{}, err
1367	}
1368	return result, nil
1369}
1370
1371// listByProductHandleError handles the ListByProduct error response.
1372func (client *TagClient) listByProductHandleError(resp *azcore.Response) error {
1373	body, err := resp.Payload()
1374	if err != nil {
1375		return azcore.NewResponseError(err, resp.Response)
1376	}
1377	errType := ErrorResponse{raw: string(body)}
1378	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
1379		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
1380	}
1381	return azcore.NewResponseError(&errType, resp.Response)
1382}
1383
1384// ListByService - Lists a collection of tags defined within a service instance.
1385// If the operation fails it returns the *ErrorResponse error type.
1386func (client *TagClient) ListByService(resourceGroupName string, serviceName string, options *TagListByServiceOptions) TagListByServicePager {
1387	return &tagListByServicePager{
1388		client: client,
1389		requester: func(ctx context.Context) (*azcore.Request, error) {
1390			return client.listByServiceCreateRequest(ctx, resourceGroupName, serviceName, options)
1391		},
1392		advancer: func(ctx context.Context, resp TagListByServiceResponse) (*azcore.Request, error) {
1393			return azcore.NewRequest(ctx, http.MethodGet, *resp.TagCollection.NextLink)
1394		},
1395	}
1396}
1397
1398// listByServiceCreateRequest creates the ListByService request.
1399func (client *TagClient) listByServiceCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, options *TagListByServiceOptions) (*azcore.Request, error) {
1400	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tags"
1401	if resourceGroupName == "" {
1402		return nil, errors.New("parameter resourceGroupName cannot be empty")
1403	}
1404	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
1405	if serviceName == "" {
1406		return nil, errors.New("parameter serviceName cannot be empty")
1407	}
1408	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
1409	if client.subscriptionID == "" {
1410		return nil, errors.New("parameter client.subscriptionID cannot be empty")
1411	}
1412	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
1413	req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath))
1414	if err != nil {
1415		return nil, err
1416	}
1417	req.Telemetry(telemetryInfo)
1418	reqQP := req.URL.Query()
1419	if options != nil && options.Filter != nil {
1420		reqQP.Set("$filter", *options.Filter)
1421	}
1422	if options != nil && options.Top != nil {
1423		reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10))
1424	}
1425	if options != nil && options.Skip != nil {
1426		reqQP.Set("$skip", strconv.FormatInt(int64(*options.Skip), 10))
1427	}
1428	if options != nil && options.Scope != nil {
1429		reqQP.Set("scope", *options.Scope)
1430	}
1431	reqQP.Set("api-version", "2020-12-01")
1432	req.URL.RawQuery = reqQP.Encode()
1433	req.Header.Set("Accept", "application/json")
1434	return req, nil
1435}
1436
1437// listByServiceHandleResponse handles the ListByService response.
1438func (client *TagClient) listByServiceHandleResponse(resp *azcore.Response) (TagListByServiceResponse, error) {
1439	result := TagListByServiceResponse{RawResponse: resp.Response}
1440	if err := resp.UnmarshalAsJSON(&result.TagCollection); err != nil {
1441		return TagListByServiceResponse{}, err
1442	}
1443	return result, nil
1444}
1445
1446// listByServiceHandleError handles the ListByService error response.
1447func (client *TagClient) listByServiceHandleError(resp *azcore.Response) error {
1448	body, err := resp.Payload()
1449	if err != nil {
1450		return azcore.NewResponseError(err, resp.Response)
1451	}
1452	errType := ErrorResponse{raw: string(body)}
1453	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
1454		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
1455	}
1456	return azcore.NewResponseError(&errType, resp.Response)
1457}
1458
1459// Update - Updates the details of the tag specified by its identifier.
1460// If the operation fails it returns the *ErrorResponse error type.
1461func (client *TagClient) Update(ctx context.Context, resourceGroupName string, serviceName string, tagID string, ifMatch string, parameters TagCreateUpdateParameters, options *TagUpdateOptions) (TagUpdateResponse, error) {
1462	req, err := client.updateCreateRequest(ctx, resourceGroupName, serviceName, tagID, ifMatch, parameters, options)
1463	if err != nil {
1464		return TagUpdateResponse{}, err
1465	}
1466	resp, err := client.con.Pipeline().Do(req)
1467	if err != nil {
1468		return TagUpdateResponse{}, err
1469	}
1470	if !resp.HasStatusCode(http.StatusOK) {
1471		return TagUpdateResponse{}, client.updateHandleError(resp)
1472	}
1473	return client.updateHandleResponse(resp)
1474}
1475
1476// updateCreateRequest creates the Update request.
1477func (client *TagClient) updateCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, tagID string, ifMatch string, parameters TagCreateUpdateParameters, options *TagUpdateOptions) (*azcore.Request, error) {
1478	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tags/{tagId}"
1479	if resourceGroupName == "" {
1480		return nil, errors.New("parameter resourceGroupName cannot be empty")
1481	}
1482	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
1483	if serviceName == "" {
1484		return nil, errors.New("parameter serviceName cannot be empty")
1485	}
1486	urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
1487	if tagID == "" {
1488		return nil, errors.New("parameter tagID cannot be empty")
1489	}
1490	urlPath = strings.ReplaceAll(urlPath, "{tagId}", url.PathEscape(tagID))
1491	if client.subscriptionID == "" {
1492		return nil, errors.New("parameter client.subscriptionID cannot be empty")
1493	}
1494	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
1495	req, err := azcore.NewRequest(ctx, http.MethodPatch, azcore.JoinPaths(client.con.Endpoint(), urlPath))
1496	if err != nil {
1497		return nil, err
1498	}
1499	req.Telemetry(telemetryInfo)
1500	reqQP := req.URL.Query()
1501	reqQP.Set("api-version", "2020-12-01")
1502	req.URL.RawQuery = reqQP.Encode()
1503	req.Header.Set("If-Match", ifMatch)
1504	req.Header.Set("Accept", "application/json")
1505	return req, req.MarshalAsJSON(parameters)
1506}
1507
1508// updateHandleResponse handles the Update response.
1509func (client *TagClient) updateHandleResponse(resp *azcore.Response) (TagUpdateResponse, error) {
1510	result := TagUpdateResponse{RawResponse: resp.Response}
1511	if val := resp.Header.Get("ETag"); val != "" {
1512		result.ETag = &val
1513	}
1514	if err := resp.UnmarshalAsJSON(&result.TagContract); err != nil {
1515		return TagUpdateResponse{}, err
1516	}
1517	return result, nil
1518}
1519
1520// updateHandleError handles the Update error response.
1521func (client *TagClient) updateHandleError(resp *azcore.Response) error {
1522	body, err := resp.Payload()
1523	if err != nil {
1524		return azcore.NewResponseError(err, resp.Response)
1525	}
1526	errType := ErrorResponse{raw: string(body)}
1527	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
1528		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
1529	}
1530	return azcore.NewResponseError(&errType, resp.Response)
1531}
1532