// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT.

package armbilling

import (
	"context"
	"errors"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
	"net/http"
	"net/url"
	"strconv"
	"strings"
)

// RequestsClient contains the methods for the Requests group.
// Don't use this type directly, use NewRequestsClient() instead.
//
// Generated from API version 2024-04-01
type RequestsClient struct {
	internal *arm.Client
}

// NewRequestsClient creates a new instance of RequestsClient with the specified values.
//   - credential - used to authorize requests. Usually a credential from azidentity.
//   - options - Contains optional client configuration. Pass nil to accept the default values.
func NewRequestsClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*RequestsClient, error) {
	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
	if err != nil {
		return nil, err
	}
	client := &RequestsClient{
		internal: cl,
	}
	return client, nil
}

// BeginCreateOrUpdate - Create or update a billing request.
// If the operation fails it returns an *azcore.ResponseError type.
//   - billingRequestName - The ID that uniquely identifies a billing request.
//   - parameters - A request submitted by a user to manage billing. Users with an owner role on the scope can approve or decline
//     these requests.
//   - options - RequestsClientBeginCreateOrUpdateOptions contains the optional parameters for the RequestsClient.BeginCreateOrUpdate
//     method.
func (client *RequestsClient) BeginCreateOrUpdate(ctx context.Context, billingRequestName string, parameters Request, options *RequestsClientBeginCreateOrUpdateOptions) (*runtime.Poller[RequestsClientCreateOrUpdateResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.createOrUpdate(ctx, billingRequestName, parameters, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RequestsClientCreateOrUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[RequestsClientCreateOrUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// CreateOrUpdate - Create or update a billing request.
// If the operation fails it returns an *azcore.ResponseError type.
func (client *RequestsClient) createOrUpdate(ctx context.Context, billingRequestName string, parameters Request, options *RequestsClientBeginCreateOrUpdateOptions) (*http.Response, error) {
	var err error
	const operationName = "RequestsClient.BeginCreateOrUpdate"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.createOrUpdateCreateRequest(ctx, billingRequestName, parameters, options)
	if err != nil {
		return nil, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return nil, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// createOrUpdateCreateRequest creates the CreateOrUpdate request.
func (client *RequestsClient) createOrUpdateCreateRequest(ctx context.Context, billingRequestName string, parameters Request, _ *RequestsClientBeginCreateOrUpdateOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingRequests/{billingRequestName}"
	if billingRequestName == "" {
		return nil, errors.New("parameter billingRequestName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{billingRequestName}", url.PathEscape(billingRequestName))
	req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", version20240401)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, parameters); err != nil {
		return nil, err
	}
	return req, nil
}

// Get - Gets a billing request by its ID.
// If the operation fails it returns an *azcore.ResponseError type.
//   - billingRequestName - The ID that uniquely identifies a billing request.
//   - options - RequestsClientGetOptions contains the optional parameters for the RequestsClient.Get method.
func (client *RequestsClient) Get(ctx context.Context, billingRequestName string, options *RequestsClientGetOptions) (RequestsClientGetResponse, error) {
	var err error
	const operationName = "RequestsClient.Get"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getCreateRequest(ctx, billingRequestName, options)
	if err != nil {
		return RequestsClientGetResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return RequestsClientGetResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return RequestsClientGetResponse{}, err
	}
	resp, err := client.getHandleResponse(httpResp)
	return resp, err
}

// getCreateRequest creates the Get request.
func (client *RequestsClient) getCreateRequest(ctx context.Context, billingRequestName string, _ *RequestsClientGetOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingRequests/{billingRequestName}"
	if billingRequestName == "" {
		return nil, errors.New("parameter billingRequestName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{billingRequestName}", url.PathEscape(billingRequestName))
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", version20240401)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// getHandleResponse handles the Get response.
func (client *RequestsClient) getHandleResponse(resp *http.Response) (RequestsClientGetResponse, error) {
	result := RequestsClientGetResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.Request); err != nil {
		return RequestsClientGetResponse{}, err
	}
	return result, nil
}

// NewListByBillingAccountPager - The list of billing requests submitted for the billing account.
//   - billingAccountName - The ID that uniquely identifies a billing account.
//   - options - RequestsClientListByBillingAccountOptions contains the optional parameters for the RequestsClient.NewListByBillingAccountPager
//     method.
func (client *RequestsClient) NewListByBillingAccountPager(billingAccountName string, options *RequestsClientListByBillingAccountOptions) *runtime.Pager[RequestsClientListByBillingAccountResponse] {
	return runtime.NewPager(runtime.PagingHandler[RequestsClientListByBillingAccountResponse]{
		More: func(page RequestsClientListByBillingAccountResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *RequestsClientListByBillingAccountResponse) (RequestsClientListByBillingAccountResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RequestsClient.NewListByBillingAccountPager")
			nextLink := ""
			if page != nil {
				nextLink = *page.NextLink
			}
			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
				return client.listByBillingAccountCreateRequest(ctx, billingAccountName, options)
			}, nil)
			if err != nil {
				return RequestsClientListByBillingAccountResponse{}, err
			}
			return client.listByBillingAccountHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByBillingAccountCreateRequest creates the ListByBillingAccount request.
func (client *RequestsClient) listByBillingAccountCreateRequest(ctx context.Context, billingAccountName string, options *RequestsClientListByBillingAccountOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingRequests"
	if billingAccountName == "" {
		return nil, errors.New("parameter billingAccountName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{billingAccountName}", url.PathEscape(billingAccountName))
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", version20240401)
	if options != nil && options.Count != nil {
		reqQP.Set("count", strconv.FormatBool(*options.Count))
	}
	if options != nil && options.Filter != nil {
		reqQP.Set("filter", *options.Filter)
	}
	if options != nil && options.OrderBy != nil {
		reqQP.Set("orderBy", *options.OrderBy)
	}
	if options != nil && options.Search != nil {
		reqQP.Set("search", *options.Search)
	}
	if options != nil && options.Skip != nil {
		reqQP.Set("skip", strconv.FormatInt(*options.Skip, 10))
	}
	if options != nil && options.Top != nil {
		reqQP.Set("top", strconv.FormatInt(*options.Top, 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listByBillingAccountHandleResponse handles the ListByBillingAccount response.
func (client *RequestsClient) listByBillingAccountHandleResponse(resp *http.Response) (RequestsClientListByBillingAccountResponse, error) {
	result := RequestsClientListByBillingAccountResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.RequestListResult); err != nil {
		return RequestsClientListByBillingAccountResponse{}, err
	}
	return result, nil
}

// NewListByBillingProfilePager - The list of billing requests submitted for the billing profile.
//   - billingAccountName - The ID that uniquely identifies a billing account.
//   - billingProfileName - The ID that uniquely identifies a billing profile.
//   - options - RequestsClientListByBillingProfileOptions contains the optional parameters for the RequestsClient.NewListByBillingProfilePager
//     method.
func (client *RequestsClient) NewListByBillingProfilePager(billingAccountName string, billingProfileName string, options *RequestsClientListByBillingProfileOptions) *runtime.Pager[RequestsClientListByBillingProfileResponse] {
	return runtime.NewPager(runtime.PagingHandler[RequestsClientListByBillingProfileResponse]{
		More: func(page RequestsClientListByBillingProfileResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *RequestsClientListByBillingProfileResponse) (RequestsClientListByBillingProfileResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RequestsClient.NewListByBillingProfilePager")
			nextLink := ""
			if page != nil {
				nextLink = *page.NextLink
			}
			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
				return client.listByBillingProfileCreateRequest(ctx, billingAccountName, billingProfileName, options)
			}, nil)
			if err != nil {
				return RequestsClientListByBillingProfileResponse{}, err
			}
			return client.listByBillingProfileHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByBillingProfileCreateRequest creates the ListByBillingProfile request.
func (client *RequestsClient) listByBillingProfileCreateRequest(ctx context.Context, billingAccountName string, billingProfileName string, options *RequestsClientListByBillingProfileOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/billingRequests"
	if billingAccountName == "" {
		return nil, errors.New("parameter billingAccountName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{billingAccountName}", url.PathEscape(billingAccountName))
	if billingProfileName == "" {
		return nil, errors.New("parameter billingProfileName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{billingProfileName}", url.PathEscape(billingProfileName))
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", version20240401)
	if options != nil && options.Count != nil {
		reqQP.Set("count", strconv.FormatBool(*options.Count))
	}
	if options != nil && options.Filter != nil {
		reqQP.Set("filter", *options.Filter)
	}
	if options != nil && options.OrderBy != nil {
		reqQP.Set("orderBy", *options.OrderBy)
	}
	if options != nil && options.Search != nil {
		reqQP.Set("search", *options.Search)
	}
	if options != nil && options.Skip != nil {
		reqQP.Set("skip", strconv.FormatInt(*options.Skip, 10))
	}
	if options != nil && options.Top != nil {
		reqQP.Set("top", strconv.FormatInt(*options.Top, 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listByBillingProfileHandleResponse handles the ListByBillingProfile response.
func (client *RequestsClient) listByBillingProfileHandleResponse(resp *http.Response) (RequestsClientListByBillingProfileResponse, error) {
	result := RequestsClientListByBillingProfileResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.RequestListResult); err != nil {
		return RequestsClientListByBillingProfileResponse{}, err
	}
	return result, nil
}

// NewListByCustomerPager - The list of billing requests submitted for the customer.
//   - billingAccountName - The ID that uniquely identifies a billing account.
//   - billingProfileName - The ID that uniquely identifies a billing profile.
//   - customerName - The ID that uniquely identifies a customer.
//   - options - RequestsClientListByCustomerOptions contains the optional parameters for the RequestsClient.NewListByCustomerPager
//     method.
func (client *RequestsClient) NewListByCustomerPager(billingAccountName string, billingProfileName string, customerName string, options *RequestsClientListByCustomerOptions) *runtime.Pager[RequestsClientListByCustomerResponse] {
	return runtime.NewPager(runtime.PagingHandler[RequestsClientListByCustomerResponse]{
		More: func(page RequestsClientListByCustomerResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *RequestsClientListByCustomerResponse) (RequestsClientListByCustomerResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RequestsClient.NewListByCustomerPager")
			nextLink := ""
			if page != nil {
				nextLink = *page.NextLink
			}
			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
				return client.listByCustomerCreateRequest(ctx, billingAccountName, billingProfileName, customerName, options)
			}, nil)
			if err != nil {
				return RequestsClientListByCustomerResponse{}, err
			}
			return client.listByCustomerHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByCustomerCreateRequest creates the ListByCustomer request.
func (client *RequestsClient) listByCustomerCreateRequest(ctx context.Context, billingAccountName string, billingProfileName string, customerName string, options *RequestsClientListByCustomerOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/customers/{customerName}/billingRequests"
	if billingAccountName == "" {
		return nil, errors.New("parameter billingAccountName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{billingAccountName}", url.PathEscape(billingAccountName))
	if billingProfileName == "" {
		return nil, errors.New("parameter billingProfileName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{billingProfileName}", url.PathEscape(billingProfileName))
	if customerName == "" {
		return nil, errors.New("parameter customerName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{customerName}", url.PathEscape(customerName))
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", version20240401)
	if options != nil && options.Count != nil {
		reqQP.Set("count", strconv.FormatBool(*options.Count))
	}
	if options != nil && options.Filter != nil {
		reqQP.Set("filter", *options.Filter)
	}
	if options != nil && options.OrderBy != nil {
		reqQP.Set("orderBy", *options.OrderBy)
	}
	if options != nil && options.Search != nil {
		reqQP.Set("search", *options.Search)
	}
	if options != nil && options.Skip != nil {
		reqQP.Set("skip", strconv.FormatInt(*options.Skip, 10))
	}
	if options != nil && options.Top != nil {
		reqQP.Set("top", strconv.FormatInt(*options.Top, 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listByCustomerHandleResponse handles the ListByCustomer response.
func (client *RequestsClient) listByCustomerHandleResponse(resp *http.Response) (RequestsClientListByCustomerResponse, error) {
	result := RequestsClientListByCustomerResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.RequestListResult); err != nil {
		return RequestsClientListByCustomerResponse{}, err
	}
	return result, nil
}

// NewListByInvoiceSectionPager - The list of billing requests submitted for the invoice section.
//   - billingAccountName - The ID that uniquely identifies a billing account.
//   - billingProfileName - The ID that uniquely identifies a billing profile.
//   - invoiceSectionName - The ID that uniquely identifies an invoice section.
//   - options - RequestsClientListByInvoiceSectionOptions contains the optional parameters for the RequestsClient.NewListByInvoiceSectionPager
//     method.
func (client *RequestsClient) NewListByInvoiceSectionPager(billingAccountName string, billingProfileName string, invoiceSectionName string, options *RequestsClientListByInvoiceSectionOptions) *runtime.Pager[RequestsClientListByInvoiceSectionResponse] {
	return runtime.NewPager(runtime.PagingHandler[RequestsClientListByInvoiceSectionResponse]{
		More: func(page RequestsClientListByInvoiceSectionResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *RequestsClientListByInvoiceSectionResponse) (RequestsClientListByInvoiceSectionResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RequestsClient.NewListByInvoiceSectionPager")
			nextLink := ""
			if page != nil {
				nextLink = *page.NextLink
			}
			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
				return client.listByInvoiceSectionCreateRequest(ctx, billingAccountName, billingProfileName, invoiceSectionName, options)
			}, nil)
			if err != nil {
				return RequestsClientListByInvoiceSectionResponse{}, err
			}
			return client.listByInvoiceSectionHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByInvoiceSectionCreateRequest creates the ListByInvoiceSection request.
func (client *RequestsClient) listByInvoiceSectionCreateRequest(ctx context.Context, billingAccountName string, billingProfileName string, invoiceSectionName string, options *RequestsClientListByInvoiceSectionOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/invoiceSections/{invoiceSectionName}/billingRequests"
	if billingAccountName == "" {
		return nil, errors.New("parameter billingAccountName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{billingAccountName}", url.PathEscape(billingAccountName))
	if billingProfileName == "" {
		return nil, errors.New("parameter billingProfileName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{billingProfileName}", url.PathEscape(billingProfileName))
	if invoiceSectionName == "" {
		return nil, errors.New("parameter invoiceSectionName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{invoiceSectionName}", url.PathEscape(invoiceSectionName))
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", version20240401)
	if options != nil && options.Count != nil {
		reqQP.Set("count", strconv.FormatBool(*options.Count))
	}
	if options != nil && options.Filter != nil {
		reqQP.Set("filter", *options.Filter)
	}
	if options != nil && options.OrderBy != nil {
		reqQP.Set("orderBy", *options.OrderBy)
	}
	if options != nil && options.Search != nil {
		reqQP.Set("search", *options.Search)
	}
	if options != nil && options.Skip != nil {
		reqQP.Set("skip", strconv.FormatInt(*options.Skip, 10))
	}
	if options != nil && options.Top != nil {
		reqQP.Set("top", strconv.FormatInt(*options.Top, 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listByInvoiceSectionHandleResponse handles the ListByInvoiceSection response.
func (client *RequestsClient) listByInvoiceSectionHandleResponse(resp *http.Response) (RequestsClientListByInvoiceSectionResponse, error) {
	result := RequestsClientListByInvoiceSectionResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.RequestListResult); err != nil {
		return RequestsClientListByInvoiceSectionResponse{}, err
	}
	return result, nil
}

// NewListByUserPager - The list of billing requests submitted by a user.
//   - options - RequestsClientListByUserOptions contains the optional parameters for the RequestsClient.NewListByUserPager method.
func (client *RequestsClient) NewListByUserPager(options *RequestsClientListByUserOptions) *runtime.Pager[RequestsClientListByUserResponse] {
	return runtime.NewPager(runtime.PagingHandler[RequestsClientListByUserResponse]{
		More: func(page RequestsClientListByUserResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *RequestsClientListByUserResponse) (RequestsClientListByUserResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RequestsClient.NewListByUserPager")
			nextLink := ""
			if page != nil {
				nextLink = *page.NextLink
			}
			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
				return client.listByUserCreateRequest(ctx, options)
			}, nil)
			if err != nil {
				return RequestsClientListByUserResponse{}, err
			}
			return client.listByUserHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByUserCreateRequest creates the ListByUser request.
func (client *RequestsClient) listByUserCreateRequest(ctx context.Context, options *RequestsClientListByUserOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingRequests"
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", version20240401)
	if options != nil && options.Count != nil {
		reqQP.Set("count", strconv.FormatBool(*options.Count))
	}
	if options != nil && options.Filter != nil {
		reqQP.Set("filter", *options.Filter)
	}
	if options != nil && options.OrderBy != nil {
		reqQP.Set("orderBy", *options.OrderBy)
	}
	if options != nil && options.Search != nil {
		reqQP.Set("search", *options.Search)
	}
	if options != nil && options.Skip != nil {
		reqQP.Set("skip", strconv.FormatInt(*options.Skip, 10))
	}
	if options != nil && options.Top != nil {
		reqQP.Set("top", strconv.FormatInt(*options.Top, 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listByUserHandleResponse handles the ListByUser response.
func (client *RequestsClient) listByUserHandleResponse(resp *http.Response) (RequestsClientListByUserResponse, error) {
	result := RequestsClientListByUserResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.RequestListResult); err != nil {
		return RequestsClientListByUserResponse{}, err
	}
	return result, nil
}
