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

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

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

// NewClient creates a new instance of Client 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 NewClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*Client, error) {
	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
	if err != nil {
		return nil, err
	}
	client := &Client{
		subscriptionID: subscriptionID,
		internal:       cl,
	}
	return client, nil
}

// ClusterGetVersion - Get details of a version for an Extension Type installable to the cluster.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - clusterRp - The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes, Microsoft.HybridContainerService.
//   - clusterResourceName - The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters, provisionedClusters,
//     appliances.
//   - clusterName - The name of the kubernetes cluster.
//   - extensionTypeName - Name of the Extension Type.
//   - versionNumber - Version number of the Extension Type.
//   - options - ClientClusterGetVersionOptions contains the optional parameters for the Client.ClusterGetVersion method.
func (client *Client) ClusterGetVersion(ctx context.Context, resourceGroupName string, clusterRp string, clusterResourceName string, clusterName string, extensionTypeName string, versionNumber string, options *ClientClusterGetVersionOptions) (ClientClusterGetVersionResponse, error) {
	var err error
	const operationName = "Client.ClusterGetVersion"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.clusterGetVersionCreateRequest(ctx, resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionTypeName, versionNumber, options)
	if err != nil {
		return ClientClusterGetVersionResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return ClientClusterGetVersionResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return ClientClusterGetVersionResponse{}, err
	}
	resp, err := client.clusterGetVersionHandleResponse(httpResp)
	return resp, err
}

