// 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 armpurestorageblock

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

// ReservationsClient contains the methods for the Reservations group.
// Don't use this type directly, use NewReservationsClient() instead.
type ReservationsClient struct {
	internal       *arm.Client
	subscriptionID string
}

// NewReservationsClient creates a new instance of ReservationsClient with the specified values.
//   - subscriptionID - The ID of the target subscription. The value must be an UUID.
//   - credential - used to authorize requests. Usually a credential from azidentity.
//   - options - pass nil to accept the default values.
func NewReservationsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ReservationsClient, error) {
	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
	if err != nil {
		return nil, err
	}
	client := &ReservationsClient{
		subscriptionID: subscriptionID,
		internal:       cl,
	}
	return client, nil
}

// BeginCreate - Create a reservation
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - reservationName - Name of the reservation.
//   - resource - Resource create parameters.
//   - options - ReservationsClientBeginCreateOptions contains the optional parameters for the ReservationsClient.BeginCreate
//     method.
func (client *ReservationsClient) BeginCreate(ctx context.Context, resourceGroupName string, reservationName string, resource Reservation, options *ReservationsClientBeginCreateOptions) (*runtime.Poller[ReservationsClientCreateResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.create(ctx, resourceGroupName, reservationName, resource, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ReservationsClientCreateResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ReservationsClientCreateResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// Create - Create a reservation
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
func (client *ReservationsClient) create(ctx context.Context, resourceGroupName string, reservationName string, resource Reservation, options *ReservationsClientBeginCreateOptions) (*http.Response, error) {
	var err error
	const operationName = "ReservationsClient.BeginCreate"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.createCreateRequest(ctx, resourceGroupName, reservationName, resource, 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
}

// createCreateRequest creates the Create request.
func (client *ReservationsClient) createCreateRequest(ctx context.Context, resourceGroupName string, reservationName string, resource Reservation, _ *ReservationsClientBeginCreateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/PureStorage.Block/reservations/{reservationName}"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if reservationName == "" {
		return nil, errors.New("parameter reservationName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{reservationName}", url.PathEscape(reservationName))
	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", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, resource); err != nil {
		return nil, err
	}
	return req, nil
}

// BeginDelete - Delete a reservation
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - reservationName - Name of the reservation.
//   - options - ReservationsClientBeginDeleteOptions contains the optional parameters for the ReservationsClient.BeginDelete
//     method.
func (client *ReservationsClient) BeginDelete(ctx context.Context, resourceGroupName string, reservationName string, options *ReservationsClientBeginDeleteOptions) (*runtime.Poller[ReservationsClientDeleteResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.deleteOperation(ctx, resourceGroupName, reservationName, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ReservationsClientDeleteResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ReservationsClientDeleteResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// Delete - Delete a reservation
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
func (client *ReservationsClient) deleteOperation(ctx context.Context, resourceGroupName string, reservationName string, options *ReservationsClientBeginDeleteOptions) (*http.Response, error) {
	var err error
	const operationName = "ReservationsClient.BeginDelete"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.deleteCreateRequest(ctx, resourceGroupName, reservationName, 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.StatusAccepted, http.StatusNoContent) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// deleteCreateRequest creates the Delete request.
func (client *ReservationsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, reservationName string, _ *ReservationsClientBeginDeleteOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/PureStorage.Block/reservations/{reservationName}"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if reservationName == "" {
		return nil, errors.New("parameter reservationName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{reservationName}", url.PathEscape(reservationName))
	req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	return req, nil
}

// Get - Get a reservation
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - reservationName - Name of the reservation.
//   - options - ReservationsClientGetOptions contains the optional parameters for the ReservationsClient.Get method.
func (client *ReservationsClient) Get(ctx context.Context, resourceGroupName string, reservationName string, options *ReservationsClientGetOptions) (ReservationsClientGetResponse, error) {
	var err error
	const operationName = "ReservationsClient.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, resourceGroupName, reservationName, options)
	if err != nil {
		return ReservationsClientGetResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return ReservationsClientGetResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return ReservationsClientGetResponse{}, err
	}
	resp, err := client.getHandleResponse(httpResp)
	return resp, err
}

// getCreateRequest creates the Get request.
func (client *ReservationsClient) getCreateRequest(ctx context.Context, resourceGroupName string, reservationName string, _ *ReservationsClientGetOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/PureStorage.Block/reservations/{reservationName}"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if reservationName == "" {
		return nil, errors.New("parameter reservationName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{reservationName}", url.PathEscape(reservationName))
	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-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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

// GetBillingReport - Provides a summarized report along with actions for resources billed via given reservation
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - reservationName - Name of the reservation.
//   - options - ReservationsClientGetBillingReportOptions contains the optional parameters for the ReservationsClient.GetBillingReport
//     method.
func (client *ReservationsClient) GetBillingReport(ctx context.Context, resourceGroupName string, reservationName string, options *ReservationsClientGetBillingReportOptions) (ReservationsClientGetBillingReportResponse, error) {
	var err error
	const operationName = "ReservationsClient.GetBillingReport"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getBillingReportCreateRequest(ctx, resourceGroupName, reservationName, options)
	if err != nil {
		return ReservationsClientGetBillingReportResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return ReservationsClientGetBillingReportResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return ReservationsClientGetBillingReportResponse{}, err
	}
	resp, err := client.getBillingReportHandleResponse(httpResp)
	return resp, err
}

// getBillingReportCreateRequest creates the GetBillingReport request.
func (client *ReservationsClient) getBillingReportCreateRequest(ctx context.Context, resourceGroupName string, reservationName string, _ *ReservationsClientGetBillingReportOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/PureStorage.Block/reservations/{reservationName}/getBillingReport"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if reservationName == "" {
		return nil, errors.New("parameter reservationName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{reservationName}", url.PathEscape(reservationName))
	req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// getBillingReportHandleResponse handles the GetBillingReport response.
func (client *ReservationsClient) getBillingReportHandleResponse(resp *http.Response) (ReservationsClientGetBillingReportResponse, error) {
	result := ReservationsClientGetBillingReportResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.ReservationBillingUsageReport); err != nil {
		return ReservationsClientGetBillingReportResponse{}, err
	}
	return result, nil
}

// GetBillingStatus - Provides various statistics about resources billed via given reservation.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - reservationName - Name of the reservation.
//   - options - ReservationsClientGetBillingStatusOptions contains the optional parameters for the ReservationsClient.GetBillingStatus
//     method.
func (client *ReservationsClient) GetBillingStatus(ctx context.Context, resourceGroupName string, reservationName string, options *ReservationsClientGetBillingStatusOptions) (ReservationsClientGetBillingStatusResponse, error) {
	var err error
	const operationName = "ReservationsClient.GetBillingStatus"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getBillingStatusCreateRequest(ctx, resourceGroupName, reservationName, options)
	if err != nil {
		return ReservationsClientGetBillingStatusResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return ReservationsClientGetBillingStatusResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return ReservationsClientGetBillingStatusResponse{}, err
	}
	resp, err := client.getBillingStatusHandleResponse(httpResp)
	return resp, err
}

// getBillingStatusCreateRequest creates the GetBillingStatus request.
func (client *ReservationsClient) getBillingStatusCreateRequest(ctx context.Context, resourceGroupName string, reservationName string, _ *ReservationsClientGetBillingStatusOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/PureStorage.Block/reservations/{reservationName}/getBillingStatus"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if reservationName == "" {
		return nil, errors.New("parameter reservationName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{reservationName}", url.PathEscape(reservationName))
	req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// getBillingStatusHandleResponse handles the GetBillingStatus response.
func (client *ReservationsClient) getBillingStatusHandleResponse(resp *http.Response) (ReservationsClientGetBillingStatusResponse, error) {
	result := ReservationsClientGetBillingStatusResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.ReservationBillingStatus); err != nil {
		return ReservationsClientGetBillingStatusResponse{}, err
	}
	return result, nil
}

// GetResourceLimits - Limits constraining certain resource properties.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - reservationName - Name of the reservation.
//   - options - ReservationsClientGetResourceLimitsOptions contains the optional parameters for the ReservationsClient.GetResourceLimits
//     method.
func (client *ReservationsClient) GetResourceLimits(ctx context.Context, resourceGroupName string, reservationName string, options *ReservationsClientGetResourceLimitsOptions) (ReservationsClientGetResourceLimitsResponse, error) {
	var err error
	const operationName = "ReservationsClient.GetResourceLimits"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getResourceLimitsCreateRequest(ctx, resourceGroupName, reservationName, options)
	if err != nil {
		return ReservationsClientGetResourceLimitsResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return ReservationsClientGetResourceLimitsResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return ReservationsClientGetResourceLimitsResponse{}, err
	}
	resp, err := client.getResourceLimitsHandleResponse(httpResp)
	return resp, err
}

// getResourceLimitsCreateRequest creates the GetResourceLimits request.
func (client *ReservationsClient) getResourceLimitsCreateRequest(ctx context.Context, resourceGroupName string, reservationName string, _ *ReservationsClientGetResourceLimitsOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/PureStorage.Block/reservations/{reservationName}/getResourceLimits"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if reservationName == "" {
		return nil, errors.New("parameter reservationName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{reservationName}", url.PathEscape(reservationName))
	req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// getResourceLimitsHandleResponse handles the GetResourceLimits response.
func (client *ReservationsClient) getResourceLimitsHandleResponse(resp *http.Response) (ReservationsClientGetResourceLimitsResponse, error) {
	result := ReservationsClientGetResourceLimitsResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.LimitDetails); err != nil {
		return ReservationsClientGetResourceLimitsResponse{}, err
	}
	return result, nil
}

// NewListByResourceGroupPager - List reservations by resource group
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - options - ReservationsClientListByResourceGroupOptions contains the optional parameters for the ReservationsClient.NewListByResourceGroupPager
//     method.
func (client *ReservationsClient) NewListByResourceGroupPager(resourceGroupName string, options *ReservationsClientListByResourceGroupOptions) *runtime.Pager[ReservationsClientListByResourceGroupResponse] {
	return runtime.NewPager(runtime.PagingHandler[ReservationsClientListByResourceGroupResponse]{
		More: func(page ReservationsClientListByResourceGroupResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *ReservationsClientListByResourceGroupResponse) (ReservationsClientListByResourceGroupResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ReservationsClient.NewListByResourceGroupPager")
			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.listByResourceGroupCreateRequest(ctx, resourceGroupName, options)
			}, nil)
			if err != nil {
				return ReservationsClientListByResourceGroupResponse{}, err
			}
			return client.listByResourceGroupHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByResourceGroupCreateRequest creates the ListByResourceGroup request.
func (client *ReservationsClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, _ *ReservationsClientListByResourceGroupOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/PureStorage.Block/reservations"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	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-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listByResourceGroupHandleResponse handles the ListByResourceGroup response.
func (client *ReservationsClient) listByResourceGroupHandleResponse(resp *http.Response) (ReservationsClientListByResourceGroupResponse, error) {
	result := ReservationsClientListByResourceGroupResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.ReservationListResult); err != nil {
		return ReservationsClientListByResourceGroupResponse{}, err
	}
	return result, nil
}

// NewListBySubscriptionPager - List reservations by Azure subscription ID
//
// Generated from API version 2024-11-01
//   - options - ReservationsClientListBySubscriptionOptions contains the optional parameters for the ReservationsClient.NewListBySubscriptionPager
//     method.
func (client *ReservationsClient) NewListBySubscriptionPager(options *ReservationsClientListBySubscriptionOptions) *runtime.Pager[ReservationsClientListBySubscriptionResponse] {
	return runtime.NewPager(runtime.PagingHandler[ReservationsClientListBySubscriptionResponse]{
		More: func(page ReservationsClientListBySubscriptionResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *ReservationsClientListBySubscriptionResponse) (ReservationsClientListBySubscriptionResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ReservationsClient.NewListBySubscriptionPager")
			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.listBySubscriptionCreateRequest(ctx, options)
			}, nil)
			if err != nil {
				return ReservationsClientListBySubscriptionResponse{}, err
			}
			return client.listBySubscriptionHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listBySubscriptionCreateRequest creates the ListBySubscription request.
func (client *ReservationsClient) listBySubscriptionCreateRequest(ctx context.Context, _ *ReservationsClientListBySubscriptionOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/PureStorage.Block/reservations"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	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-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listBySubscriptionHandleResponse handles the ListBySubscription response.
func (client *ReservationsClient) listBySubscriptionHandleResponse(resp *http.Response) (ReservationsClientListBySubscriptionResponse, error) {
	result := ReservationsClientListBySubscriptionResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.ReservationListResult); err != nil {
		return ReservationsClientListBySubscriptionResponse{}, err
	}
	return result, nil
}

// BeginUpdate - Update a reservation
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - reservationName - Name of the reservation.
//   - properties - The resource properties to be updated.
//   - options - ReservationsClientBeginUpdateOptions contains the optional parameters for the ReservationsClient.BeginUpdate
//     method.
func (client *ReservationsClient) BeginUpdate(ctx context.Context, resourceGroupName string, reservationName string, properties ReservationUpdate, options *ReservationsClientBeginUpdateOptions) (*runtime.Poller[ReservationsClientUpdateResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.update(ctx, resourceGroupName, reservationName, properties, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ReservationsClientUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ReservationsClientUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// Update - Update a reservation
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
func (client *ReservationsClient) update(ctx context.Context, resourceGroupName string, reservationName string, properties ReservationUpdate, options *ReservationsClientBeginUpdateOptions) (*http.Response, error) {
	var err error
	const operationName = "ReservationsClient.BeginUpdate"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.updateCreateRequest(ctx, resourceGroupName, reservationName, properties, 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.StatusAccepted) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// updateCreateRequest creates the Update request.
func (client *ReservationsClient) updateCreateRequest(ctx context.Context, resourceGroupName string, reservationName string, properties ReservationUpdate, _ *ReservationsClientBeginUpdateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/PureStorage.Block/reservations/{reservationName}"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if reservationName == "" {
		return nil, errors.New("parameter reservationName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{reservationName}", url.PathEscape(reservationName))
	req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, properties); err != nil {
		return nil, err
	}
	return req, nil
}
