1package apimanagement
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// ReportsClient is the apiManagement Client
30type ReportsClient struct {
31	BaseClient
32}
33
34// NewReportsClient creates an instance of the ReportsClient client.
35func NewReportsClient(subscriptionID string) ReportsClient {
36	return NewReportsClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewReportsClientWithBaseURI creates an instance of the ReportsClient client.
40func NewReportsClientWithBaseURI(baseURI string, subscriptionID string) ReportsClient {
41	return ReportsClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// ListByAPI lists report records by API.
45// Parameters:
46// resourceGroupName - the name of the resource group.
47// serviceName - the name of the API Management service.
48// filter - the filter to apply on the operation.
49// top - number of records to return.
50// skip - number of records to skip.
51func (client ReportsClient) ListByAPI(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result ReportCollectionPage, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListByAPI")
54		defer func() {
55			sc := -1
56			if result.rc.Response.Response != nil {
57				sc = result.rc.Response.Response.StatusCode
58			}
59			tracing.EndSpan(ctx, sc, err)
60		}()
61	}
62	if err := validation.Validate([]validation.Validation{
63		{TargetValue: serviceName,
64			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
65				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
66				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
67		{TargetValue: top,
68			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
69				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
70		{TargetValue: skip,
71			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
72				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
73		return result, validation.NewError("apimanagement.ReportsClient", "ListByAPI", err.Error())
74	}
75
76	result.fn = client.listByAPINextResults
77	req, err := client.ListByAPIPreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
78	if err != nil {
79		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByAPI", nil, "Failure preparing request")
80		return
81	}
82
83	resp, err := client.ListByAPISender(req)
84	if err != nil {
85		result.rc.Response = autorest.Response{Response: resp}
86		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByAPI", resp, "Failure sending request")
87		return
88	}
89
90	result.rc, err = client.ListByAPIResponder(resp)
91	if err != nil {
92		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByAPI", resp, "Failure responding to request")
93	}
94
95	return
96}
97
98// ListByAPIPreparer prepares the ListByAPI request.
99func (client ReportsClient) ListByAPIPreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
100	pathParameters := map[string]interface{}{
101		"resourceGroupName": autorest.Encode("path", resourceGroupName),
102		"serviceName":       autorest.Encode("path", serviceName),
103		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
104	}
105
106	const APIVersion = "2017-03-01"
107	queryParameters := map[string]interface{}{
108		"$filter":     autorest.Encode("query", filter),
109		"api-version": APIVersion,
110	}
111	if top != nil {
112		queryParameters["$top"] = autorest.Encode("query", *top)
113	}
114	if skip != nil {
115		queryParameters["$skip"] = autorest.Encode("query", *skip)
116	}
117
118	preparer := autorest.CreatePreparer(
119		autorest.AsGet(),
120		autorest.WithBaseURL(client.BaseURI),
121		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/reports/byApi", pathParameters),
122		autorest.WithQueryParameters(queryParameters))
123	return preparer.Prepare((&http.Request{}).WithContext(ctx))
124}
125
126// ListByAPISender sends the ListByAPI request. The method will close the
127// http.Response Body if it receives an error.
128func (client ReportsClient) ListByAPISender(req *http.Request) (*http.Response, error) {
129	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
130	return autorest.SendWithSender(client, req, sd...)
131}
132
133// ListByAPIResponder handles the response to the ListByAPI request. The method always
134// closes the http.Response Body.
135func (client ReportsClient) ListByAPIResponder(resp *http.Response) (result ReportCollection, err error) {
136	err = autorest.Respond(
137		resp,
138		client.ByInspecting(),
139		azure.WithErrorUnlessStatusCode(http.StatusOK),
140		autorest.ByUnmarshallingJSON(&result),
141		autorest.ByClosing())
142	result.Response = autorest.Response{Response: resp}
143	return
144}
145
146// listByAPINextResults retrieves the next set of results, if any.
147func (client ReportsClient) listByAPINextResults(ctx context.Context, lastResults ReportCollection) (result ReportCollection, err error) {
148	req, err := lastResults.reportCollectionPreparer(ctx)
149	if err != nil {
150		return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByAPINextResults", nil, "Failure preparing next results request")
151	}
152	if req == nil {
153		return
154	}
155	resp, err := client.ListByAPISender(req)
156	if err != nil {
157		result.Response = autorest.Response{Response: resp}
158		return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByAPINextResults", resp, "Failure sending next results request")
159	}
160	result, err = client.ListByAPIResponder(resp)
161	if err != nil {
162		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByAPINextResults", resp, "Failure responding to next results request")
163	}
164	return
165}
166
167// ListByAPIComplete enumerates all values, automatically crossing page boundaries as required.
168func (client ReportsClient) ListByAPIComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result ReportCollectionIterator, err error) {
169	if tracing.IsEnabled() {
170		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListByAPI")
171		defer func() {
172			sc := -1
173			if result.Response().Response.Response != nil {
174				sc = result.page.Response().Response.Response.StatusCode
175			}
176			tracing.EndSpan(ctx, sc, err)
177		}()
178	}
179	result.page, err = client.ListByAPI(ctx, resourceGroupName, serviceName, filter, top, skip)
180	return
181}
182
183// ListByGeo lists report records by geography.
184// Parameters:
185// resourceGroupName - the name of the resource group.
186// serviceName - the name of the API Management service.
187// filter - the filter to apply on the operation.
188// top - number of records to return.
189// skip - number of records to skip.
190func (client ReportsClient) ListByGeo(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result ReportCollectionPage, err error) {
191	if tracing.IsEnabled() {
192		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListByGeo")
193		defer func() {
194			sc := -1
195			if result.rc.Response.Response != nil {
196				sc = result.rc.Response.Response.StatusCode
197			}
198			tracing.EndSpan(ctx, sc, err)
199		}()
200	}
201	if err := validation.Validate([]validation.Validation{
202		{TargetValue: serviceName,
203			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
204				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
205				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
206		{TargetValue: top,
207			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
208				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
209		{TargetValue: skip,
210			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
211				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
212		return result, validation.NewError("apimanagement.ReportsClient", "ListByGeo", err.Error())
213	}
214
215	result.fn = client.listByGeoNextResults
216	req, err := client.ListByGeoPreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
217	if err != nil {
218		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByGeo", nil, "Failure preparing request")
219		return
220	}
221
222	resp, err := client.ListByGeoSender(req)
223	if err != nil {
224		result.rc.Response = autorest.Response{Response: resp}
225		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByGeo", resp, "Failure sending request")
226		return
227	}
228
229	result.rc, err = client.ListByGeoResponder(resp)
230	if err != nil {
231		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByGeo", resp, "Failure responding to request")
232	}
233
234	return
235}
236
237// ListByGeoPreparer prepares the ListByGeo request.
238func (client ReportsClient) ListByGeoPreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
239	pathParameters := map[string]interface{}{
240		"resourceGroupName": autorest.Encode("path", resourceGroupName),
241		"serviceName":       autorest.Encode("path", serviceName),
242		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
243	}
244
245	const APIVersion = "2017-03-01"
246	queryParameters := map[string]interface{}{
247		"api-version": APIVersion,
248	}
249	if len(filter) > 0 {
250		queryParameters["$filter"] = autorest.Encode("query", filter)
251	}
252	if top != nil {
253		queryParameters["$top"] = autorest.Encode("query", *top)
254	}
255	if skip != nil {
256		queryParameters["$skip"] = autorest.Encode("query", *skip)
257	}
258
259	preparer := autorest.CreatePreparer(
260		autorest.AsGet(),
261		autorest.WithBaseURL(client.BaseURI),
262		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/reports/byGeo", pathParameters),
263		autorest.WithQueryParameters(queryParameters))
264	return preparer.Prepare((&http.Request{}).WithContext(ctx))
265}
266
267// ListByGeoSender sends the ListByGeo request. The method will close the
268// http.Response Body if it receives an error.
269func (client ReportsClient) ListByGeoSender(req *http.Request) (*http.Response, error) {
270	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
271	return autorest.SendWithSender(client, req, sd...)
272}
273
274// ListByGeoResponder handles the response to the ListByGeo request. The method always
275// closes the http.Response Body.
276func (client ReportsClient) ListByGeoResponder(resp *http.Response) (result ReportCollection, err error) {
277	err = autorest.Respond(
278		resp,
279		client.ByInspecting(),
280		azure.WithErrorUnlessStatusCode(http.StatusOK),
281		autorest.ByUnmarshallingJSON(&result),
282		autorest.ByClosing())
283	result.Response = autorest.Response{Response: resp}
284	return
285}
286
287// listByGeoNextResults retrieves the next set of results, if any.
288func (client ReportsClient) listByGeoNextResults(ctx context.Context, lastResults ReportCollection) (result ReportCollection, err error) {
289	req, err := lastResults.reportCollectionPreparer(ctx)
290	if err != nil {
291		return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByGeoNextResults", nil, "Failure preparing next results request")
292	}
293	if req == nil {
294		return
295	}
296	resp, err := client.ListByGeoSender(req)
297	if err != nil {
298		result.Response = autorest.Response{Response: resp}
299		return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByGeoNextResults", resp, "Failure sending next results request")
300	}
301	result, err = client.ListByGeoResponder(resp)
302	if err != nil {
303		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByGeoNextResults", resp, "Failure responding to next results request")
304	}
305	return
306}
307
308// ListByGeoComplete enumerates all values, automatically crossing page boundaries as required.
309func (client ReportsClient) ListByGeoComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result ReportCollectionIterator, err error) {
310	if tracing.IsEnabled() {
311		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListByGeo")
312		defer func() {
313			sc := -1
314			if result.Response().Response.Response != nil {
315				sc = result.page.Response().Response.Response.StatusCode
316			}
317			tracing.EndSpan(ctx, sc, err)
318		}()
319	}
320	result.page, err = client.ListByGeo(ctx, resourceGroupName, serviceName, filter, top, skip)
321	return
322}
323
324// ListByOperation lists report records by API Operations.
325// Parameters:
326// resourceGroupName - the name of the resource group.
327// serviceName - the name of the API Management service.
328// filter - the filter to apply on the operation.
329// top - number of records to return.
330// skip - number of records to skip.
331func (client ReportsClient) ListByOperation(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result ReportCollectionPage, err error) {
332	if tracing.IsEnabled() {
333		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListByOperation")
334		defer func() {
335			sc := -1
336			if result.rc.Response.Response != nil {
337				sc = result.rc.Response.Response.StatusCode
338			}
339			tracing.EndSpan(ctx, sc, err)
340		}()
341	}
342	if err := validation.Validate([]validation.Validation{
343		{TargetValue: serviceName,
344			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
345				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
346				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
347		{TargetValue: top,
348			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
349				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
350		{TargetValue: skip,
351			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
352				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
353		return result, validation.NewError("apimanagement.ReportsClient", "ListByOperation", err.Error())
354	}
355
356	result.fn = client.listByOperationNextResults
357	req, err := client.ListByOperationPreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
358	if err != nil {
359		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByOperation", nil, "Failure preparing request")
360		return
361	}
362
363	resp, err := client.ListByOperationSender(req)
364	if err != nil {
365		result.rc.Response = autorest.Response{Response: resp}
366		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByOperation", resp, "Failure sending request")
367		return
368	}
369
370	result.rc, err = client.ListByOperationResponder(resp)
371	if err != nil {
372		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByOperation", resp, "Failure responding to request")
373	}
374
375	return
376}
377
378// ListByOperationPreparer prepares the ListByOperation request.
379func (client ReportsClient) ListByOperationPreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
380	pathParameters := map[string]interface{}{
381		"resourceGroupName": autorest.Encode("path", resourceGroupName),
382		"serviceName":       autorest.Encode("path", serviceName),
383		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
384	}
385
386	const APIVersion = "2017-03-01"
387	queryParameters := map[string]interface{}{
388		"$filter":     autorest.Encode("query", filter),
389		"api-version": APIVersion,
390	}
391	if top != nil {
392		queryParameters["$top"] = autorest.Encode("query", *top)
393	}
394	if skip != nil {
395		queryParameters["$skip"] = autorest.Encode("query", *skip)
396	}
397
398	preparer := autorest.CreatePreparer(
399		autorest.AsGet(),
400		autorest.WithBaseURL(client.BaseURI),
401		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/reports/byOperation", pathParameters),
402		autorest.WithQueryParameters(queryParameters))
403	return preparer.Prepare((&http.Request{}).WithContext(ctx))
404}
405
406// ListByOperationSender sends the ListByOperation request. The method will close the
407// http.Response Body if it receives an error.
408func (client ReportsClient) ListByOperationSender(req *http.Request) (*http.Response, error) {
409	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
410	return autorest.SendWithSender(client, req, sd...)
411}
412
413// ListByOperationResponder handles the response to the ListByOperation request. The method always
414// closes the http.Response Body.
415func (client ReportsClient) ListByOperationResponder(resp *http.Response) (result ReportCollection, err error) {
416	err = autorest.Respond(
417		resp,
418		client.ByInspecting(),
419		azure.WithErrorUnlessStatusCode(http.StatusOK),
420		autorest.ByUnmarshallingJSON(&result),
421		autorest.ByClosing())
422	result.Response = autorest.Response{Response: resp}
423	return
424}
425
426// listByOperationNextResults retrieves the next set of results, if any.
427func (client ReportsClient) listByOperationNextResults(ctx context.Context, lastResults ReportCollection) (result ReportCollection, err error) {
428	req, err := lastResults.reportCollectionPreparer(ctx)
429	if err != nil {
430		return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByOperationNextResults", nil, "Failure preparing next results request")
431	}
432	if req == nil {
433		return
434	}
435	resp, err := client.ListByOperationSender(req)
436	if err != nil {
437		result.Response = autorest.Response{Response: resp}
438		return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByOperationNextResults", resp, "Failure sending next results request")
439	}
440	result, err = client.ListByOperationResponder(resp)
441	if err != nil {
442		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByOperationNextResults", resp, "Failure responding to next results request")
443	}
444	return
445}
446
447// ListByOperationComplete enumerates all values, automatically crossing page boundaries as required.
448func (client ReportsClient) ListByOperationComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result ReportCollectionIterator, err error) {
449	if tracing.IsEnabled() {
450		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListByOperation")
451		defer func() {
452			sc := -1
453			if result.Response().Response.Response != nil {
454				sc = result.page.Response().Response.Response.StatusCode
455			}
456			tracing.EndSpan(ctx, sc, err)
457		}()
458	}
459	result.page, err = client.ListByOperation(ctx, resourceGroupName, serviceName, filter, top, skip)
460	return
461}
462
463// ListByProduct lists report records by Product.
464// Parameters:
465// resourceGroupName - the name of the resource group.
466// serviceName - the name of the API Management service.
467// filter - the filter to apply on the operation.
468// top - number of records to return.
469// skip - number of records to skip.
470func (client ReportsClient) ListByProduct(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result ReportCollectionPage, err error) {
471	if tracing.IsEnabled() {
472		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListByProduct")
473		defer func() {
474			sc := -1
475			if result.rc.Response.Response != nil {
476				sc = result.rc.Response.Response.StatusCode
477			}
478			tracing.EndSpan(ctx, sc, err)
479		}()
480	}
481	if err := validation.Validate([]validation.Validation{
482		{TargetValue: serviceName,
483			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
484				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
485				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
486		{TargetValue: top,
487			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
488				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
489		{TargetValue: skip,
490			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
491				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
492		return result, validation.NewError("apimanagement.ReportsClient", "ListByProduct", err.Error())
493	}
494
495	result.fn = client.listByProductNextResults
496	req, err := client.ListByProductPreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
497	if err != nil {
498		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByProduct", nil, "Failure preparing request")
499		return
500	}
501
502	resp, err := client.ListByProductSender(req)
503	if err != nil {
504		result.rc.Response = autorest.Response{Response: resp}
505		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByProduct", resp, "Failure sending request")
506		return
507	}
508
509	result.rc, err = client.ListByProductResponder(resp)
510	if err != nil {
511		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByProduct", resp, "Failure responding to request")
512	}
513
514	return
515}
516
517// ListByProductPreparer prepares the ListByProduct request.
518func (client ReportsClient) ListByProductPreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
519	pathParameters := map[string]interface{}{
520		"resourceGroupName": autorest.Encode("path", resourceGroupName),
521		"serviceName":       autorest.Encode("path", serviceName),
522		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
523	}
524
525	const APIVersion = "2017-03-01"
526	queryParameters := map[string]interface{}{
527		"$filter":     autorest.Encode("query", filter),
528		"api-version": APIVersion,
529	}
530	if top != nil {
531		queryParameters["$top"] = autorest.Encode("query", *top)
532	}
533	if skip != nil {
534		queryParameters["$skip"] = autorest.Encode("query", *skip)
535	}
536
537	preparer := autorest.CreatePreparer(
538		autorest.AsGet(),
539		autorest.WithBaseURL(client.BaseURI),
540		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/reports/byProduct", pathParameters),
541		autorest.WithQueryParameters(queryParameters))
542	return preparer.Prepare((&http.Request{}).WithContext(ctx))
543}
544
545// ListByProductSender sends the ListByProduct request. The method will close the
546// http.Response Body if it receives an error.
547func (client ReportsClient) ListByProductSender(req *http.Request) (*http.Response, error) {
548	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
549	return autorest.SendWithSender(client, req, sd...)
550}
551
552// ListByProductResponder handles the response to the ListByProduct request. The method always
553// closes the http.Response Body.
554func (client ReportsClient) ListByProductResponder(resp *http.Response) (result ReportCollection, err error) {
555	err = autorest.Respond(
556		resp,
557		client.ByInspecting(),
558		azure.WithErrorUnlessStatusCode(http.StatusOK),
559		autorest.ByUnmarshallingJSON(&result),
560		autorest.ByClosing())
561	result.Response = autorest.Response{Response: resp}
562	return
563}
564
565// listByProductNextResults retrieves the next set of results, if any.
566func (client ReportsClient) listByProductNextResults(ctx context.Context, lastResults ReportCollection) (result ReportCollection, err error) {
567	req, err := lastResults.reportCollectionPreparer(ctx)
568	if err != nil {
569		return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByProductNextResults", nil, "Failure preparing next results request")
570	}
571	if req == nil {
572		return
573	}
574	resp, err := client.ListByProductSender(req)
575	if err != nil {
576		result.Response = autorest.Response{Response: resp}
577		return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByProductNextResults", resp, "Failure sending next results request")
578	}
579	result, err = client.ListByProductResponder(resp)
580	if err != nil {
581		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByProductNextResults", resp, "Failure responding to next results request")
582	}
583	return
584}
585
586// ListByProductComplete enumerates all values, automatically crossing page boundaries as required.
587func (client ReportsClient) ListByProductComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result ReportCollectionIterator, err error) {
588	if tracing.IsEnabled() {
589		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListByProduct")
590		defer func() {
591			sc := -1
592			if result.Response().Response.Response != nil {
593				sc = result.page.Response().Response.Response.StatusCode
594			}
595			tracing.EndSpan(ctx, sc, err)
596		}()
597	}
598	result.page, err = client.ListByProduct(ctx, resourceGroupName, serviceName, filter, top, skip)
599	return
600}
601
602// ListByRequest lists report records by Request.
603// Parameters:
604// resourceGroupName - the name of the resource group.
605// serviceName - the name of the API Management service.
606// filter - the filter to apply on the operation.
607// top - number of records to return.
608// skip - number of records to skip.
609func (client ReportsClient) ListByRequest(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result RequestReportCollection, err error) {
610	if tracing.IsEnabled() {
611		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListByRequest")
612		defer func() {
613			sc := -1
614			if result.Response.Response != nil {
615				sc = result.Response.Response.StatusCode
616			}
617			tracing.EndSpan(ctx, sc, err)
618		}()
619	}
620	if err := validation.Validate([]validation.Validation{
621		{TargetValue: serviceName,
622			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
623				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
624				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
625		{TargetValue: top,
626			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
627				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
628		{TargetValue: skip,
629			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
630				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
631		return result, validation.NewError("apimanagement.ReportsClient", "ListByRequest", err.Error())
632	}
633
634	req, err := client.ListByRequestPreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
635	if err != nil {
636		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByRequest", nil, "Failure preparing request")
637		return
638	}
639
640	resp, err := client.ListByRequestSender(req)
641	if err != nil {
642		result.Response = autorest.Response{Response: resp}
643		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByRequest", resp, "Failure sending request")
644		return
645	}
646
647	result, err = client.ListByRequestResponder(resp)
648	if err != nil {
649		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByRequest", resp, "Failure responding to request")
650	}
651
652	return
653}
654
655// ListByRequestPreparer prepares the ListByRequest request.
656func (client ReportsClient) ListByRequestPreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
657	pathParameters := map[string]interface{}{
658		"resourceGroupName": autorest.Encode("path", resourceGroupName),
659		"serviceName":       autorest.Encode("path", serviceName),
660		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
661	}
662
663	const APIVersion = "2017-03-01"
664	queryParameters := map[string]interface{}{
665		"$filter":     autorest.Encode("query", filter),
666		"api-version": APIVersion,
667	}
668	if top != nil {
669		queryParameters["$top"] = autorest.Encode("query", *top)
670	}
671	if skip != nil {
672		queryParameters["$skip"] = autorest.Encode("query", *skip)
673	}
674
675	preparer := autorest.CreatePreparer(
676		autorest.AsGet(),
677		autorest.WithBaseURL(client.BaseURI),
678		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/reports/byRequest", pathParameters),
679		autorest.WithQueryParameters(queryParameters))
680	return preparer.Prepare((&http.Request{}).WithContext(ctx))
681}
682
683// ListByRequestSender sends the ListByRequest request. The method will close the
684// http.Response Body if it receives an error.
685func (client ReportsClient) ListByRequestSender(req *http.Request) (*http.Response, error) {
686	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
687	return autorest.SendWithSender(client, req, sd...)
688}
689
690// ListByRequestResponder handles the response to the ListByRequest request. The method always
691// closes the http.Response Body.
692func (client ReportsClient) ListByRequestResponder(resp *http.Response) (result RequestReportCollection, err error) {
693	err = autorest.Respond(
694		resp,
695		client.ByInspecting(),
696		azure.WithErrorUnlessStatusCode(http.StatusOK),
697		autorest.ByUnmarshallingJSON(&result),
698		autorest.ByClosing())
699	result.Response = autorest.Response{Response: resp}
700	return
701}
702
703// ListBySubscription lists report records by subscription.
704// Parameters:
705// resourceGroupName - the name of the resource group.
706// serviceName - the name of the API Management service.
707// filter - the filter to apply on the operation.
708// top - number of records to return.
709// skip - number of records to skip.
710func (client ReportsClient) ListBySubscription(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result ReportCollectionPage, err error) {
711	if tracing.IsEnabled() {
712		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListBySubscription")
713		defer func() {
714			sc := -1
715			if result.rc.Response.Response != nil {
716				sc = result.rc.Response.Response.StatusCode
717			}
718			tracing.EndSpan(ctx, sc, err)
719		}()
720	}
721	if err := validation.Validate([]validation.Validation{
722		{TargetValue: serviceName,
723			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
724				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
725				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
726		{TargetValue: top,
727			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
728				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
729		{TargetValue: skip,
730			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
731				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
732		return result, validation.NewError("apimanagement.ReportsClient", "ListBySubscription", err.Error())
733	}
734
735	result.fn = client.listBySubscriptionNextResults
736	req, err := client.ListBySubscriptionPreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
737	if err != nil {
738		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListBySubscription", nil, "Failure preparing request")
739		return
740	}
741
742	resp, err := client.ListBySubscriptionSender(req)
743	if err != nil {
744		result.rc.Response = autorest.Response{Response: resp}
745		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListBySubscription", resp, "Failure sending request")
746		return
747	}
748
749	result.rc, err = client.ListBySubscriptionResponder(resp)
750	if err != nil {
751		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListBySubscription", resp, "Failure responding to request")
752	}
753
754	return
755}
756
757// ListBySubscriptionPreparer prepares the ListBySubscription request.
758func (client ReportsClient) ListBySubscriptionPreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
759	pathParameters := map[string]interface{}{
760		"resourceGroupName": autorest.Encode("path", resourceGroupName),
761		"serviceName":       autorest.Encode("path", serviceName),
762		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
763	}
764
765	const APIVersion = "2017-03-01"
766	queryParameters := map[string]interface{}{
767		"api-version": APIVersion,
768	}
769	if len(filter) > 0 {
770		queryParameters["$filter"] = autorest.Encode("query", filter)
771	}
772	if top != nil {
773		queryParameters["$top"] = autorest.Encode("query", *top)
774	}
775	if skip != nil {
776		queryParameters["$skip"] = autorest.Encode("query", *skip)
777	}
778
779	preparer := autorest.CreatePreparer(
780		autorest.AsGet(),
781		autorest.WithBaseURL(client.BaseURI),
782		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/reports/bySubscription", pathParameters),
783		autorest.WithQueryParameters(queryParameters))
784	return preparer.Prepare((&http.Request{}).WithContext(ctx))
785}
786
787// ListBySubscriptionSender sends the ListBySubscription request. The method will close the
788// http.Response Body if it receives an error.
789func (client ReportsClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
790	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
791	return autorest.SendWithSender(client, req, sd...)
792}
793
794// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
795// closes the http.Response Body.
796func (client ReportsClient) ListBySubscriptionResponder(resp *http.Response) (result ReportCollection, err error) {
797	err = autorest.Respond(
798		resp,
799		client.ByInspecting(),
800		azure.WithErrorUnlessStatusCode(http.StatusOK),
801		autorest.ByUnmarshallingJSON(&result),
802		autorest.ByClosing())
803	result.Response = autorest.Response{Response: resp}
804	return
805}
806
807// listBySubscriptionNextResults retrieves the next set of results, if any.
808func (client ReportsClient) listBySubscriptionNextResults(ctx context.Context, lastResults ReportCollection) (result ReportCollection, err error) {
809	req, err := lastResults.reportCollectionPreparer(ctx)
810	if err != nil {
811		return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listBySubscriptionNextResults", nil, "Failure preparing next results request")
812	}
813	if req == nil {
814		return
815	}
816	resp, err := client.ListBySubscriptionSender(req)
817	if err != nil {
818		result.Response = autorest.Response{Response: resp}
819		return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listBySubscriptionNextResults", resp, "Failure sending next results request")
820	}
821	result, err = client.ListBySubscriptionResponder(resp)
822	if err != nil {
823		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listBySubscriptionNextResults", resp, "Failure responding to next results request")
824	}
825	return
826}
827
828// ListBySubscriptionComplete enumerates all values, automatically crossing page boundaries as required.
829func (client ReportsClient) ListBySubscriptionComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result ReportCollectionIterator, err error) {
830	if tracing.IsEnabled() {
831		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListBySubscription")
832		defer func() {
833			sc := -1
834			if result.Response().Response.Response != nil {
835				sc = result.page.Response().Response.Response.StatusCode
836			}
837			tracing.EndSpan(ctx, sc, err)
838		}()
839	}
840	result.page, err = client.ListBySubscription(ctx, resourceGroupName, serviceName, filter, top, skip)
841	return
842}
843
844// ListByTime lists report records by Time.
845// Parameters:
846// resourceGroupName - the name of the resource group.
847// serviceName - the name of the API Management service.
848// interval - by time interval. Interval must be multiple of 15 minutes and may not be zero. The value should
849// be in ISO  8601 format (http://en.wikipedia.org/wiki/ISO_8601#Durations).This code can be used to convert
850// TimeSpan to a valid interval string: XmlConvert.ToString(new TimeSpan(hours, minutes, seconds))
851// filter - the filter to apply on the operation.
852// top - number of records to return.
853// skip - number of records to skip.
854func (client ReportsClient) ListByTime(ctx context.Context, resourceGroupName string, serviceName string, interval string, filter string, top *int32, skip *int32) (result ReportCollectionPage, err error) {
855	if tracing.IsEnabled() {
856		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListByTime")
857		defer func() {
858			sc := -1
859			if result.rc.Response.Response != nil {
860				sc = result.rc.Response.Response.StatusCode
861			}
862			tracing.EndSpan(ctx, sc, err)
863		}()
864	}
865	if err := validation.Validate([]validation.Validation{
866		{TargetValue: serviceName,
867			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
868				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
869				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
870		{TargetValue: top,
871			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
872				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
873		{TargetValue: skip,
874			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
875				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
876		return result, validation.NewError("apimanagement.ReportsClient", "ListByTime", err.Error())
877	}
878
879	result.fn = client.listByTimeNextResults
880	req, err := client.ListByTimePreparer(ctx, resourceGroupName, serviceName, interval, filter, top, skip)
881	if err != nil {
882		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByTime", nil, "Failure preparing request")
883		return
884	}
885
886	resp, err := client.ListByTimeSender(req)
887	if err != nil {
888		result.rc.Response = autorest.Response{Response: resp}
889		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByTime", resp, "Failure sending request")
890		return
891	}
892
893	result.rc, err = client.ListByTimeResponder(resp)
894	if err != nil {
895		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByTime", resp, "Failure responding to request")
896	}
897
898	return
899}
900
901// ListByTimePreparer prepares the ListByTime request.
902func (client ReportsClient) ListByTimePreparer(ctx context.Context, resourceGroupName string, serviceName string, interval string, filter string, top *int32, skip *int32) (*http.Request, error) {
903	pathParameters := map[string]interface{}{
904		"resourceGroupName": autorest.Encode("path", resourceGroupName),
905		"serviceName":       autorest.Encode("path", serviceName),
906		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
907	}
908
909	const APIVersion = "2017-03-01"
910	queryParameters := map[string]interface{}{
911		"api-version": APIVersion,
912		"interval":    autorest.Encode("query", interval),
913	}
914	if len(filter) > 0 {
915		queryParameters["$filter"] = autorest.Encode("query", filter)
916	}
917	if top != nil {
918		queryParameters["$top"] = autorest.Encode("query", *top)
919	}
920	if skip != nil {
921		queryParameters["$skip"] = autorest.Encode("query", *skip)
922	}
923
924	preparer := autorest.CreatePreparer(
925		autorest.AsGet(),
926		autorest.WithBaseURL(client.BaseURI),
927		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/reports/byTime", pathParameters),
928		autorest.WithQueryParameters(queryParameters))
929	return preparer.Prepare((&http.Request{}).WithContext(ctx))
930}
931
932// ListByTimeSender sends the ListByTime request. The method will close the
933// http.Response Body if it receives an error.
934func (client ReportsClient) ListByTimeSender(req *http.Request) (*http.Response, error) {
935	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
936	return autorest.SendWithSender(client, req, sd...)
937}
938
939// ListByTimeResponder handles the response to the ListByTime request. The method always
940// closes the http.Response Body.
941func (client ReportsClient) ListByTimeResponder(resp *http.Response) (result ReportCollection, err error) {
942	err = autorest.Respond(
943		resp,
944		client.ByInspecting(),
945		azure.WithErrorUnlessStatusCode(http.StatusOK),
946		autorest.ByUnmarshallingJSON(&result),
947		autorest.ByClosing())
948	result.Response = autorest.Response{Response: resp}
949	return
950}
951
952// listByTimeNextResults retrieves the next set of results, if any.
953func (client ReportsClient) listByTimeNextResults(ctx context.Context, lastResults ReportCollection) (result ReportCollection, err error) {
954	req, err := lastResults.reportCollectionPreparer(ctx)
955	if err != nil {
956		return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByTimeNextResults", nil, "Failure preparing next results request")
957	}
958	if req == nil {
959		return
960	}
961	resp, err := client.ListByTimeSender(req)
962	if err != nil {
963		result.Response = autorest.Response{Response: resp}
964		return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByTimeNextResults", resp, "Failure sending next results request")
965	}
966	result, err = client.ListByTimeResponder(resp)
967	if err != nil {
968		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByTimeNextResults", resp, "Failure responding to next results request")
969	}
970	return
971}
972
973// ListByTimeComplete enumerates all values, automatically crossing page boundaries as required.
974func (client ReportsClient) ListByTimeComplete(ctx context.Context, resourceGroupName string, serviceName string, interval string, filter string, top *int32, skip *int32) (result ReportCollectionIterator, err error) {
975	if tracing.IsEnabled() {
976		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListByTime")
977		defer func() {
978			sc := -1
979			if result.Response().Response.Response != nil {
980				sc = result.page.Response().Response.Response.StatusCode
981			}
982			tracing.EndSpan(ctx, sc, err)
983		}()
984	}
985	result.page, err = client.ListByTime(ctx, resourceGroupName, serviceName, interval, filter, top, skip)
986	return
987}
988
989// ListByUser lists report records by User.
990// Parameters:
991// resourceGroupName - the name of the resource group.
992// serviceName - the name of the API Management service.
993// filter - the filter to apply on the operation.
994// top - number of records to return.
995// skip - number of records to skip.
996func (client ReportsClient) ListByUser(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result ReportCollectionPage, err error) {
997	if tracing.IsEnabled() {
998		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListByUser")
999		defer func() {
1000			sc := -1
1001			if result.rc.Response.Response != nil {
1002				sc = result.rc.Response.Response.StatusCode
1003			}
1004			tracing.EndSpan(ctx, sc, err)
1005		}()
1006	}
1007	if err := validation.Validate([]validation.Validation{
1008		{TargetValue: serviceName,
1009			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
1010				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
1011				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
1012		{TargetValue: top,
1013			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
1014				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
1015		{TargetValue: skip,
1016			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
1017				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
1018		return result, validation.NewError("apimanagement.ReportsClient", "ListByUser", err.Error())
1019	}
1020
1021	result.fn = client.listByUserNextResults
1022	req, err := client.ListByUserPreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
1023	if err != nil {
1024		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByUser", nil, "Failure preparing request")
1025		return
1026	}
1027
1028	resp, err := client.ListByUserSender(req)
1029	if err != nil {
1030		result.rc.Response = autorest.Response{Response: resp}
1031		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByUser", resp, "Failure sending request")
1032		return
1033	}
1034
1035	result.rc, err = client.ListByUserResponder(resp)
1036	if err != nil {
1037		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByUser", resp, "Failure responding to request")
1038	}
1039
1040	return
1041}
1042
1043// ListByUserPreparer prepares the ListByUser request.
1044func (client ReportsClient) ListByUserPreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
1045	pathParameters := map[string]interface{}{
1046		"resourceGroupName": autorest.Encode("path", resourceGroupName),
1047		"serviceName":       autorest.Encode("path", serviceName),
1048		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
1049	}
1050
1051	const APIVersion = "2017-03-01"
1052	queryParameters := map[string]interface{}{
1053		"$filter":     autorest.Encode("query", filter),
1054		"api-version": APIVersion,
1055	}
1056	if top != nil {
1057		queryParameters["$top"] = autorest.Encode("query", *top)
1058	}
1059	if skip != nil {
1060		queryParameters["$skip"] = autorest.Encode("query", *skip)
1061	}
1062
1063	preparer := autorest.CreatePreparer(
1064		autorest.AsGet(),
1065		autorest.WithBaseURL(client.BaseURI),
1066		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/reports/byUser", pathParameters),
1067		autorest.WithQueryParameters(queryParameters))
1068	return preparer.Prepare((&http.Request{}).WithContext(ctx))
1069}
1070
1071// ListByUserSender sends the ListByUser request. The method will close the
1072// http.Response Body if it receives an error.
1073func (client ReportsClient) ListByUserSender(req *http.Request) (*http.Response, error) {
1074	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
1075	return autorest.SendWithSender(client, req, sd...)
1076}
1077
1078// ListByUserResponder handles the response to the ListByUser request. The method always
1079// closes the http.Response Body.
1080func (client ReportsClient) ListByUserResponder(resp *http.Response) (result ReportCollection, err error) {
1081	err = autorest.Respond(
1082		resp,
1083		client.ByInspecting(),
1084		azure.WithErrorUnlessStatusCode(http.StatusOK),
1085		autorest.ByUnmarshallingJSON(&result),
1086		autorest.ByClosing())
1087	result.Response = autorest.Response{Response: resp}
1088	return
1089}
1090
1091// listByUserNextResults retrieves the next set of results, if any.
1092func (client ReportsClient) listByUserNextResults(ctx context.Context, lastResults ReportCollection) (result ReportCollection, err error) {
1093	req, err := lastResults.reportCollectionPreparer(ctx)
1094	if err != nil {
1095		return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByUserNextResults", nil, "Failure preparing next results request")
1096	}
1097	if req == nil {
1098		return
1099	}
1100	resp, err := client.ListByUserSender(req)
1101	if err != nil {
1102		result.Response = autorest.Response{Response: resp}
1103		return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByUserNextResults", resp, "Failure sending next results request")
1104	}
1105	result, err = client.ListByUserResponder(resp)
1106	if err != nil {
1107		err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByUserNextResults", resp, "Failure responding to next results request")
1108	}
1109	return
1110}
1111
1112// ListByUserComplete enumerates all values, automatically crossing page boundaries as required.
1113func (client ReportsClient) ListByUserComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result ReportCollectionIterator, err error) {
1114	if tracing.IsEnabled() {
1115		ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListByUser")
1116		defer func() {
1117			sc := -1
1118			if result.Response().Response.Response != nil {
1119				sc = result.page.Response().Response.Response.StatusCode
1120			}
1121			tracing.EndSpan(ctx, sc, err)
1122		}()
1123	}
1124	result.page, err = client.ListByUser(ctx, resourceGroupName, serviceName, filter, top, skip)
1125	return
1126}
1127