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

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

// SolutionTemplatesClient contains the methods for the SolutionTemplates group.
// Don't use this type directly, use NewSolutionTemplatesClient() instead.
//
// Generated from API version 2025-06-01
type SolutionTemplatesClient struct {
	internal       *arm.Client
	subscriptionID string
}

// NewSolutionTemplatesClient creates a new instance of SolutionTemplatesClient 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 - Contains optional client configuration. Pass nil to accept the default values.
func NewSolutionTemplatesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*SolutionTemplatesClient, error) {
	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
	if err != nil {
		return nil, err
	}
	client := &SolutionTemplatesClient{
		subscriptionID: subscriptionID,
		internal:       cl,
	}
	return client, nil
}

// BeginCreateOrUpdate - Create or update a Solution Template Resource
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - solutionTemplateName - The name of the SolutionTemplate
//   - resource - Resource create parameters.
//   - options - SolutionTemplatesClientBeginCreateOrUpdateOptions contains the optional parameters for the SolutionTemplatesClient.BeginCreateOrUpdate
//     method.
func (client *SolutionTemplatesClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, solutionTemplateName string, resource SolutionTemplate, options *SolutionTemplatesClientBeginCreateOrUpdateOptions) (*runtime.Poller[SolutionTemplatesClientCreateOrUpdateResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.createOrUpdate(ctx, resourceGroupName, solutionTemplateName, resource, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SolutionTemplatesClientCreateOrUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[SolutionTemplatesClientCreateOrUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// CreateOrUpdate - Create or update a Solution Template Resource
// If the operation fails it returns an *azcore.ResponseError type.
func (client *SolutionTemplatesClient) createOrUpdate(ctx context.Context, resourceGroupName string, solutionTemplateName string, resource SolutionTemplate, options *SolutionTemplatesClientBeginCreateOrUpdateOptions) (*http.Response, error) {
	var err error
	const operationName = "SolutionTemplatesClient.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, solutionTemplateName, 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
}

// createOrUpdateCreateRequest creates the CreateOrUpdate request.
func (client *SolutionTemplatesClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, solutionTemplateName string, resource SolutionTemplate, _ *SolutionTemplatesClientBeginCreateOrUpdateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Edge/solutionTemplates/{solutionTemplateName}"
	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 solutionTemplateName == "" {
		return nil, errors.New("parameter solutionTemplateName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{solutionTemplateName}", url.PathEscape(solutionTemplateName))
	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", version20250601)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, resource); err != nil {
		return nil, err
	}
	return req, nil
}

// BeginCreateVersion - Create a Solution Template Version Resource
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - solutionTemplateName - The name of the SolutionTemplate
//   - body - The content of the action request
//   - options - SolutionTemplatesClientBeginCreateVersionOptions contains the optional parameters for the SolutionTemplatesClient.BeginCreateVersion
//     method.
func (client *SolutionTemplatesClient) BeginCreateVersion(ctx context.Context, resourceGroupName string, solutionTemplateName string, body SolutionTemplateVersionWithUpdateType, options *SolutionTemplatesClientBeginCreateVersionOptions) (*runtime.Poller[SolutionTemplatesClientCreateVersionResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.createVersion(ctx, resourceGroupName, solutionTemplateName, body, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SolutionTemplatesClientCreateVersionResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[SolutionTemplatesClientCreateVersionResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// CreateVersion - Create a Solution Template Version Resource
// If the operation fails it returns an *azcore.ResponseError type.
func (client *SolutionTemplatesClient) createVersion(ctx context.Context, resourceGroupName string, solutionTemplateName string, body SolutionTemplateVersionWithUpdateType, options *SolutionTemplatesClientBeginCreateVersionOptions) (*http.Response, error) {
	var err error
	const operationName = "SolutionTemplatesClient.BeginCreateVersion"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.createVersionCreateRequest(ctx, resourceGroupName, solutionTemplateName, body, 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
}

// createVersionCreateRequest creates the CreateVersion request.
func (client *SolutionTemplatesClient) createVersionCreateRequest(ctx context.Context, resourceGroupName string, solutionTemplateName string, body SolutionTemplateVersionWithUpdateType, _ *SolutionTemplatesClientBeginCreateVersionOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Edge/solutionTemplates/{solutionTemplateName}/createVersion"
	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 solutionTemplateName == "" {
		return nil, errors.New("parameter solutionTemplateName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{solutionTemplateName}", url.PathEscape(solutionTemplateName))
	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", version20250601)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, body); err != nil {
		return nil, err
	}
	return req, nil
}

// BeginDelete - Delete a Solution Template Resource
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - solutionTemplateName - The name of the SolutionTemplate
//   - options - SolutionTemplatesClientBeginDeleteOptions contains the optional parameters for the SolutionTemplatesClient.BeginDelete
//     method.
func (client *SolutionTemplatesClient) BeginDelete(ctx context.Context, resourceGroupName string, solutionTemplateName string, options *SolutionTemplatesClientBeginDeleteOptions) (*runtime.Poller[SolutionTemplatesClientDeleteResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.deleteOperation(ctx, resourceGroupName, solutionTemplateName, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SolutionTemplatesClientDeleteResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[SolutionTemplatesClientDeleteResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// Delete - Delete a Solution Template Resource
// If the operation fails it returns an *azcore.ResponseError type.
func (client *SolutionTemplatesClient) deleteOperation(ctx context.Context, resourceGroupName string, solutionTemplateName string, options *SolutionTemplatesClientBeginDeleteOptions) (*http.Response, error) {
	var err error
	const operationName = "SolutionTemplatesClient.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, solutionTemplateName, 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 *SolutionTemplatesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, solutionTemplateName string, _ *SolutionTemplatesClientBeginDeleteOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Edge/solutionTemplates/{solutionTemplateName}"
	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 solutionTemplateName == "" {
		return nil, errors.New("parameter solutionTemplateName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{solutionTemplateName}", url.PathEscape(solutionTemplateName))
	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", version20250601)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	return req, nil
}

// Get - Get a Solution Template Resource
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - solutionTemplateName - The name of the SolutionTemplate
//   - options - SolutionTemplatesClientGetOptions contains the optional parameters for the SolutionTemplatesClient.Get method.
func (client *SolutionTemplatesClient) Get(ctx context.Context, resourceGroupName string, solutionTemplateName string, options *SolutionTemplatesClientGetOptions) (SolutionTemplatesClientGetResponse, error) {
	var err error
	const operationName = "SolutionTemplatesClient.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, solutionTemplateName, options)
	if err != nil {
		return SolutionTemplatesClientGetResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return SolutionTemplatesClientGetResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return SolutionTemplatesClientGetResponse{}, err
	}
	resp, err := client.getHandleResponse(httpResp)
	return resp, err
}

// getCreateRequest creates the Get request.
func (client *SolutionTemplatesClient) getCreateRequest(ctx context.Context, resourceGroupName string, solutionTemplateName string, _ *SolutionTemplatesClientGetOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Edge/solutionTemplates/{solutionTemplateName}"
	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 solutionTemplateName == "" {
		return nil, errors.New("parameter solutionTemplateName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{solutionTemplateName}", url.PathEscape(solutionTemplateName))
	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", version20250601)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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

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

// listByResourceGroupCreateRequest creates the ListByResourceGroup request.
func (client *SolutionTemplatesClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, _ *SolutionTemplatesClientListByResourceGroupOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Edge/solutionTemplates"
	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", version20250601)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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

// NewListBySubscriptionPager - List by subscription
//   - options - SolutionTemplatesClientListBySubscriptionOptions contains the optional parameters for the SolutionTemplatesClient.NewListBySubscriptionPager
//     method.
func (client *SolutionTemplatesClient) NewListBySubscriptionPager(options *SolutionTemplatesClientListBySubscriptionOptions) *runtime.Pager[SolutionTemplatesClientListBySubscriptionResponse] {
	return runtime.NewPager(runtime.PagingHandler[SolutionTemplatesClientListBySubscriptionResponse]{
		More: func(page SolutionTemplatesClientListBySubscriptionResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *SolutionTemplatesClientListBySubscriptionResponse) (SolutionTemplatesClientListBySubscriptionResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SolutionTemplatesClient.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 SolutionTemplatesClientListBySubscriptionResponse{}, err
			}
			return client.listBySubscriptionHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listBySubscriptionCreateRequest creates the ListBySubscription request.
func (client *SolutionTemplatesClient) listBySubscriptionCreateRequest(ctx context.Context, _ *SolutionTemplatesClientListBySubscriptionOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Edge/solutionTemplates"
	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", version20250601)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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

// BeginRemoveVersion - Remove Solution Template Version Resource
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - solutionTemplateName - The name of the SolutionTemplate
//   - body - The content of the action request
//   - options - SolutionTemplatesClientBeginRemoveVersionOptions contains the optional parameters for the SolutionTemplatesClient.BeginRemoveVersion
//     method.
func (client *SolutionTemplatesClient) BeginRemoveVersion(ctx context.Context, resourceGroupName string, solutionTemplateName string, body VersionParameter, options *SolutionTemplatesClientBeginRemoveVersionOptions) (*runtime.Poller[SolutionTemplatesClientRemoveVersionResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.removeVersion(ctx, resourceGroupName, solutionTemplateName, body, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SolutionTemplatesClientRemoveVersionResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[SolutionTemplatesClientRemoveVersionResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// RemoveVersion - Remove Solution Template Version Resource
// If the operation fails it returns an *azcore.ResponseError type.
func (client *SolutionTemplatesClient) removeVersion(ctx context.Context, resourceGroupName string, solutionTemplateName string, body VersionParameter, options *SolutionTemplatesClientBeginRemoveVersionOptions) (*http.Response, error) {
	var err error
	const operationName = "SolutionTemplatesClient.BeginRemoveVersion"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.removeVersionCreateRequest(ctx, resourceGroupName, solutionTemplateName, body, 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) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// removeVersionCreateRequest creates the RemoveVersion request.
func (client *SolutionTemplatesClient) removeVersionCreateRequest(ctx context.Context, resourceGroupName string, solutionTemplateName string, body VersionParameter, _ *SolutionTemplatesClientBeginRemoveVersionOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Edge/solutionTemplates/{solutionTemplateName}/removeVersion"
	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 solutionTemplateName == "" {
		return nil, errors.New("parameter solutionTemplateName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{solutionTemplateName}", url.PathEscape(solutionTemplateName))
	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", version20250601)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, body); err != nil {
		return nil, err
	}
	return req, nil
}

// Update - update a Solution Template Resource
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - solutionTemplateName - The name of the SolutionTemplate
//   - properties - The resource properties to be updated.
//   - options - SolutionTemplatesClientUpdateOptions contains the optional parameters for the SolutionTemplatesClient.Update
//     method.
func (client *SolutionTemplatesClient) Update(ctx context.Context, resourceGroupName string, solutionTemplateName string, properties SolutionTemplateUpdate, options *SolutionTemplatesClientUpdateOptions) (SolutionTemplatesClientUpdateResponse, error) {
	var err error
	const operationName = "SolutionTemplatesClient.Update"
	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, solutionTemplateName, properties, options)
	if err != nil {
		return SolutionTemplatesClientUpdateResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return SolutionTemplatesClientUpdateResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return SolutionTemplatesClientUpdateResponse{}, err
	}
	resp, err := client.updateHandleResponse(httpResp)
	return resp, err
}

// updateCreateRequest creates the Update request.
func (client *SolutionTemplatesClient) updateCreateRequest(ctx context.Context, resourceGroupName string, solutionTemplateName string, properties SolutionTemplateUpdate, _ *SolutionTemplatesClientUpdateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Edge/solutionTemplates/{solutionTemplateName}"
	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 solutionTemplateName == "" {
		return nil, errors.New("parameter solutionTemplateName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{solutionTemplateName}", url.PathEscape(solutionTemplateName))
	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", version20250601)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, properties); err != nil {
		return nil, err
	}
	return req, nil
}

// updateHandleResponse handles the Update response.
func (client *SolutionTemplatesClient) updateHandleResponse(resp *http.Response) (SolutionTemplatesClientUpdateResponse, error) {
	result := SolutionTemplatesClientUpdateResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.SolutionTemplate); err != nil {
		return SolutionTemplatesClientUpdateResponse{}, err
	}
	return result, nil
}
