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

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

// ScenarioConfigurationsClient contains the methods for the ScenarioConfigurations group.
// Don't use this type directly, use NewScenarioConfigurationsClient() instead.
//
// Generated from API version 2026-05-01-preview
type ScenarioConfigurationsClient struct {
	internal       *arm.Client
	subscriptionID string
}

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

// BeginCreateOrUpdate - Create or update a scenario definition.
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - workspaceName - String that represents a Workspace resource name.
//   - scenarioName - Name of the scenario.
//   - scenarioConfigurationName - Name of the scenario definition.
//   - resource - Resource create parameters.
//   - options - ScenarioConfigurationsClientBeginCreateOrUpdateOptions contains the optional parameters for the ScenarioConfigurationsClient.BeginCreateOrUpdate
//     method.
func (client *ScenarioConfigurationsClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, resource ScenarioConfiguration, options *ScenarioConfigurationsClientBeginCreateOrUpdateOptions) (*runtime.Poller[ScenarioConfigurationsClientCreateOrUpdateResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.createOrUpdate(ctx, resourceGroupName, workspaceName, scenarioName, scenarioConfigurationName, resource, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ScenarioConfigurationsClientCreateOrUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ScenarioConfigurationsClientCreateOrUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// CreateOrUpdate - Create or update a scenario definition.
// If the operation fails it returns an *azcore.ResponseError type.
func (client *ScenarioConfigurationsClient) createOrUpdate(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, resource ScenarioConfiguration, options *ScenarioConfigurationsClientBeginCreateOrUpdateOptions) (*http.Response, error) {
	var err error
	const operationName = "ScenarioConfigurationsClient.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, workspaceName, scenarioName, scenarioConfigurationName, 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 *ScenarioConfigurationsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, resource ScenarioConfiguration, _ *ScenarioConfigurationsClientBeginCreateOrUpdateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Chaos/workspaces/{workspaceName}/scenarios/{scenarioName}/configurations/{scenarioConfigurationName}"
	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 workspaceName == "" {
		return nil, errors.New("parameter workspaceName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName))
	if scenarioName == "" {
		return nil, errors.New("parameter scenarioName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{scenarioName}", url.PathEscape(scenarioName))
	if scenarioConfigurationName == "" {
		return nil, errors.New("parameter scenarioConfigurationName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{scenarioConfigurationName}", url.PathEscape(scenarioConfigurationName))
	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", version20260501Preview)
	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
}

// BeginDelete - Delete a scenario definition.
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - workspaceName - String that represents a Workspace resource name.
//   - scenarioName - Name of the scenario.
//   - scenarioConfigurationName - Name of the scenario definition.
//   - options - ScenarioConfigurationsClientBeginDeleteOptions contains the optional parameters for the ScenarioConfigurationsClient.BeginDelete
//     method.
func (client *ScenarioConfigurationsClient) BeginDelete(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, options *ScenarioConfigurationsClientBeginDeleteOptions) (*runtime.Poller[ScenarioConfigurationsClientDeleteResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.deleteOperation(ctx, resourceGroupName, workspaceName, scenarioName, scenarioConfigurationName, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ScenarioConfigurationsClientDeleteResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ScenarioConfigurationsClientDeleteResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// Delete - Delete a scenario definition.
// If the operation fails it returns an *azcore.ResponseError type.
func (client *ScenarioConfigurationsClient) deleteOperation(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, options *ScenarioConfigurationsClientBeginDeleteOptions) (*http.Response, error) {
	var err error
	const operationName = "ScenarioConfigurationsClient.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, workspaceName, scenarioName, scenarioConfigurationName, 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 *ScenarioConfigurationsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, _ *ScenarioConfigurationsClientBeginDeleteOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Chaos/workspaces/{workspaceName}/scenarios/{scenarioName}/configurations/{scenarioConfigurationName}"
	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 workspaceName == "" {
		return nil, errors.New("parameter workspaceName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName))
	if scenarioName == "" {
		return nil, errors.New("parameter scenarioName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{scenarioName}", url.PathEscape(scenarioName))
	if scenarioConfigurationName == "" {
		return nil, errors.New("parameter scenarioConfigurationName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{scenarioConfigurationName}", url.PathEscape(scenarioConfigurationName))
	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", version20260501Preview)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	return req, nil
}

// BeginExecute - Execute the scenario execution with the given scenario configuration.
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - workspaceName - String that represents a Workspace resource name.
//   - scenarioName - Name of the scenario.
//   - scenarioConfigurationName - Name of the scenario definition.
//   - options - ScenarioConfigurationsClientBeginExecuteOptions contains the optional parameters for the ScenarioConfigurationsClient.BeginExecute
//     method.
func (client *ScenarioConfigurationsClient) BeginExecute(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, options *ScenarioConfigurationsClientBeginExecuteOptions) (*runtime.Poller[ScenarioConfigurationsClientExecuteResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.execute(ctx, resourceGroupName, workspaceName, scenarioName, scenarioConfigurationName, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ScenarioConfigurationsClientExecuteResponse]{
			FinalStateVia: runtime.FinalStateViaLocation,
			Tracer:        client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ScenarioConfigurationsClientExecuteResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// Execute - Execute the scenario execution with the given scenario configuration.
// If the operation fails it returns an *azcore.ResponseError type.
func (client *ScenarioConfigurationsClient) execute(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, options *ScenarioConfigurationsClientBeginExecuteOptions) (*http.Response, error) {
	var err error
	const operationName = "ScenarioConfigurationsClient.BeginExecute"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.executeCreateRequest(ctx, resourceGroupName, workspaceName, scenarioName, scenarioConfigurationName, 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
}

// executeCreateRequest creates the Execute request.
func (client *ScenarioConfigurationsClient) executeCreateRequest(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, _ *ScenarioConfigurationsClientBeginExecuteOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Chaos/workspaces/{workspaceName}/scenarios/{scenarioName}/configurations/{scenarioConfigurationName}/execute"
	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 workspaceName == "" {
		return nil, errors.New("parameter workspaceName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName))
	if scenarioName == "" {
		return nil, errors.New("parameter scenarioName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{scenarioName}", url.PathEscape(scenarioName))
	if scenarioConfigurationName == "" {
		return nil, errors.New("parameter scenarioConfigurationName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{scenarioConfigurationName}", url.PathEscape(scenarioConfigurationName))
	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", version20260501Preview)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	return req, nil
}

// BeginFixResourcePermissions - Fixes resource permissions for the given scenario configuration.
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - workspaceName - String that represents a Workspace resource name.
//   - scenarioName - Name of the scenario.
//   - scenarioConfigurationName - Name of the scenario definition.
//   - options - ScenarioConfigurationsClientBeginFixResourcePermissionsOptions contains the optional parameters for the ScenarioConfigurationsClient.BeginFixResourcePermissions
//     method.
func (client *ScenarioConfigurationsClient) BeginFixResourcePermissions(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, options *ScenarioConfigurationsClientBeginFixResourcePermissionsOptions) (*runtime.Poller[ScenarioConfigurationsClientFixResourcePermissionsResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.fixResourcePermissions(ctx, resourceGroupName, workspaceName, scenarioName, scenarioConfigurationName, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ScenarioConfigurationsClientFixResourcePermissionsResponse]{
			FinalStateVia: runtime.FinalStateViaLocation,
			Tracer:        client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ScenarioConfigurationsClientFixResourcePermissionsResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// FixResourcePermissions - Fixes resource permissions for the given scenario configuration.
// If the operation fails it returns an *azcore.ResponseError type.
func (client *ScenarioConfigurationsClient) fixResourcePermissions(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, options *ScenarioConfigurationsClientBeginFixResourcePermissionsOptions) (*http.Response, error) {
	var err error
	const operationName = "ScenarioConfigurationsClient.BeginFixResourcePermissions"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.fixResourcePermissionsCreateRequest(ctx, resourceGroupName, workspaceName, scenarioName, scenarioConfigurationName, 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
}

// fixResourcePermissionsCreateRequest creates the FixResourcePermissions request.
func (client *ScenarioConfigurationsClient) fixResourcePermissionsCreateRequest(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, options *ScenarioConfigurationsClientBeginFixResourcePermissionsOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Chaos/workspaces/{workspaceName}/scenarios/{scenarioName}/configurations/{scenarioConfigurationName}/fixResourcePermissions"
	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 workspaceName == "" {
		return nil, errors.New("parameter workspaceName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName))
	if scenarioName == "" {
		return nil, errors.New("parameter scenarioName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{scenarioName}", url.PathEscape(scenarioName))
	if scenarioConfigurationName == "" {
		return nil, errors.New("parameter scenarioConfigurationName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{scenarioConfigurationName}", url.PathEscape(scenarioConfigurationName))
	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", version20260501Preview)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	if options != nil && options.Body != nil {
		req.Raw().Header["Content-Type"] = []string{"application/json"}
		if err := runtime.MarshalAsJSON(req, *options.Body); err != nil {
			return nil, err
		}
		return req, nil
	}
	return req, nil
}

// Get - Get a scenario definition.
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - workspaceName - String that represents a Workspace resource name.
//   - scenarioName - Name of the scenario.
//   - scenarioConfigurationName - Name of the scenario definition.
//   - options - ScenarioConfigurationsClientGetOptions contains the optional parameters for the ScenarioConfigurationsClient.Get
//     method.
func (client *ScenarioConfigurationsClient) Get(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, options *ScenarioConfigurationsClientGetOptions) (ScenarioConfigurationsClientGetResponse, error) {
	var err error
	const operationName = "ScenarioConfigurationsClient.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, workspaceName, scenarioName, scenarioConfigurationName, options)
	if err != nil {
		return ScenarioConfigurationsClientGetResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return ScenarioConfigurationsClientGetResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return ScenarioConfigurationsClientGetResponse{}, err
	}
	resp, err := client.getHandleResponse(httpResp)
	return resp, err
}

// getCreateRequest creates the Get request.
func (client *ScenarioConfigurationsClient) getCreateRequest(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, _ *ScenarioConfigurationsClientGetOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Chaos/workspaces/{workspaceName}/scenarios/{scenarioName}/configurations/{scenarioConfigurationName}"
	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 workspaceName == "" {
		return nil, errors.New("parameter workspaceName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName))
	if scenarioName == "" {
		return nil, errors.New("parameter scenarioName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{scenarioName}", url.PathEscape(scenarioName))
	if scenarioConfigurationName == "" {
		return nil, errors.New("parameter scenarioConfigurationName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{scenarioConfigurationName}", url.PathEscape(scenarioConfigurationName))
	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", version20260501Preview)
	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 *ScenarioConfigurationsClient) getHandleResponse(resp *http.Response) (ScenarioConfigurationsClientGetResponse, error) {
	result := ScenarioConfigurationsClientGetResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.ScenarioConfiguration); err != nil {
		return ScenarioConfigurationsClientGetResponse{}, err
	}
	return result, nil
}

// NewListAllPager - Get a list of scenario definitions.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - workspaceName - String that represents a Workspace resource name.
//   - scenarioName - Name of the scenario.
//   - options - ScenarioConfigurationsClientListAllOptions contains the optional parameters for the ScenarioConfigurationsClient.NewListAllPager
//     method.
func (client *ScenarioConfigurationsClient) NewListAllPager(resourceGroupName string, workspaceName string, scenarioName string, options *ScenarioConfigurationsClientListAllOptions) *runtime.Pager[ScenarioConfigurationsClientListAllResponse] {
	return runtime.NewPager(runtime.PagingHandler[ScenarioConfigurationsClientListAllResponse]{
		More: func(page ScenarioConfigurationsClientListAllResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *ScenarioConfigurationsClientListAllResponse) (ScenarioConfigurationsClientListAllResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ScenarioConfigurationsClient.NewListAllPager")
			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.listAllCreateRequest(ctx, resourceGroupName, workspaceName, scenarioName, options)
			}, nil)
			if err != nil {
				return ScenarioConfigurationsClientListAllResponse{}, err
			}
			return client.listAllHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listAllCreateRequest creates the ListAll request.
func (client *ScenarioConfigurationsClient) listAllCreateRequest(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, _ *ScenarioConfigurationsClientListAllOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Chaos/workspaces/{workspaceName}/scenarios/{scenarioName}/configurations"
	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 workspaceName == "" {
		return nil, errors.New("parameter workspaceName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName))
	if scenarioName == "" {
		return nil, errors.New("parameter scenarioName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{scenarioName}", url.PathEscape(scenarioName))
	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", version20260501Preview)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listAllHandleResponse handles the ListAll response.
func (client *ScenarioConfigurationsClient) listAllHandleResponse(resp *http.Response) (ScenarioConfigurationsClientListAllResponse, error) {
	result := ScenarioConfigurationsClientListAllResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.ScenarioConfigurationListResult); err != nil {
		return ScenarioConfigurationsClientListAllResponse{}, err
	}
	return result, nil
}

// BeginValidate - Validate the given scenario configuration.
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - workspaceName - String that represents a Workspace resource name.
//   - scenarioName - Name of the scenario.
//   - scenarioConfigurationName - Name of the scenario definition.
//   - options - ScenarioConfigurationsClientBeginValidateOptions contains the optional parameters for the ScenarioConfigurationsClient.BeginValidate
//     method.
func (client *ScenarioConfigurationsClient) BeginValidate(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, options *ScenarioConfigurationsClientBeginValidateOptions) (*runtime.Poller[ScenarioConfigurationsClientValidateResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.validate(ctx, resourceGroupName, workspaceName, scenarioName, scenarioConfigurationName, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ScenarioConfigurationsClientValidateResponse]{
			FinalStateVia: runtime.FinalStateViaLocation,
			Tracer:        client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ScenarioConfigurationsClientValidateResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// Validate - Validate the given scenario configuration.
// If the operation fails it returns an *azcore.ResponseError type.
func (client *ScenarioConfigurationsClient) validate(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, options *ScenarioConfigurationsClientBeginValidateOptions) (*http.Response, error) {
	var err error
	const operationName = "ScenarioConfigurationsClient.BeginValidate"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.validateCreateRequest(ctx, resourceGroupName, workspaceName, scenarioName, scenarioConfigurationName, 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
}

// validateCreateRequest creates the Validate request.
func (client *ScenarioConfigurationsClient) validateCreateRequest(ctx context.Context, resourceGroupName string, workspaceName string, scenarioName string, scenarioConfigurationName string, _ *ScenarioConfigurationsClientBeginValidateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Chaos/workspaces/{workspaceName}/scenarios/{scenarioName}/configurations/{scenarioConfigurationName}/validate"
	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 workspaceName == "" {
		return nil, errors.New("parameter workspaceName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName))
	if scenarioName == "" {
		return nil, errors.New("parameter scenarioName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{scenarioName}", url.PathEscape(scenarioName))
	if scenarioConfigurationName == "" {
		return nil, errors.New("parameter scenarioConfigurationName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{scenarioConfigurationName}", url.PathEscape(scenarioConfigurationName))
	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", version20260501Preview)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	return req, nil
}