// clusterGetVersionCreateRequest creates the ClusterGetVersion request.
func (client *Client) clusterGetVersionCreateRequest(ctx context.Context, resourceGroupName string, clusterRp string, clusterResourceName string, clusterName string, extensionTypeName string, versionNumber string, _ *ClientClusterGetVersionOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{clusterRp}/{clusterResourceName}/{clusterName}/providers/Microsoft.KubernetesConfiguration/extensionTypes/{extensionTypeName}/versions/{versionNumber}"
	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 clusterRp == "" {
		return nil, errors.New("parameter clusterRp cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{clusterRp}", url.PathEscape(clusterRp))
	if clusterResourceName == "" {
		return nil, errors.New("parameter clusterResourceName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{clusterResourceName}", url.PathEscape(clusterResourceName))
	if clusterName == "" {
		return nil, errors.New("parameter clusterName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName))
	if extensionTypeName == "" {
		return nil, errors.New("parameter extensionTypeName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{extensionTypeName}", url.PathEscape(extensionTypeName))
	if versionNumber == "" {
		return nil, errors.New("parameter versionNumber cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{versionNumber}", url.PathEscape(versionNumber))
	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-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// clusterGetVersionHandleResponse handles the ClusterGetVersion response.
func (client *Client) clusterGetVersionHandleResponse(resp *http.Response) (ClientClusterGetVersionResponse, error) {
	result := ClientClusterGetVersionResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.ExtensionTypeVersionForReleaseTrain); err != nil {
		return ClientClusterGetVersionResponse{}, err
	}
	return result, nil
}

// NewClusterListVersionsPager - List the version for an Extension Type installable to the cluster.
//
// Generated from API version 2024-11-01-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - clusterRp - The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes, Microsoft.HybridContainerService.
//   - clusterResourceName - The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters, provisionedClusters,
//     appliances.
//   - clusterName - The name of the kubernetes cluster.
//   - extensionTypeName - Name of the Extension Type.
//   - options - ClientClusterListVersionsOptions contains the optional parameters for the Client.NewClusterListVersionsPager
//     method.
func (client *Client) NewClusterListVersionsPager(resourceGroupName string, clusterRp string, clusterResourceName string, clusterName string, extensionTypeName string, options *ClientClusterListVersionsOptions) *runtime.Pager[ClientClusterListVersionsResponse] {
	return runtime.NewPager(runtime.PagingHandler[ClientClusterListVersionsResponse]{
		More: func(page ClientClusterListVersionsResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *ClientClusterListVersionsResponse) (ClientClusterListVersionsResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewClusterListVersionsPager")
			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.clusterListVersionsCreateRequest(ctx, resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionTypeName, options)
			}, nil)
			if err != nil {
				return ClientClusterListVersionsResponse{}, err
			}
			return client.clusterListVersionsHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// clusterListVersionsCreateRequest creates the ClusterListVersions request.
func (client *Client) clusterListVersionsCreateRequest(ctx context.Context, resourceGroupName string, clusterRp string, clusterResourceName string, clusterName string, extensionTypeName string, options *ClientClusterListVersionsOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{clusterRp}/{clusterResourceName}/{clusterName}/providers/Microsoft.KubernetesConfiguration/extensionTypes/{extensionTypeName}/versions"
	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 clusterRp == "" {
		return nil, errors.New("parameter clusterRp cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{clusterRp}", url.PathEscape(clusterRp))
	if clusterResourceName == "" {
		return nil, errors.New("parameter clusterResourceName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{clusterResourceName}", url.PathEscape(clusterResourceName))
	if clusterName == "" {
		return nil, errors.New("parameter clusterName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName))
	if extensionTypeName == "" {
		return nil, errors.New("parameter extensionTypeName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{extensionTypeName}", url.PathEscape(extensionTypeName))
	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-preview")
	if options != nil && options.MajorVersion != nil {
		reqQP.Set("majorVersion", *options.MajorVersion)
	}
	if options != nil && options.ReleaseTrain != nil {
		reqQP.Set("releaseTrain", *options.ReleaseTrain)
	}
	if options != nil && options.ShowLatest != nil {
		reqQP.Set("showLatest", strconv.FormatBool(*options.ShowLatest))
	}
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// clusterListVersionsHandleResponse handles the ClusterListVersions response.
func (client *Client) clusterListVersionsHandleResponse(resp *http.Response) (ClientClusterListVersionsResponse, error) {
	result := ClientClusterListVersionsResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.ExtensionTypeVersionsList); err != nil {
		return ClientClusterListVersionsResponse{}, err
	}
	return result, nil
}

// Get - Get an Extension Type installable to the cluster based region and type for the cluster.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - clusterRp - The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes, Microsoft.HybridContainerService.
//   - clusterResourceName - The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters, provisionedClusters,
//     appliances.
//   - clusterName - The name of the kubernetes cluster.
//   - extensionTypeName - Name of the Extension Type.
//   - options - ClientGetOptions contains the optional parameters for the Client.Get method.
func (client *Client) Get(ctx context.Context, resourceGroupName string, clusterRp string, clusterResourceName string, clusterName string, extensionTypeName string, options *ClientGetOptions) (ClientGetResponse, error) {
	var err error
	const operationName = "Client.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, clusterRp, clusterResourceName, clusterName, extensionTypeName, options)
	if err != nil {
		return ClientGetResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return ClientGetResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return ClientGetResponse{}, err
	}
	resp, err := client.getHandleResponse(httpResp)
	return resp, err
}

// getCreateRequest creates the Get request.
func (client *Client) getCreateRequest(ctx context.Context, resourceGroupName string, clusterRp string, clusterResourceName string, clusterName string, extensionTypeName string, _ *ClientGetOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{clusterRp}/{clusterResourceName}/{clusterName}/providers/Microsoft.KubernetesConfiguration/extensionTypes/{extensionTypeName}"
	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 clusterRp == "" {
		return nil, errors.New("parameter clusterRp cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{clusterRp}", url.PathEscape(clusterRp))
	if clusterResourceName == "" {
		return nil, errors.New("parameter clusterResourceName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{clusterResourceName}", url.PathEscape(clusterResourceName))
	if clusterName == "" {
		return nil, errors.New("parameter clusterName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName))
	if extensionTypeName == "" {
		return nil, errors.New("parameter extensionTypeName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{extensionTypeName}", url.PathEscape(extensionTypeName))
	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-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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

// GetVersion - Get details of a version for an extension type and location
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01-preview
//   - location - The name of Azure region.
//   - extensionTypeName - Name of the Extension Type.
//   - versionNumber - Version number of the Extension Type.
//   - options - ClientGetVersionOptions contains the optional parameters for the Client.GetVersion method.
func (client *Client) GetVersion(ctx context.Context, location string, extensionTypeName string, versionNumber string, options *ClientGetVersionOptions) (ClientGetVersionResponse, error) {
	var err error
	const operationName = "Client.GetVersion"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getVersionCreateRequest(ctx, location, extensionTypeName, versionNumber, options)
	if err != nil {
		return ClientGetVersionResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return ClientGetVersionResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return ClientGetVersionResponse{}, err
	}
	resp, err := client.getVersionHandleResponse(httpResp)
	return resp, err
}

// getVersionCreateRequest creates the GetVersion request.
func (client *Client) getVersionCreateRequest(ctx context.Context, location string, extensionTypeName string, versionNumber string, _ *ClientGetVersionOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.KubernetesConfiguration/locations/{location}/extensionTypes/{extensionTypeName}/versions/{versionNumber}"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if location == "" {
		return nil, errors.New("parameter location cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location))
	if extensionTypeName == "" {
		return nil, errors.New("parameter extensionTypeName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{extensionTypeName}", url.PathEscape(extensionTypeName))
	if versionNumber == "" {
		return nil, errors.New("parameter versionNumber cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{versionNumber}", url.PathEscape(versionNumber))
	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-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// getVersionHandleResponse handles the GetVersion response.
func (client *Client) getVersionHandleResponse(resp *http.Response) (ClientGetVersionResponse, error) {
	result := ClientGetVersionResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.ExtensionTypeVersionForReleaseTrain); err != nil {
		return ClientGetVersionResponse{}, err
	}
	return result, nil
}

// NewListPager - List installable Extension Types for the cluster based region and type for the cluster.
//
// Generated from API version 2024-11-01-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - clusterRp - The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes, Microsoft.HybridContainerService.
//   - clusterResourceName - The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters, provisionedClusters,
//     appliances.
//   - clusterName - The name of the kubernetes cluster.
//   - options - ClientListOptions contains the optional parameters for the Client.NewListPager method.
func (client *Client) NewListPager(resourceGroupName string, clusterRp string, clusterResourceName string, clusterName string, options *ClientListOptions) *runtime.Pager[ClientListResponse] {
	return runtime.NewPager(runtime.PagingHandler[ClientListResponse]{
		More: func(page ClientListResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *ClientListResponse) (ClientListResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.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, resourceGroupName, clusterRp, clusterResourceName, clusterName, options)
			}, nil)
			if err != nil {
				return ClientListResponse{}, err
			}
			return client.listHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listCreateRequest creates the List request.
func (client *Client) listCreateRequest(ctx context.Context, resourceGroupName string, clusterRp string, clusterResourceName string, clusterName string, options *ClientListOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{clusterRp}/{clusterResourceName}/{clusterName}/providers/Microsoft.KubernetesConfiguration/extensionTypes"
	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 clusterRp == "" {
		return nil, errors.New("parameter clusterRp cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{clusterRp}", url.PathEscape(clusterRp))
	if clusterResourceName == "" {
		return nil, errors.New("parameter clusterResourceName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{clusterResourceName}", url.PathEscape(clusterResourceName))
	if clusterName == "" {
		return nil, errors.New("parameter clusterName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName))
	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-preview")
	if options != nil && options.OfferID != nil {
		reqQP.Set("offerId", *options.OfferID)
	}
	if options != nil && options.PlanID != nil {
		reqQP.Set("planId", *options.PlanID)
	}
	if options != nil && options.PublisherID != nil {
		reqQP.Set("publisherId", *options.PublisherID)
	}
	if options != nil && options.ReleaseTrain != nil {
		reqQP.Set("releaseTrain", *options.ReleaseTrain)
	}
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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

// NewListVersionsPager - List the versions for an extension type and location.
//
// Generated from API version 2024-11-01-preview
//   - location - The name of Azure region.
//   - extensionTypeName - Name of the Extension Type.
//   - options - ClientListVersionsOptions contains the optional parameters for the Client.NewListVersionsPager method.
func (client *Client) NewListVersionsPager(location string, extensionTypeName string, options *ClientListVersionsOptions) *runtime.Pager[ClientListVersionsResponse] {
	return runtime.NewPager(runtime.PagingHandler[ClientListVersionsResponse]{
		More: func(page ClientListVersionsResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *ClientListVersionsResponse) (ClientListVersionsResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListVersionsPager")
			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.listVersionsCreateRequest(ctx, location, extensionTypeName, options)
			}, nil)
			if err != nil {
				return ClientListVersionsResponse{}, err
			}
			return client.listVersionsHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listVersionsCreateRequest creates the ListVersions request.
func (client *Client) listVersionsCreateRequest(ctx context.Context, location string, extensionTypeName string, options *ClientListVersionsOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.KubernetesConfiguration/locations/{location}/extensionTypes/{extensionTypeName}/versions"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if location == "" {
		return nil, errors.New("parameter location cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location))
	if extensionTypeName == "" {
		return nil, errors.New("parameter extensionTypeName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{extensionTypeName}", url.PathEscape(extensionTypeName))
	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-preview")
	if options != nil && options.ClusterType != nil {
		reqQP.Set("clusterType", *options.ClusterType)
	}
	if options != nil && options.MajorVersion != nil {
		reqQP.Set("majorVersion", *options.MajorVersion)
	}
	if options != nil && options.ReleaseTrain != nil {
		reqQP.Set("releaseTrain", *options.ReleaseTrain)
	}
	if options != nil && options.ShowLatest != nil {
		reqQP.Set("showLatest", strconv.FormatBool(*options.ShowLatest))
	}
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listVersionsHandleResponse handles the ListVersions response.
func (client *Client) listVersionsHandleResponse(resp *http.Response) (ClientListVersionsResponse, error) {
	result := ClientListVersionsResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.ExtensionTypeVersionsList); err != nil {
		return ClientListVersionsResponse{}, err
	}
	return result, nil
}

// LocationGet - Get an extension type for the location.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01-preview
//   - location - The name of Azure region.
//   - extensionTypeName - Name of the Extension Type.
//   - options - ClientLocationGetOptions contains the optional parameters for the Client.LocationGet method.
func (client *Client) LocationGet(ctx context.Context, location string, extensionTypeName string, options *ClientLocationGetOptions) (ClientLocationGetResponse, error) {
	var err error
	const operationName = "Client.LocationGet"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.locationGetCreateRequest(ctx, location, extensionTypeName, options)
	if err != nil {
		return ClientLocationGetResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return ClientLocationGetResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return ClientLocationGetResponse{}, err
	}
	resp, err := client.locationGetHandleResponse(httpResp)
	return resp, err
}

// locationGetCreateRequest creates the LocationGet request.
func (client *Client) locationGetCreateRequest(ctx context.Context, location string, extensionTypeName string, _ *ClientLocationGetOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.KubernetesConfiguration/locations/{location}/extensionTypes/{extensionTypeName}"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if location == "" {
		return nil, errors.New("parameter location cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location))
	if extensionTypeName == "" {
		return nil, errors.New("parameter extensionTypeName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{extensionTypeName}", url.PathEscape(extensionTypeName))
	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-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// locationGetHandleResponse handles the LocationGet response.
func (client *Client) locationGetHandleResponse(resp *http.Response) (ClientLocationGetResponse, error) {
	result := ClientLocationGetResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.ExtensionType); err != nil {
		return ClientLocationGetResponse{}, err
	}
	return result, nil
}

// NewLocationListPager - List all Extension Types for the location.
//
// Generated from API version 2024-11-01-preview
//   - location - The name of Azure region.
//   - options - ClientLocationListOptions contains the optional parameters for the Client.NewLocationListPager method.
func (client *Client) NewLocationListPager(location string, options *ClientLocationListOptions) *runtime.Pager[ClientLocationListResponse] {
	return runtime.NewPager(runtime.PagingHandler[ClientLocationListResponse]{
		More: func(page ClientLocationListResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *ClientLocationListResponse) (ClientLocationListResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewLocationListPager")
			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.locationListCreateRequest(ctx, location, options)
			}, nil)
			if err != nil {
				return ClientLocationListResponse{}, err
			}
			return client.locationListHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// locationListCreateRequest creates the LocationList request.
func (client *Client) locationListCreateRequest(ctx context.Context, location string, options *ClientLocationListOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.KubernetesConfiguration/locations/{location}/extensionTypes"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if location == "" {
		return nil, errors.New("parameter location cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location))
	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-preview")
	if options != nil && options.ClusterType != nil {
		reqQP.Set("clusterType", *options.ClusterType)
	}
	if options != nil && options.OfferID != nil {
		reqQP.Set("offerId", *options.OfferID)
	}
	if options != nil && options.PlanID != nil {
		reqQP.Set("planId", *options.PlanID)
	}
	if options != nil && options.PublisherID != nil {
		reqQP.Set("publisherId", *options.PublisherID)
	}
	if options != nil && options.ReleaseTrain != nil {
		reqQP.Set("releaseTrain", *options.ReleaseTrain)
	}
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// locationListHandleResponse handles the LocationList response.
func (client *Client) locationListHandleResponse(resp *http.Response) (ClientLocationListResponse, error) {
	result := ClientLocationListResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.List); err != nil {
		return ClientLocationListResponse{}, err
	}
	return result, nil
}
