//go:build go1.18
// +build go1.18

// 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) AutoRest Code Generator. DO NOT EDIT.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

package armbilling

import (
	"context"
	"errors"
	"net/http"
	"net/url"
	"strings"

	"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"
)

// RoleDefinitionClient contains the methods for the BillingRoleDefinition group.
// Don't use this type directly, use NewRoleDefinitionClient() instead.
type RoleDefinitionClient struct {
	internal *arm.Client
}

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

// GetByBillingAccount - Gets the definition for a role on a billing account. The operation is supported for billing accounts
// with agreement type Microsoft Partner Agreement, Microsoft Customer Agreement or Enterprise
// Agreement.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-04-01
//   - billingAccountName - The ID that uniquely identifies a billing account.
//   - roleDefinitionName - The ID that uniquely identifies a role definition.
//   - options - RoleDefinitionClientGetByBillingAccountOptions contains the optional parameters for the RoleDefinitionClient.GetByBillingAccount
//     method.
func (client *RoleDefinitionClient) GetByBillingAccount(ctx context.Context, billingAccountName string, roleDefinitionName string, options *RoleDefinitionClientGetByBillingAccountOptions) (RoleDefinitionClientGetByBillingAccountResponse, error) {
	var err error
	const operationName = "RoleDefinitionClient.GetByBillingAccount"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getByBillingAccountCreateRequest(ctx, billingAccountName, roleDefinitionName, options)
	if err != nil {
		return RoleDefinitionClientGetByBillingAccountResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return RoleDefinitionClientGetByBillingAccountResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return RoleDefinitionClientGetByBillingAccountResponse{}, err
	}
	resp, err := client.getByBillingAccountHandleResponse(httpResp)
	return resp, err
}

