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