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

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

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

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

// Archive - Archive data from the AML file system.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-07-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - amlFilesystemName - Name for the AML file system. Allows alphanumerics, underscores, and hyphens. Start and end with alphanumeric.
//   - options - AmlFilesystemsClientArchiveOptions contains the optional parameters for the AmlFilesystemsClient.Archive method.
func (client *AmlFilesystemsClient) Archive(ctx context.Context, resourceGroupName string, amlFilesystemName string, options *AmlFilesystemsClientArchiveOptions) (AmlFilesystemsClientArchiveResponse, error) {
	var err error
	const operationName = "AmlFilesystemsClient.Archive"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.archiveCreateRequest(ctx, resourceGroupName, amlFilesystemName, options)
	if err != nil {
		return AmlFilesystemsClientArchiveResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return AmlFilesystemsClientArchiveResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return AmlFilesystemsClientArchiveResponse{}, err
	}
	return AmlFilesystemsClientArchiveResponse{}, nil
}

// archiveCreateRequest creates the Archive request.
func (client *AmlFilesystemsClient) archiveCreateRequest(ctx context.Context, resourceGroupName string, amlFilesystemName string, options *AmlFilesystemsClientArchiveOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageCache/amlFilesystems/{amlFilesystemName}/archive"
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if amlFilesystemName == "" {
		return nil, errors.New("parameter amlFilesystemName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{amlFilesystemName}", url.PathEscape(amlFilesystemName))
	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", "2025-07-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	if options != nil && options.ArchiveInfo != nil {
		if err := runtime.MarshalAsJSON(req, *options.ArchiveInfo); err != nil {
			return nil, err
		}
		return req, nil
	}
	return req, nil
}

// CancelArchive - Cancel archiving data from the AML file system.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-07-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - amlFilesystemName - Name for the AML file system. Allows alphanumerics, underscores, and hyphens. Start and end with alphanumeric.
//   - options - AmlFilesystemsClientCancelArchiveOptions contains the optional parameters for the AmlFilesystemsClient.CancelArchive
//     method.
func (client *AmlFilesystemsClient) CancelArchive(ctx context.Context, resourceGroupName string, amlFilesystemName string, options *AmlFilesystemsClientCancelArchiveOptions) (AmlFilesystemsClientCancelArchiveResponse, error) {
	var err error
	const operationName = "AmlFilesystemsClient.CancelArchive"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.cancelArchiveCreateRequest(ctx, resourceGroupName, amlFilesystemName, options)
	if err != nil {
		return AmlFilesystemsClientCancelArchiveResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return AmlFilesystemsClientCancelArchiveResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return AmlFilesystemsClientCancelArchiveResponse{}, err
	}
	return AmlFilesystemsClientCancelArchiveResponse{}, nil
}

// cancelArchiveCreateRequest creates the CancelArchive request.
func (client *AmlFilesystemsClient) cancelArchiveCreateRequest(ctx context.Context, resourceGroupName string, amlFilesystemName string, _ *AmlFilesystemsClientCancelArchiveOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageCache/amlFilesystems/{amlFilesystemName}/cancelArchive"
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if amlFilesystemName == "" {
		return nil, errors.New("parameter amlFilesystemName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{amlFilesystemName}", url.PathEscape(amlFilesystemName))
	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", "2025-07-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// BeginCreateOrUpdate - Create or update an AML file system.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-07-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - amlFilesystemName - Name for the AML file system. Allows alphanumerics, underscores, and hyphens. Start and end with alphanumeric.
//   - amlFilesystem - Object containing the user-selectable properties of the AML file system. If read-only properties are included,
//     they must match the existing values of those properties.
//   - options - AmlFilesystemsClientBeginCreateOrUpdateOptions contains the optional parameters for the AmlFilesystemsClient.BeginCreateOrUpdate
//     method.
func (client *AmlFilesystemsClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, amlFilesystemName string, amlFilesystem AmlFilesystem, options *AmlFilesystemsClientBeginCreateOrUpdateOptions) (*runtime.Poller[AmlFilesystemsClientCreateOrUpdateResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.createOrUpdate(ctx, resourceGroupName, amlFilesystemName, amlFilesystem, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AmlFilesystemsClientCreateOrUpdateResponse]{
			FinalStateVia: runtime.FinalStateViaAzureAsyncOp,
			Tracer:        client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[AmlFilesystemsClientCreateOrUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// CreateOrUpdate - Create or update an AML file system.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-07-01
func (client *AmlFilesystemsClient) createOrUpdate(ctx context.Context, resourceGroupName string, amlFilesystemName string, amlFilesystem AmlFilesystem, options *AmlFilesystemsClientBeginCreateOrUpdateOptions) (*http.Response, error) {
	var err error
	const operationName = "AmlFilesystemsClient.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, resourceGroupName, amlFilesystemName, amlFilesystem, 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 *AmlFilesystemsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, amlFilesystemName string, amlFilesystem AmlFilesystem, _ *AmlFilesystemsClientBeginCreateOrUpdateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageCache/amlFilesystems/{amlFilesystemName}"
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if amlFilesystemName == "" {
		return nil, errors.New("parameter amlFilesystemName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{amlFilesystemName}", url.PathEscape(amlFilesystemName))
	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", "2025-07-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, amlFilesystem); err != nil {
		return nil, err
	}
	return req, nil
}

// BeginDelete - Schedules an AML file system for deletion.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-07-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - amlFilesystemName - Name for the AML file system. Allows alphanumerics, underscores, and hyphens. Start and end with alphanumeric.
//   - options - AmlFilesystemsClientBeginDeleteOptions contains the optional parameters for the AmlFilesystemsClient.BeginDelete
//     method.
func (client *AmlFilesystemsClient) BeginDelete(ctx context.Context, resourceGroupName string, amlFilesystemName string, options *AmlFilesystemsClientBeginDeleteOptions) (*runtime.Poller[AmlFilesystemsClientDeleteResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.deleteOperation(ctx, resourceGroupName, amlFilesystemName, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AmlFilesystemsClientDeleteResponse]{
			FinalStateVia: runtime.FinalStateViaLocation,
			Tracer:        client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[AmlFilesystemsClientDeleteResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// Delete - Schedules an AML file system for deletion.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-07-01
func (client *AmlFilesystemsClient) deleteOperation(ctx context.Context, resourceGroupName string, amlFilesystemName string, options *AmlFilesystemsClientBeginDeleteOptions) (*http.Response, error) {
	var err error
	const operationName = "AmlFilesystemsClient.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, amlFilesystemName, 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, http.StatusNoContent) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// deleteCreateRequest creates the Delete request.
func (client *AmlFilesystemsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, amlFilesystemName string, _ *AmlFilesystemsClientBeginDeleteOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageCache/amlFilesystems/{amlFilesystemName}"
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if amlFilesystemName == "" {
		return nil, errors.New("parameter amlFilesystemName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{amlFilesystemName}", url.PathEscape(amlFilesystemName))
	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.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2025-07-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// Get - Returns an AML file system.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-07-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - amlFilesystemName - Name for the AML file system. Allows alphanumerics, underscores, and hyphens. Start and end with alphanumeric.
//   - options - AmlFilesystemsClientGetOptions contains the optional parameters for the AmlFilesystemsClient.Get method.
func (client *AmlFilesystemsClient) Get(ctx context.Context, resourceGroupName string, amlFilesystemName string, options *AmlFilesystemsClientGetOptions) (AmlFilesystemsClientGetResponse, error) {
	var err error
	const operationName = "AmlFilesystemsClient.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, amlFilesystemName, options)
	if err != nil {
		return AmlFilesystemsClientGetResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return AmlFilesystemsClientGetResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return AmlFilesystemsClientGetResponse{}, err
	}
	resp, err := client.getHandleResponse(httpResp)
	return resp, err
}

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

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

// NewListPager - Returns all AML file systems the user has access to under a subscription.
//
// Generated from API version 2025-07-01
//   - options - AmlFilesystemsClientListOptions contains the optional parameters for the AmlFilesystemsClient.NewListPager method.
func (client *AmlFilesystemsClient) NewListPager(options *AmlFilesystemsClientListOptions) *runtime.Pager[AmlFilesystemsClientListResponse] {
	return runtime.NewPager(runtime.PagingHandler[AmlFilesystemsClientListResponse]{
		More: func(page AmlFilesystemsClientListResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *AmlFilesystemsClientListResponse) (AmlFilesystemsClientListResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AmlFilesystemsClient.NewListPager")
			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.listCreateRequest(ctx, options)
			}, nil)
			if err != nil {
				return AmlFilesystemsClientListResponse{}, err
			}
			return client.listHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listCreateRequest creates the List request.
func (client *AmlFilesystemsClient) listCreateRequest(ctx context.Context, _ *AmlFilesystemsClientListOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.StorageCache/amlFilesystems"
	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", "2025-07-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listHandleResponse handles the List response.
func (client *AmlFilesystemsClient) listHandleResponse(resp *http.Response) (AmlFilesystemsClientListResponse, error) {
	result := AmlFilesystemsClientListResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.AmlFilesystemsListResult); err != nil {
		return AmlFilesystemsClientListResponse{}, err
	}
	return result, nil
}

// NewListByResourceGroupPager - Returns all AML file systems the user has access to under a resource group.
//
// Generated from API version 2025-07-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - options - AmlFilesystemsClientListByResourceGroupOptions contains the optional parameters for the AmlFilesystemsClient.NewListByResourceGroupPager
//     method.
func (client *AmlFilesystemsClient) NewListByResourceGroupPager(resourceGroupName string, options *AmlFilesystemsClientListByResourceGroupOptions) *runtime.Pager[AmlFilesystemsClientListByResourceGroupResponse] {
	return runtime.NewPager(runtime.PagingHandler[AmlFilesystemsClientListByResourceGroupResponse]{
		More: func(page AmlFilesystemsClientListByResourceGroupResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *AmlFilesystemsClientListByResourceGroupResponse) (AmlFilesystemsClientListByResourceGroupResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AmlFilesystemsClient.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 AmlFilesystemsClientListByResourceGroupResponse{}, err
			}
			return client.listByResourceGroupHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

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

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

// BeginUpdate - Update an AML file system instance.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-07-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - amlFilesystemName - Name for the AML file system. Allows alphanumerics, underscores, and hyphens. Start and end with alphanumeric.
//   - amlFilesystem - Object containing the user-selectable properties of the AML file system. If read-only properties are included,
//     they must match the existing values of those properties.
//   - options - AmlFilesystemsClientBeginUpdateOptions contains the optional parameters for the AmlFilesystemsClient.BeginUpdate
//     method.
func (client *AmlFilesystemsClient) BeginUpdate(ctx context.Context, resourceGroupName string, amlFilesystemName string, amlFilesystem AmlFilesystemUpdate, options *AmlFilesystemsClientBeginUpdateOptions) (*runtime.Poller[AmlFilesystemsClientUpdateResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.update(ctx, resourceGroupName, amlFilesystemName, amlFilesystem, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[AmlFilesystemsClientUpdateResponse]{
			FinalStateVia: runtime.FinalStateViaAzureAsyncOp,
			Tracer:        client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[AmlFilesystemsClientUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// Update - Update an AML file system instance.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-07-01
func (client *AmlFilesystemsClient) update(ctx context.Context, resourceGroupName string, amlFilesystemName string, amlFilesystem AmlFilesystemUpdate, options *AmlFilesystemsClientBeginUpdateOptions) (*http.Response, error) {
	var err error
	const operationName = "AmlFilesystemsClient.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, amlFilesystemName, amlFilesystem, 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 *AmlFilesystemsClient) updateCreateRequest(ctx context.Context, resourceGroupName string, amlFilesystemName string, amlFilesystem AmlFilesystemUpdate, _ *AmlFilesystemsClientBeginUpdateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageCache/amlFilesystems/{amlFilesystemName}"
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if amlFilesystemName == "" {
		return nil, errors.New("parameter amlFilesystemName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{amlFilesystemName}", url.PathEscape(amlFilesystemName))
	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", "2025-07-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, amlFilesystem); err != nil {
		return nil, err
	}
	return req, nil
}