// getByBillingAccountCreateRequest creates the GetByBillingAccount request.
func (client *RoleDefinitionClient) getByBillingAccountCreateRequest(ctx context.Context, billingAccountName string, roleDefinitionName string, options *RoleDefinitionClientGetByBillingAccountOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingRoleDefinitions/{roleDefinitionName}"
	if billingAccountName == "" {
		return nil, errors.New("parameter billingAccountName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{billingAccountName}", url.PathEscape(billingAccountName))
	if roleDefinitionName == "" {
		return nil, errors.New("parameter roleDefinitionName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{roleDefinitionName}", url.PathEscape(roleDefinitionName))
	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", "2024-04-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// getByBillingAccountHandleResponse handles the GetByBillingAccount response.
func (client *RoleDefinitionClient) getByBillingAccountHandleResponse(resp *http.Response) (RoleDefinitionClientGetByBillingAccountResponse, error) {
	result := RoleDefinitionClientGetByBillingAccountResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.RoleDefinition); err != nil {
		return RoleDefinitionClientGetByBillingAccountResponse{}, err
	}
	return result, nil
}

// GetByBillingProfile - Gets the definition for a role on a billing profile. The operation is supported for billing accounts
// with agreement type Microsoft Partner Agreement or Microsoft Customer Agreement.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-04-01
//   - billingAccountName - The ID that uniquely identifies a billing account.
//   - billingProfileName - The ID that uniquely identifies a billing profile.
//   - roleDefinitionName - The ID that uniquely identifies a role definition.
//   - options - RoleDefinitionClientGetByBillingProfileOptions contains the optional parameters for the RoleDefinitionClient.GetByBillingProfile
//     method.
func (client *RoleDefinitionClient) GetByBillingProfile(ctx context.Context, billingAccountName string, billingProfileName string, roleDefinitionName string, options *RoleDefinitionClientGetByBillingProfileOptions) (RoleDefinitionClientGetByBillingProfileResponse, error) {
	var err error
	const operationName = "RoleDefinitionClient.GetByBillingProfile"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getByBillingProfileCreateRequest(ctx, billingAccountName, billingProfileName, roleDefinitionName, options)
	if err != nil {
		return RoleDefinitionClientGetByBillingProfileResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return RoleDefinitionClientGetByBillingProfileResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return RoleDefinitionClientGetByBillingProfileResponse{}, err
	}
	resp, err := client.getByBillingProfileHandleResponse(httpResp)
	return resp, err
}

// getByBillingProfileCreateRequest creates the GetByBillingProfile request.
func (client *RoleDefinitionClient) getByBillingProfileCreateRequest(ctx context.Context, billingAccountName string, billingProfileName string, roleDefinitionName string, options *RoleDefinitionClientGetByBillingProfileOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/billingRoleDefinitions/{roleDefinitionName}"
	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 roleDefinitionName == "" {
		return nil, errors.New("parameter roleDefinitionName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{roleDefinitionName}", url.PathEscape(roleDefinitionName))
	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", "2024-04-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// getByBillingProfileHandleResponse handles the GetByBillingProfile response.
func (client *RoleDefinitionClient) getByBillingProfileHandleResponse(resp *http.Response) (RoleDefinitionClientGetByBillingProfileResponse, error) {
	result := RoleDefinitionClientGetByBillingProfileResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.RoleDefinition); err != nil {
		return RoleDefinitionClientGetByBillingProfileResponse{}, err
	}
	return result, nil
}

// GetByCustomer - Gets the definition for a role on a customer. The operation is supported only for billing accounts with
// agreement type Microsoft Partner Agreement.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-04-01
//   - 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.
//   - roleDefinitionName - The ID that uniquely identifies a role definition.
//   - options - RoleDefinitionClientGetByCustomerOptions contains the optional parameters for the RoleDefinitionClient.GetByCustomer
//     method.
func (client *RoleDefinitionClient) GetByCustomer(ctx context.Context, billingAccountName string, billingProfileName string, customerName string, roleDefinitionName string, options *RoleDefinitionClientGetByCustomerOptions) (RoleDefinitionClientGetByCustomerResponse, error) {
	var err error
	const operationName = "RoleDefinitionClient.GetByCustomer"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getByCustomerCreateRequest(ctx, billingAccountName, billingProfileName, customerName, roleDefinitionName, options)
	if err != nil {
		return RoleDefinitionClientGetByCustomerResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return RoleDefinitionClientGetByCustomerResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return RoleDefinitionClientGetByCustomerResponse{}, err
	}
	resp, err := client.getByCustomerHandleResponse(httpResp)
	return resp, err
}

// getByCustomerCreateRequest creates the GetByCustomer request.
func (client *RoleDefinitionClient) getByCustomerCreateRequest(ctx context.Context, billingAccountName string, billingProfileName string, customerName string, roleDefinitionName string, options *RoleDefinitionClientGetByCustomerOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/customers/{customerName}/billingRoleDefinitions/{roleDefinitionName}"
	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))
	if roleDefinitionName == "" {
		return nil, errors.New("parameter roleDefinitionName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{roleDefinitionName}", url.PathEscape(roleDefinitionName))
	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", "2024-04-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// getByCustomerHandleResponse handles the GetByCustomer response.
func (client *RoleDefinitionClient) getByCustomerHandleResponse(resp *http.Response) (RoleDefinitionClientGetByCustomerResponse, error) {
	result := RoleDefinitionClientGetByCustomerResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.RoleDefinition); err != nil {
		return RoleDefinitionClientGetByCustomerResponse{}, err
	}
	return result, nil
}

// GetByDepartment - Gets the definition for a role on a department. The operation is supported for billing accounts with
// agreement type Enterprise Agreement.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-04-01
//   - billingAccountName - The ID that uniquely identifies a billing account.
//   - departmentName - The name of the department.
//   - roleDefinitionName - The ID that uniquely identifies a role definition.
//   - options - RoleDefinitionClientGetByDepartmentOptions contains the optional parameters for the RoleDefinitionClient.GetByDepartment
//     method.
func (client *RoleDefinitionClient) GetByDepartment(ctx context.Context, billingAccountName string, departmentName string, roleDefinitionName string, options *RoleDefinitionClientGetByDepartmentOptions) (RoleDefinitionClientGetByDepartmentResponse, error) {
	var err error
	const operationName = "RoleDefinitionClient.GetByDepartment"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getByDepartmentCreateRequest(ctx, billingAccountName, departmentName, roleDefinitionName, options)
	if err != nil {
		return RoleDefinitionClientGetByDepartmentResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return RoleDefinitionClientGetByDepartmentResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return RoleDefinitionClientGetByDepartmentResponse{}, err
	}
	resp, err := client.getByDepartmentHandleResponse(httpResp)
	return resp, err
}

// getByDepartmentCreateRequest creates the GetByDepartment request.
func (client *RoleDefinitionClient) getByDepartmentCreateRequest(ctx context.Context, billingAccountName string, departmentName string, roleDefinitionName string, options *RoleDefinitionClientGetByDepartmentOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/departments/{departmentName}/billingRoleDefinitions/{roleDefinitionName}"
	if billingAccountName == "" {
		return nil, errors.New("parameter billingAccountName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{billingAccountName}", url.PathEscape(billingAccountName))
	if departmentName == "" {
		return nil, errors.New("parameter departmentName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{departmentName}", url.PathEscape(departmentName))
	if roleDefinitionName == "" {
		return nil, errors.New("parameter roleDefinitionName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{roleDefinitionName}", url.PathEscape(roleDefinitionName))
	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", "2024-04-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// getByDepartmentHandleResponse handles the GetByDepartment response.
func (client *RoleDefinitionClient) getByDepartmentHandleResponse(resp *http.Response) (RoleDefinitionClientGetByDepartmentResponse, error) {
	result := RoleDefinitionClientGetByDepartmentResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.RoleDefinition); err != nil {
		return RoleDefinitionClientGetByDepartmentResponse{}, err
	}
	return result, nil
}

// GetByEnrollmentAccount - Gets the definition for a role on an enrollment account. The operation is supported for billing
// accounts with agreement type Enterprise Agreement.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-04-01
//   - billingAccountName - The ID that uniquely identifies a billing account.
//   - enrollmentAccountName - The name of the enrollment account.
//   - roleDefinitionName - The ID that uniquely identifies a role definition.
//   - options - RoleDefinitionClientGetByEnrollmentAccountOptions contains the optional parameters for the RoleDefinitionClient.GetByEnrollmentAccount
//     method.
func (client *RoleDefinitionClient) GetByEnrollmentAccount(ctx context.Context, billingAccountName string, enrollmentAccountName string, roleDefinitionName string, options *RoleDefinitionClientGetByEnrollmentAccountOptions) (RoleDefinitionClientGetByEnrollmentAccountResponse, error) {
	var err error
	const operationName = "RoleDefinitionClient.GetByEnrollmentAccount"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getByEnrollmentAccountCreateRequest(ctx, billingAccountName, enrollmentAccountName, roleDefinitionName, options)
	if err != nil {
		return RoleDefinitionClientGetByEnrollmentAccountResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return RoleDefinitionClientGetByEnrollmentAccountResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return RoleDefinitionClientGetByEnrollmentAccountResponse{}, err
	}
	resp, err := client.getByEnrollmentAccountHandleResponse(httpResp)
	return resp, err
}

// getByEnrollmentAccountCreateRequest creates the GetByEnrollmentAccount request.
func (client *RoleDefinitionClient) getByEnrollmentAccountCreateRequest(ctx context.Context, billingAccountName string, enrollmentAccountName string, roleDefinitionName string, options *RoleDefinitionClientGetByEnrollmentAccountOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/enrollmentAccounts/{enrollmentAccountName}/billingRoleDefinitions/{roleDefinitionName}"
	if billingAccountName == "" {
		return nil, errors.New("parameter billingAccountName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{billingAccountName}", url.PathEscape(billingAccountName))
	if enrollmentAccountName == "" {
		return nil, errors.New("parameter enrollmentAccountName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{enrollmentAccountName}", url.PathEscape(enrollmentAccountName))
	if roleDefinitionName == "" {
		return nil, errors.New("parameter roleDefinitionName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{roleDefinitionName}", url.PathEscape(roleDefinitionName))
	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", "2024-04-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// getByEnrollmentAccountHandleResponse handles the GetByEnrollmentAccount response.
func (client *RoleDefinitionClient) getByEnrollmentAccountHandleResponse(resp *http.Response) (RoleDefinitionClientGetByEnrollmentAccountResponse, error) {
	result := RoleDefinitionClientGetByEnrollmentAccountResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.RoleDefinition); err != nil {
		return RoleDefinitionClientGetByEnrollmentAccountResponse{}, err
	}
	return result, nil
}

// GetByInvoiceSection - Gets the definition for a role on an invoice section. The operation is supported only for billing
// accounts with agreement type Microsoft Customer Agreement.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-04-01
//   - 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.
//   - roleDefinitionName - The ID that uniquely identifies a role definition.
//   - options - RoleDefinitionClientGetByInvoiceSectionOptions contains the optional parameters for the RoleDefinitionClient.GetByInvoiceSection
//     method.
func (client *RoleDefinitionClient) GetByInvoiceSection(ctx context.Context, billingAccountName string, billingProfileName string, invoiceSectionName string, roleDefinitionName string, options *RoleDefinitionClientGetByInvoiceSectionOptions) (RoleDefinitionClientGetByInvoiceSectionResponse, error) {
	var err error
	const operationName = "RoleDefinitionClient.GetByInvoiceSection"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getByInvoiceSectionCreateRequest(ctx, billingAccountName, billingProfileName, invoiceSectionName, roleDefinitionName, options)
	if err != nil {
		return RoleDefinitionClientGetByInvoiceSectionResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return RoleDefinitionClientGetByInvoiceSectionResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return RoleDefinitionClientGetByInvoiceSectionResponse{}, err
	}
	resp, err := client.getByInvoiceSectionHandleResponse(httpResp)
	return resp, err
}

// getByInvoiceSectionCreateRequest creates the GetByInvoiceSection request.
func (client *RoleDefinitionClient) getByInvoiceSectionCreateRequest(ctx context.Context, billingAccountName string, billingProfileName string, invoiceSectionName string, roleDefinitionName string, options *RoleDefinitionClientGetByInvoiceSectionOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/invoiceSections/{invoiceSectionName}/billingRoleDefinitions/{roleDefinitionName}"
	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))
	if roleDefinitionName == "" {
		return nil, errors.New("parameter roleDefinitionName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{roleDefinitionName}", url.PathEscape(roleDefinitionName))
	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", "2024-04-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// getByInvoiceSectionHandleResponse handles the GetByInvoiceSection response.
func (client *RoleDefinitionClient) getByInvoiceSectionHandleResponse(resp *http.Response) (RoleDefinitionClientGetByInvoiceSectionResponse, error) {
	result := RoleDefinitionClientGetByInvoiceSectionResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.RoleDefinition); err != nil {
		return RoleDefinitionClientGetByInvoiceSectionResponse{}, err
	}
	return result, nil
}

// NewListByBillingAccountPager - Lists the role definitions for a billing account. The operation is supported for billing
// accounts with agreement type Microsoft Partner Agreement, Microsoft Customer Agreement or Enterprise Agreement.
//
// Generated from API version 2024-04-01
//   - billingAccountName - The ID that uniquely identifies a billing account.
//   - options - RoleDefinitionClientListByBillingAccountOptions contains the optional parameters for the RoleDefinitionClient.NewListByBillingAccountPager
//     method.
func (client *RoleDefinitionClient) NewListByBillingAccountPager(billingAccountName string, options *RoleDefinitionClientListByBillingAccountOptions) *runtime.Pager[RoleDefinitionClientListByBillingAccountResponse] {
	return runtime.NewPager(runtime.PagingHandler[RoleDefinitionClientListByBillingAccountResponse]{
		More: func(page RoleDefinitionClientListByBillingAccountResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *RoleDefinitionClientListByBillingAccountResponse) (RoleDefinitionClientListByBillingAccountResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RoleDefinitionClient.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 RoleDefinitionClientListByBillingAccountResponse{}, err
			}
			return client.listByBillingAccountHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByBillingAccountCreateRequest creates the ListByBillingAccount request.
func (client *RoleDefinitionClient) listByBillingAccountCreateRequest(ctx context.Context, billingAccountName string, options *RoleDefinitionClientListByBillingAccountOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingRoleDefinitions"
	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", "2024-04-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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

// NewListByBillingProfilePager - Lists the role definitions for a billing profile. The operation is supported for billing
// accounts with agreement type Microsoft Partner Agreement, Microsoft Customer Agreement or Enterprise Agreement.
//
// Generated from API version 2024-04-01
//   - billingAccountName - The ID that uniquely identifies a billing account.
//   - billingProfileName - The ID that uniquely identifies a billing profile.
//   - options - RoleDefinitionClientListByBillingProfileOptions contains the optional parameters for the RoleDefinitionClient.NewListByBillingProfilePager
//     method.
func (client *RoleDefinitionClient) NewListByBillingProfilePager(billingAccountName string, billingProfileName string, options *RoleDefinitionClientListByBillingProfileOptions) *runtime.Pager[RoleDefinitionClientListByBillingProfileResponse] {
	return runtime.NewPager(runtime.PagingHandler[RoleDefinitionClientListByBillingProfileResponse]{
		More: func(page RoleDefinitionClientListByBillingProfileResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *RoleDefinitionClientListByBillingProfileResponse) (RoleDefinitionClientListByBillingProfileResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RoleDefinitionClient.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 RoleDefinitionClientListByBillingProfileResponse{}, err
			}
			return client.listByBillingProfileHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByBillingProfileCreateRequest creates the ListByBillingProfile request.
func (client *RoleDefinitionClient) listByBillingProfileCreateRequest(ctx context.Context, billingAccountName string, billingProfileName string, options *RoleDefinitionClientListByBillingProfileOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/billingRoleDefinitions"
	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", "2024-04-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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

// NewListByCustomerPager - Lists the role definitions for a customer. The operation is supported for billing accounts with
// agreement type Microsoft Partner Agreement.
//
// Generated from API version 2024-04-01
//   - 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 - RoleDefinitionClientListByCustomerOptions contains the optional parameters for the RoleDefinitionClient.NewListByCustomerPager
//     method.
func (client *RoleDefinitionClient) NewListByCustomerPager(billingAccountName string, billingProfileName string, customerName string, options *RoleDefinitionClientListByCustomerOptions) *runtime.Pager[RoleDefinitionClientListByCustomerResponse] {
	return runtime.NewPager(runtime.PagingHandler[RoleDefinitionClientListByCustomerResponse]{
		More: func(page RoleDefinitionClientListByCustomerResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *RoleDefinitionClientListByCustomerResponse) (RoleDefinitionClientListByCustomerResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RoleDefinitionClient.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 RoleDefinitionClientListByCustomerResponse{}, err
			}
			return client.listByCustomerHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByCustomerCreateRequest creates the ListByCustomer request.
func (client *RoleDefinitionClient) listByCustomerCreateRequest(ctx context.Context, billingAccountName string, billingProfileName string, customerName string, options *RoleDefinitionClientListByCustomerOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/customers/{customerName}/billingRoleDefinitions"
	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", "2024-04-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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

// NewListByDepartmentPager - List the definition for a department. The operation is supported for billing accounts with agreement
// type Enterprise Agreement.
//
// Generated from API version 2024-04-01
//   - billingAccountName - The ID that uniquely identifies a billing account.
//   - departmentName - The name of the department.
//   - options - RoleDefinitionClientListByDepartmentOptions contains the optional parameters for the RoleDefinitionClient.NewListByDepartmentPager
//     method.
func (client *RoleDefinitionClient) NewListByDepartmentPager(billingAccountName string, departmentName string, options *RoleDefinitionClientListByDepartmentOptions) *runtime.Pager[RoleDefinitionClientListByDepartmentResponse] {
	return runtime.NewPager(runtime.PagingHandler[RoleDefinitionClientListByDepartmentResponse]{
		More: func(page RoleDefinitionClientListByDepartmentResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *RoleDefinitionClientListByDepartmentResponse) (RoleDefinitionClientListByDepartmentResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RoleDefinitionClient.NewListByDepartmentPager")
			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.listByDepartmentCreateRequest(ctx, billingAccountName, departmentName, options)
			}, nil)
			if err != nil {
				return RoleDefinitionClientListByDepartmentResponse{}, err
			}
			return client.listByDepartmentHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByDepartmentCreateRequest creates the ListByDepartment request.
func (client *RoleDefinitionClient) listByDepartmentCreateRequest(ctx context.Context, billingAccountName string, departmentName string, options *RoleDefinitionClientListByDepartmentOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/departments/{departmentName}/billingRoleDefinitions"
	if billingAccountName == "" {
		return nil, errors.New("parameter billingAccountName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{billingAccountName}", url.PathEscape(billingAccountName))
	if departmentName == "" {
		return nil, errors.New("parameter departmentName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{departmentName}", url.PathEscape(departmentName))
	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", "2024-04-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listByDepartmentHandleResponse handles the ListByDepartment response.
func (client *RoleDefinitionClient) listByDepartmentHandleResponse(resp *http.Response) (RoleDefinitionClientListByDepartmentResponse, error) {
	result := RoleDefinitionClientListByDepartmentResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.RoleDefinitionListResult); err != nil {
		return RoleDefinitionClientListByDepartmentResponse{}, err
	}
	return result, nil
}

// NewListByEnrollmentAccountPager - List the definition for an enrollment account. The operation is supported for billing
// accounts with agreement type Enterprise Agreement.
//
// Generated from API version 2024-04-01
//   - billingAccountName - The ID that uniquely identifies a billing account.
//   - enrollmentAccountName - The name of the enrollment account.
//   - options - RoleDefinitionClientListByEnrollmentAccountOptions contains the optional parameters for the RoleDefinitionClient.NewListByEnrollmentAccountPager
//     method.
func (client *RoleDefinitionClient) NewListByEnrollmentAccountPager(billingAccountName string, enrollmentAccountName string, options *RoleDefinitionClientListByEnrollmentAccountOptions) *runtime.Pager[RoleDefinitionClientListByEnrollmentAccountResponse] {
	return runtime.NewPager(runtime.PagingHandler[RoleDefinitionClientListByEnrollmentAccountResponse]{
		More: func(page RoleDefinitionClientListByEnrollmentAccountResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *RoleDefinitionClientListByEnrollmentAccountResponse) (RoleDefinitionClientListByEnrollmentAccountResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RoleDefinitionClient.NewListByEnrollmentAccountPager")
			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.listByEnrollmentAccountCreateRequest(ctx, billingAccountName, enrollmentAccountName, options)
			}, nil)
			if err != nil {
				return RoleDefinitionClientListByEnrollmentAccountResponse{}, err
			}
			return client.listByEnrollmentAccountHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByEnrollmentAccountCreateRequest creates the ListByEnrollmentAccount request.
func (client *RoleDefinitionClient) listByEnrollmentAccountCreateRequest(ctx context.Context, billingAccountName string, enrollmentAccountName string, options *RoleDefinitionClientListByEnrollmentAccountOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/enrollmentAccounts/{enrollmentAccountName}/billingRoleDefinitions"
	if billingAccountName == "" {
		return nil, errors.New("parameter billingAccountName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{billingAccountName}", url.PathEscape(billingAccountName))
	if enrollmentAccountName == "" {
		return nil, errors.New("parameter enrollmentAccountName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{enrollmentAccountName}", url.PathEscape(enrollmentAccountName))
	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", "2024-04-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listByEnrollmentAccountHandleResponse handles the ListByEnrollmentAccount response.
func (client *RoleDefinitionClient) listByEnrollmentAccountHandleResponse(resp *http.Response) (RoleDefinitionClientListByEnrollmentAccountResponse, error) {
	result := RoleDefinitionClientListByEnrollmentAccountResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.RoleDefinitionListResult); err != nil {
		return RoleDefinitionClientListByEnrollmentAccountResponse{}, err
	}
	return result, nil
}

// NewListByInvoiceSectionPager - Lists the role definitions for an invoice section. The operation is supported for billing
// accounts with agreement type Microsoft Partner Agreement or Microsoft Customer Agreement.
//
// Generated from API version 2024-04-01
//   - 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 - RoleDefinitionClientListByInvoiceSectionOptions contains the optional parameters for the RoleDefinitionClient.NewListByInvoiceSectionPager
//     method.
func (client *RoleDefinitionClient) NewListByInvoiceSectionPager(billingAccountName string, billingProfileName string, invoiceSectionName string, options *RoleDefinitionClientListByInvoiceSectionOptions) *runtime.Pager[RoleDefinitionClientListByInvoiceSectionResponse] {
	return runtime.NewPager(runtime.PagingHandler[RoleDefinitionClientListByInvoiceSectionResponse]{
		More: func(page RoleDefinitionClientListByInvoiceSectionResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *RoleDefinitionClientListByInvoiceSectionResponse) (RoleDefinitionClientListByInvoiceSectionResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RoleDefinitionClient.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 RoleDefinitionClientListByInvoiceSectionResponse{}, err
			}
			return client.listByInvoiceSectionHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByInvoiceSectionCreateRequest creates the ListByInvoiceSection request.
func (client *RoleDefinitionClient) listByInvoiceSectionCreateRequest(ctx context.Context, billingAccountName string, billingProfileName string, invoiceSectionName string, options *RoleDefinitionClientListByInvoiceSectionOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/invoiceSections/{invoiceSectionName}/billingRoleDefinitions"
	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", "2024-04-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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