1package billing
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/tracing"
25	"net/http"
26)
27
28// InvoiceSectionsClient is the billing client provides access to billing resources for Azure subscriptions.
29type InvoiceSectionsClient struct {
30	BaseClient
31}
32
33// NewInvoiceSectionsClient creates an instance of the InvoiceSectionsClient client.
34func NewInvoiceSectionsClient(subscriptionID string) InvoiceSectionsClient {
35	return NewInvoiceSectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewInvoiceSectionsClientWithBaseURI creates an instance of the InvoiceSectionsClient client using a custom endpoint.
39// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
40func NewInvoiceSectionsClientWithBaseURI(baseURI string, subscriptionID string) InvoiceSectionsClient {
41	return InvoiceSectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// Create the operation to create a InvoiceSection.
45// Parameters:
46// billingAccountName - billing Account Id.
47// parameters - parameters supplied to the Create InvoiceSection operation.
48func (client InvoiceSectionsClient) Create(ctx context.Context, billingAccountName string, parameters InvoiceSectionCreationRequest) (result InvoiceSectionsCreateFuture, err error) {
49	if tracing.IsEnabled() {
50		ctx = tracing.StartSpan(ctx, fqdn+"/InvoiceSectionsClient.Create")
51		defer func() {
52			sc := -1
53			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
54				sc = result.FutureAPI.Response().StatusCode
55			}
56			tracing.EndSpan(ctx, sc, err)
57		}()
58	}
59	req, err := client.CreatePreparer(ctx, billingAccountName, parameters)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "Create", nil, "Failure preparing request")
62		return
63	}
64
65	result, err = client.CreateSender(req)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "Create", nil, "Failure sending request")
68		return
69	}
70
71	return
72}
73
74// CreatePreparer prepares the Create request.
75func (client InvoiceSectionsClient) CreatePreparer(ctx context.Context, billingAccountName string, parameters InvoiceSectionCreationRequest) (*http.Request, error) {
76	pathParameters := map[string]interface{}{
77		"billingAccountName": autorest.Encode("path", billingAccountName),
78	}
79
80	const APIVersion = "2018-11-01-preview"
81	queryParameters := map[string]interface{}{
82		"api-version": APIVersion,
83	}
84
85	preparer := autorest.CreatePreparer(
86		autorest.AsContentType("application/json; charset=utf-8"),
87		autorest.AsPost(),
88		autorest.WithBaseURL(client.BaseURI),
89		autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/invoiceSections", pathParameters),
90		autorest.WithJSON(parameters),
91		autorest.WithQueryParameters(queryParameters))
92	return preparer.Prepare((&http.Request{}).WithContext(ctx))
93}
94
95// CreateSender sends the Create request. The method will close the
96// http.Response Body if it receives an error.
97func (client InvoiceSectionsClient) CreateSender(req *http.Request) (future InvoiceSectionsCreateFuture, err error) {
98	var resp *http.Response
99	resp, err = client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
100	if err != nil {
101		return
102	}
103	var azf azure.Future
104	azf, err = azure.NewFutureFromResponse(resp)
105	future.FutureAPI = &azf
106	future.Result = func(client InvoiceSectionsClient) (is InvoiceSection, err error) {
107		var done bool
108		done, err = future.DoneWithContext(context.Background(), client)
109		if err != nil {
110			err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsCreateFuture", "Result", future.Response(), "Polling failure")
111			return
112		}
113		if !done {
114			err = azure.NewAsyncOpIncompleteError("billing.InvoiceSectionsCreateFuture")
115			return
116		}
117		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
118		is.Response.Response, err = future.GetResult(sender)
119		if is.Response.Response == nil && err == nil {
120			err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsCreateFuture", "Result", nil, "received nil response and error")
121		}
122		if err == nil && is.Response.Response.StatusCode != http.StatusNoContent {
123			is, err = client.CreateResponder(is.Response.Response)
124			if err != nil {
125				err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsCreateFuture", "Result", is.Response.Response, "Failure responding to request")
126			}
127		}
128		return
129	}
130	return
131}
132
133// CreateResponder handles the response to the Create request. The method always
134// closes the http.Response Body.
135func (client InvoiceSectionsClient) CreateResponder(resp *http.Response) (result InvoiceSection, err error) {
136	err = autorest.Respond(
137		resp,
138		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
139		autorest.ByUnmarshallingJSON(&result),
140		autorest.ByClosing())
141	result.Response = autorest.Response{Response: resp}
142	return
143}
144
145// ElevateToBillingProfile elevates the caller's access to match their billing profile access.
146// Parameters:
147// billingAccountName - billing Account Id.
148// invoiceSectionName - invoiceSection Id.
149func (client InvoiceSectionsClient) ElevateToBillingProfile(ctx context.Context, billingAccountName string, invoiceSectionName string) (result autorest.Response, err error) {
150	if tracing.IsEnabled() {
151		ctx = tracing.StartSpan(ctx, fqdn+"/InvoiceSectionsClient.ElevateToBillingProfile")
152		defer func() {
153			sc := -1
154			if result.Response != nil {
155				sc = result.Response.StatusCode
156			}
157			tracing.EndSpan(ctx, sc, err)
158		}()
159	}
160	req, err := client.ElevateToBillingProfilePreparer(ctx, billingAccountName, invoiceSectionName)
161	if err != nil {
162		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "ElevateToBillingProfile", nil, "Failure preparing request")
163		return
164	}
165
166	resp, err := client.ElevateToBillingProfileSender(req)
167	if err != nil {
168		result.Response = resp
169		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "ElevateToBillingProfile", resp, "Failure sending request")
170		return
171	}
172
173	result, err = client.ElevateToBillingProfileResponder(resp)
174	if err != nil {
175		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "ElevateToBillingProfile", resp, "Failure responding to request")
176		return
177	}
178
179	return
180}
181
182// ElevateToBillingProfilePreparer prepares the ElevateToBillingProfile request.
183func (client InvoiceSectionsClient) ElevateToBillingProfilePreparer(ctx context.Context, billingAccountName string, invoiceSectionName string) (*http.Request, error) {
184	pathParameters := map[string]interface{}{
185		"billingAccountName": autorest.Encode("path", billingAccountName),
186		"invoiceSectionName": autorest.Encode("path", invoiceSectionName),
187	}
188
189	preparer := autorest.CreatePreparer(
190		autorest.AsPost(),
191		autorest.WithBaseURL(client.BaseURI),
192		autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/invoiceSections/{invoiceSectionName}/elevate", pathParameters))
193	return preparer.Prepare((&http.Request{}).WithContext(ctx))
194}
195
196// ElevateToBillingProfileSender sends the ElevateToBillingProfile request. The method will close the
197// http.Response Body if it receives an error.
198func (client InvoiceSectionsClient) ElevateToBillingProfileSender(req *http.Request) (*http.Response, error) {
199	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
200}
201
202// ElevateToBillingProfileResponder handles the response to the ElevateToBillingProfile request. The method always
203// closes the http.Response Body.
204func (client InvoiceSectionsClient) ElevateToBillingProfileResponder(resp *http.Response) (result autorest.Response, err error) {
205	err = autorest.Respond(
206		resp,
207		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
208		autorest.ByClosing())
209	result.Response = resp
210	return
211}
212
213// Get get the InvoiceSection by id.
214// Parameters:
215// billingAccountName - billing Account Id.
216// invoiceSectionName - invoiceSection Id.
217// expand - may be used to expand the billingProfiles.
218func (client InvoiceSectionsClient) Get(ctx context.Context, billingAccountName string, invoiceSectionName string, expand string) (result InvoiceSection, err error) {
219	if tracing.IsEnabled() {
220		ctx = tracing.StartSpan(ctx, fqdn+"/InvoiceSectionsClient.Get")
221		defer func() {
222			sc := -1
223			if result.Response.Response != nil {
224				sc = result.Response.Response.StatusCode
225			}
226			tracing.EndSpan(ctx, sc, err)
227		}()
228	}
229	req, err := client.GetPreparer(ctx, billingAccountName, invoiceSectionName, expand)
230	if err != nil {
231		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "Get", nil, "Failure preparing request")
232		return
233	}
234
235	resp, err := client.GetSender(req)
236	if err != nil {
237		result.Response = autorest.Response{Response: resp}
238		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "Get", resp, "Failure sending request")
239		return
240	}
241
242	result, err = client.GetResponder(resp)
243	if err != nil {
244		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "Get", resp, "Failure responding to request")
245		return
246	}
247
248	return
249}
250
251// GetPreparer prepares the Get request.
252func (client InvoiceSectionsClient) GetPreparer(ctx context.Context, billingAccountName string, invoiceSectionName string, expand string) (*http.Request, error) {
253	pathParameters := map[string]interface{}{
254		"billingAccountName": autorest.Encode("path", billingAccountName),
255		"invoiceSectionName": autorest.Encode("path", invoiceSectionName),
256	}
257
258	const APIVersion = "2018-11-01-preview"
259	queryParameters := map[string]interface{}{
260		"api-version": APIVersion,
261	}
262	if len(expand) > 0 {
263		queryParameters["$expand"] = autorest.Encode("query", expand)
264	}
265
266	preparer := autorest.CreatePreparer(
267		autorest.AsGet(),
268		autorest.WithBaseURL(client.BaseURI),
269		autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/invoiceSections/{invoiceSectionName}", pathParameters),
270		autorest.WithQueryParameters(queryParameters))
271	return preparer.Prepare((&http.Request{}).WithContext(ctx))
272}
273
274// GetSender sends the Get request. The method will close the
275// http.Response Body if it receives an error.
276func (client InvoiceSectionsClient) GetSender(req *http.Request) (*http.Response, error) {
277	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
278}
279
280// GetResponder handles the response to the Get request. The method always
281// closes the http.Response Body.
282func (client InvoiceSectionsClient) GetResponder(resp *http.Response) (result InvoiceSection, err error) {
283	err = autorest.Respond(
284		resp,
285		azure.WithErrorUnlessStatusCode(http.StatusOK),
286		autorest.ByUnmarshallingJSON(&result),
287		autorest.ByClosing())
288	result.Response = autorest.Response{Response: resp}
289	return
290}
291
292// ListByBillingAccountName lists all invoice sections for which a user has access.
293// Parameters:
294// billingAccountName - billing Account Id.
295// expand - may be used to expand the billingProfiles.
296func (client InvoiceSectionsClient) ListByBillingAccountName(ctx context.Context, billingAccountName string, expand string) (result InvoiceSectionListResult, err error) {
297	if tracing.IsEnabled() {
298		ctx = tracing.StartSpan(ctx, fqdn+"/InvoiceSectionsClient.ListByBillingAccountName")
299		defer func() {
300			sc := -1
301			if result.Response.Response != nil {
302				sc = result.Response.Response.StatusCode
303			}
304			tracing.EndSpan(ctx, sc, err)
305		}()
306	}
307	req, err := client.ListByBillingAccountNamePreparer(ctx, billingAccountName, expand)
308	if err != nil {
309		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "ListByBillingAccountName", nil, "Failure preparing request")
310		return
311	}
312
313	resp, err := client.ListByBillingAccountNameSender(req)
314	if err != nil {
315		result.Response = autorest.Response{Response: resp}
316		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "ListByBillingAccountName", resp, "Failure sending request")
317		return
318	}
319
320	result, err = client.ListByBillingAccountNameResponder(resp)
321	if err != nil {
322		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "ListByBillingAccountName", resp, "Failure responding to request")
323		return
324	}
325
326	return
327}
328
329// ListByBillingAccountNamePreparer prepares the ListByBillingAccountName request.
330func (client InvoiceSectionsClient) ListByBillingAccountNamePreparer(ctx context.Context, billingAccountName string, expand string) (*http.Request, error) {
331	pathParameters := map[string]interface{}{
332		"billingAccountName": autorest.Encode("path", billingAccountName),
333	}
334
335	const APIVersion = "2018-11-01-preview"
336	queryParameters := map[string]interface{}{
337		"api-version": APIVersion,
338	}
339	if len(expand) > 0 {
340		queryParameters["$expand"] = autorest.Encode("query", expand)
341	}
342
343	preparer := autorest.CreatePreparer(
344		autorest.AsGet(),
345		autorest.WithBaseURL(client.BaseURI),
346		autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/invoiceSections", pathParameters),
347		autorest.WithQueryParameters(queryParameters))
348	return preparer.Prepare((&http.Request{}).WithContext(ctx))
349}
350
351// ListByBillingAccountNameSender sends the ListByBillingAccountName request. The method will close the
352// http.Response Body if it receives an error.
353func (client InvoiceSectionsClient) ListByBillingAccountNameSender(req *http.Request) (*http.Response, error) {
354	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
355}
356
357// ListByBillingAccountNameResponder handles the response to the ListByBillingAccountName request. The method always
358// closes the http.Response Body.
359func (client InvoiceSectionsClient) ListByBillingAccountNameResponder(resp *http.Response) (result InvoiceSectionListResult, err error) {
360	err = autorest.Respond(
361		resp,
362		azure.WithErrorUnlessStatusCode(http.StatusOK),
363		autorest.ByUnmarshallingJSON(&result),
364		autorest.ByClosing())
365	result.Response = autorest.Response{Response: resp}
366	return
367}
368
369// ListByBillingProfileName lists all invoice sections under a billing profile for which a user has access.
370// Parameters:
371// billingAccountName - billing Account Id.
372// billingProfileName - billing Profile Id.
373func (client InvoiceSectionsClient) ListByBillingProfileName(ctx context.Context, billingAccountName string, billingProfileName string) (result InvoiceSectionListResultPage, err error) {
374	if tracing.IsEnabled() {
375		ctx = tracing.StartSpan(ctx, fqdn+"/InvoiceSectionsClient.ListByBillingProfileName")
376		defer func() {
377			sc := -1
378			if result.islr.Response.Response != nil {
379				sc = result.islr.Response.Response.StatusCode
380			}
381			tracing.EndSpan(ctx, sc, err)
382		}()
383	}
384	result.fn = client.listByBillingProfileNameNextResults
385	req, err := client.ListByBillingProfileNamePreparer(ctx, billingAccountName, billingProfileName)
386	if err != nil {
387		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "ListByBillingProfileName", nil, "Failure preparing request")
388		return
389	}
390
391	resp, err := client.ListByBillingProfileNameSender(req)
392	if err != nil {
393		result.islr.Response = autorest.Response{Response: resp}
394		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "ListByBillingProfileName", resp, "Failure sending request")
395		return
396	}
397
398	result.islr, err = client.ListByBillingProfileNameResponder(resp)
399	if err != nil {
400		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "ListByBillingProfileName", resp, "Failure responding to request")
401		return
402	}
403	if result.islr.hasNextLink() && result.islr.IsEmpty() {
404		err = result.NextWithContext(ctx)
405		return
406	}
407
408	return
409}
410
411// ListByBillingProfileNamePreparer prepares the ListByBillingProfileName request.
412func (client InvoiceSectionsClient) ListByBillingProfileNamePreparer(ctx context.Context, billingAccountName string, billingProfileName string) (*http.Request, error) {
413	pathParameters := map[string]interface{}{
414		"billingAccountName": autorest.Encode("path", billingAccountName),
415		"billingProfileName": autorest.Encode("path", billingProfileName),
416	}
417
418	const APIVersion = "2018-11-01-preview"
419	queryParameters := map[string]interface{}{
420		"api-version": APIVersion,
421	}
422
423	preparer := autorest.CreatePreparer(
424		autorest.AsGet(),
425		autorest.WithBaseURL(client.BaseURI),
426		autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/invoiceSections", pathParameters),
427		autorest.WithQueryParameters(queryParameters))
428	return preparer.Prepare((&http.Request{}).WithContext(ctx))
429}
430
431// ListByBillingProfileNameSender sends the ListByBillingProfileName request. The method will close the
432// http.Response Body if it receives an error.
433func (client InvoiceSectionsClient) ListByBillingProfileNameSender(req *http.Request) (*http.Response, error) {
434	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
435}
436
437// ListByBillingProfileNameResponder handles the response to the ListByBillingProfileName request. The method always
438// closes the http.Response Body.
439func (client InvoiceSectionsClient) ListByBillingProfileNameResponder(resp *http.Response) (result InvoiceSectionListResult, err error) {
440	err = autorest.Respond(
441		resp,
442		azure.WithErrorUnlessStatusCode(http.StatusOK),
443		autorest.ByUnmarshallingJSON(&result),
444		autorest.ByClosing())
445	result.Response = autorest.Response{Response: resp}
446	return
447}
448
449// listByBillingProfileNameNextResults retrieves the next set of results, if any.
450func (client InvoiceSectionsClient) listByBillingProfileNameNextResults(ctx context.Context, lastResults InvoiceSectionListResult) (result InvoiceSectionListResult, err error) {
451	req, err := lastResults.invoiceSectionListResultPreparer(ctx)
452	if err != nil {
453		return result, autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "listByBillingProfileNameNextResults", nil, "Failure preparing next results request")
454	}
455	if req == nil {
456		return
457	}
458	resp, err := client.ListByBillingProfileNameSender(req)
459	if err != nil {
460		result.Response = autorest.Response{Response: resp}
461		return result, autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "listByBillingProfileNameNextResults", resp, "Failure sending next results request")
462	}
463	result, err = client.ListByBillingProfileNameResponder(resp)
464	if err != nil {
465		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "listByBillingProfileNameNextResults", resp, "Failure responding to next results request")
466	}
467	return
468}
469
470// ListByBillingProfileNameComplete enumerates all values, automatically crossing page boundaries as required.
471func (client InvoiceSectionsClient) ListByBillingProfileNameComplete(ctx context.Context, billingAccountName string, billingProfileName string) (result InvoiceSectionListResultIterator, err error) {
472	if tracing.IsEnabled() {
473		ctx = tracing.StartSpan(ctx, fqdn+"/InvoiceSectionsClient.ListByBillingProfileName")
474		defer func() {
475			sc := -1
476			if result.Response().Response.Response != nil {
477				sc = result.page.Response().Response.Response.StatusCode
478			}
479			tracing.EndSpan(ctx, sc, err)
480		}()
481	}
482	result.page, err = client.ListByBillingProfileName(ctx, billingAccountName, billingProfileName)
483	return
484}
485
486// ListByCreateSubscriptionPermission lists all invoiceSections with create subscription permission for a user.
487// Parameters:
488// billingAccountName - billing Account Id.
489// expand - may be used to expand the billingProfiles.
490func (client InvoiceSectionsClient) ListByCreateSubscriptionPermission(ctx context.Context, billingAccountName string, expand string) (result InvoiceSectionListResultPage, err error) {
491	if tracing.IsEnabled() {
492		ctx = tracing.StartSpan(ctx, fqdn+"/InvoiceSectionsClient.ListByCreateSubscriptionPermission")
493		defer func() {
494			sc := -1
495			if result.islr.Response.Response != nil {
496				sc = result.islr.Response.Response.StatusCode
497			}
498			tracing.EndSpan(ctx, sc, err)
499		}()
500	}
501	result.fn = client.listByCreateSubscriptionPermissionNextResults
502	req, err := client.ListByCreateSubscriptionPermissionPreparer(ctx, billingAccountName, expand)
503	if err != nil {
504		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "ListByCreateSubscriptionPermission", nil, "Failure preparing request")
505		return
506	}
507
508	resp, err := client.ListByCreateSubscriptionPermissionSender(req)
509	if err != nil {
510		result.islr.Response = autorest.Response{Response: resp}
511		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "ListByCreateSubscriptionPermission", resp, "Failure sending request")
512		return
513	}
514
515	result.islr, err = client.ListByCreateSubscriptionPermissionResponder(resp)
516	if err != nil {
517		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "ListByCreateSubscriptionPermission", resp, "Failure responding to request")
518		return
519	}
520	if result.islr.hasNextLink() && result.islr.IsEmpty() {
521		err = result.NextWithContext(ctx)
522		return
523	}
524
525	return
526}
527
528// ListByCreateSubscriptionPermissionPreparer prepares the ListByCreateSubscriptionPermission request.
529func (client InvoiceSectionsClient) ListByCreateSubscriptionPermissionPreparer(ctx context.Context, billingAccountName string, expand string) (*http.Request, error) {
530	pathParameters := map[string]interface{}{
531		"billingAccountName": autorest.Encode("path", billingAccountName),
532	}
533
534	const APIVersion = "2018-11-01-preview"
535	queryParameters := map[string]interface{}{
536		"api-version": APIVersion,
537	}
538	if len(expand) > 0 {
539		queryParameters["$expand"] = autorest.Encode("query", expand)
540	}
541
542	preparer := autorest.CreatePreparer(
543		autorest.AsGet(),
544		autorest.WithBaseURL(client.BaseURI),
545		autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/listInvoiceSectionsWithCreateSubscriptionPermission", pathParameters),
546		autorest.WithQueryParameters(queryParameters))
547	return preparer.Prepare((&http.Request{}).WithContext(ctx))
548}
549
550// ListByCreateSubscriptionPermissionSender sends the ListByCreateSubscriptionPermission request. The method will close the
551// http.Response Body if it receives an error.
552func (client InvoiceSectionsClient) ListByCreateSubscriptionPermissionSender(req *http.Request) (*http.Response, error) {
553	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
554}
555
556// ListByCreateSubscriptionPermissionResponder handles the response to the ListByCreateSubscriptionPermission request. The method always
557// closes the http.Response Body.
558func (client InvoiceSectionsClient) ListByCreateSubscriptionPermissionResponder(resp *http.Response) (result InvoiceSectionListResult, err error) {
559	err = autorest.Respond(
560		resp,
561		azure.WithErrorUnlessStatusCode(http.StatusOK),
562		autorest.ByUnmarshallingJSON(&result),
563		autorest.ByClosing())
564	result.Response = autorest.Response{Response: resp}
565	return
566}
567
568// listByCreateSubscriptionPermissionNextResults retrieves the next set of results, if any.
569func (client InvoiceSectionsClient) listByCreateSubscriptionPermissionNextResults(ctx context.Context, lastResults InvoiceSectionListResult) (result InvoiceSectionListResult, err error) {
570	req, err := lastResults.invoiceSectionListResultPreparer(ctx)
571	if err != nil {
572		return result, autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "listByCreateSubscriptionPermissionNextResults", nil, "Failure preparing next results request")
573	}
574	if req == nil {
575		return
576	}
577	resp, err := client.ListByCreateSubscriptionPermissionSender(req)
578	if err != nil {
579		result.Response = autorest.Response{Response: resp}
580		return result, autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "listByCreateSubscriptionPermissionNextResults", resp, "Failure sending next results request")
581	}
582	result, err = client.ListByCreateSubscriptionPermissionResponder(resp)
583	if err != nil {
584		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "listByCreateSubscriptionPermissionNextResults", resp, "Failure responding to next results request")
585	}
586	return
587}
588
589// ListByCreateSubscriptionPermissionComplete enumerates all values, automatically crossing page boundaries as required.
590func (client InvoiceSectionsClient) ListByCreateSubscriptionPermissionComplete(ctx context.Context, billingAccountName string, expand string) (result InvoiceSectionListResultIterator, err error) {
591	if tracing.IsEnabled() {
592		ctx = tracing.StartSpan(ctx, fqdn+"/InvoiceSectionsClient.ListByCreateSubscriptionPermission")
593		defer func() {
594			sc := -1
595			if result.Response().Response.Response != nil {
596				sc = result.page.Response().Response.Response.StatusCode
597			}
598			tracing.EndSpan(ctx, sc, err)
599		}()
600	}
601	result.page, err = client.ListByCreateSubscriptionPermission(ctx, billingAccountName, expand)
602	return
603}
604
605// Update the operation to update a InvoiceSection.
606// Parameters:
607// billingAccountName - billing Account Id.
608// invoiceSectionName - invoiceSection Id.
609// parameters - parameters supplied to the Create InvoiceSection operation.
610func (client InvoiceSectionsClient) Update(ctx context.Context, billingAccountName string, invoiceSectionName string, parameters InvoiceSection) (result InvoiceSectionsUpdateFuture, err error) {
611	if tracing.IsEnabled() {
612		ctx = tracing.StartSpan(ctx, fqdn+"/InvoiceSectionsClient.Update")
613		defer func() {
614			sc := -1
615			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
616				sc = result.FutureAPI.Response().StatusCode
617			}
618			tracing.EndSpan(ctx, sc, err)
619		}()
620	}
621	req, err := client.UpdatePreparer(ctx, billingAccountName, invoiceSectionName, parameters)
622	if err != nil {
623		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "Update", nil, "Failure preparing request")
624		return
625	}
626
627	result, err = client.UpdateSender(req)
628	if err != nil {
629		err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsClient", "Update", nil, "Failure sending request")
630		return
631	}
632
633	return
634}
635
636// UpdatePreparer prepares the Update request.
637func (client InvoiceSectionsClient) UpdatePreparer(ctx context.Context, billingAccountName string, invoiceSectionName string, parameters InvoiceSection) (*http.Request, error) {
638	pathParameters := map[string]interface{}{
639		"billingAccountName": autorest.Encode("path", billingAccountName),
640		"invoiceSectionName": autorest.Encode("path", invoiceSectionName),
641	}
642
643	const APIVersion = "2018-11-01-preview"
644	queryParameters := map[string]interface{}{
645		"api-version": APIVersion,
646	}
647
648	preparer := autorest.CreatePreparer(
649		autorest.AsContentType("application/json; charset=utf-8"),
650		autorest.AsPut(),
651		autorest.WithBaseURL(client.BaseURI),
652		autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/invoiceSections/{invoiceSectionName}", pathParameters),
653		autorest.WithJSON(parameters),
654		autorest.WithQueryParameters(queryParameters))
655	return preparer.Prepare((&http.Request{}).WithContext(ctx))
656}
657
658// UpdateSender sends the Update request. The method will close the
659// http.Response Body if it receives an error.
660func (client InvoiceSectionsClient) UpdateSender(req *http.Request) (future InvoiceSectionsUpdateFuture, err error) {
661	var resp *http.Response
662	resp, err = client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
663	if err != nil {
664		return
665	}
666	var azf azure.Future
667	azf, err = azure.NewFutureFromResponse(resp)
668	future.FutureAPI = &azf
669	future.Result = func(client InvoiceSectionsClient) (is InvoiceSection, err error) {
670		var done bool
671		done, err = future.DoneWithContext(context.Background(), client)
672		if err != nil {
673			err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsUpdateFuture", "Result", future.Response(), "Polling failure")
674			return
675		}
676		if !done {
677			err = azure.NewAsyncOpIncompleteError("billing.InvoiceSectionsUpdateFuture")
678			return
679		}
680		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
681		is.Response.Response, err = future.GetResult(sender)
682		if is.Response.Response == nil && err == nil {
683			err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsUpdateFuture", "Result", nil, "received nil response and error")
684		}
685		if err == nil && is.Response.Response.StatusCode != http.StatusNoContent {
686			is, err = client.UpdateResponder(is.Response.Response)
687			if err != nil {
688				err = autorest.NewErrorWithError(err, "billing.InvoiceSectionsUpdateFuture", "Result", is.Response.Response, "Failure responding to request")
689			}
690		}
691		return
692	}
693	return
694}
695
696// UpdateResponder handles the response to the Update request. The method always
697// closes the http.Response Body.
698func (client InvoiceSectionsClient) UpdateResponder(resp *http.Response) (result InvoiceSection, err error) {
699	err = autorest.Respond(
700		resp,
701		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
702		autorest.ByUnmarshallingJSON(&result),
703		autorest.ByClosing())
704	result.Response = autorest.Response{Response: resp}
705	return
706}
707