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

import (
	"context"
	"errors"
	"fmt"
	azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/redisenterprise/armredisenterprise/v2"
	"net/http"
	"net/url"
	"reflect"
	"regexp"
)

// DatabasesServer is a fake server for instances of the armredisenterprise.DatabasesClient type.
type DatabasesServer struct {
	// BeginCreate is the fake for method DatabasesClient.BeginCreate
	// HTTP status codes to indicate success: http.StatusOK, http.StatusCreated
	BeginCreate func(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, parameters armredisenterprise.Database, options *armredisenterprise.DatabasesClientBeginCreateOptions) (resp azfake.PollerResponder[armredisenterprise.DatabasesClientCreateResponse], errResp azfake.ErrorResponder)

	// BeginDelete is the fake for method DatabasesClient.BeginDelete
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginDelete func(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, options *armredisenterprise.DatabasesClientBeginDeleteOptions) (resp azfake.PollerResponder[armredisenterprise.DatabasesClientDeleteResponse], errResp azfake.ErrorResponder)

	// BeginExport is the fake for method DatabasesClient.BeginExport
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginExport func(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, parameters armredisenterprise.ExportClusterParameters, options *armredisenterprise.DatabasesClientBeginExportOptions) (resp azfake.PollerResponder[armredisenterprise.DatabasesClientExportResponse], errResp azfake.ErrorResponder)

	// BeginFlush is the fake for method DatabasesClient.BeginFlush
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginFlush func(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, options *armredisenterprise.DatabasesClientBeginFlushOptions) (resp azfake.PollerResponder[armredisenterprise.DatabasesClientFlushResponse], errResp azfake.ErrorResponder)

	// BeginForceLinkToReplicationGroup is the fake for method DatabasesClient.BeginForceLinkToReplicationGroup
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginForceLinkToReplicationGroup func(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, parameters armredisenterprise.ForceLinkParameters, options *armredisenterprise.DatabasesClientBeginForceLinkToReplicationGroupOptions) (resp azfake.PollerResponder[armredisenterprise.DatabasesClientForceLinkToReplicationGroupResponse], errResp azfake.ErrorResponder)

	// BeginForceUnlink is the fake for method DatabasesClient.BeginForceUnlink
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginForceUnlink func(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, parameters armredisenterprise.ForceUnlinkParameters, options *armredisenterprise.DatabasesClientBeginForceUnlinkOptions) (resp azfake.PollerResponder[armredisenterprise.DatabasesClientForceUnlinkResponse], errResp azfake.ErrorResponder)

	// Get is the fake for method DatabasesClient.Get
	// HTTP status codes to indicate success: http.StatusOK
	Get func(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, options *armredisenterprise.DatabasesClientGetOptions) (resp azfake.Responder[armredisenterprise.DatabasesClientGetResponse], errResp azfake.ErrorResponder)

	// BeginImport is the fake for method DatabasesClient.BeginImport
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginImport func(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, parameters armredisenterprise.ImportClusterParameters, options *armredisenterprise.DatabasesClientBeginImportOptions) (resp azfake.PollerResponder[armredisenterprise.DatabasesClientImportResponse], errResp azfake.ErrorResponder)

	// NewListByClusterPager is the fake for method DatabasesClient.NewListByClusterPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListByClusterPager func(resourceGroupName string, clusterName string, options *armredisenterprise.DatabasesClientListByClusterOptions) (resp azfake.PagerResponder[armredisenterprise.DatabasesClientListByClusterResponse])

	// ListKeys is the fake for method DatabasesClient.ListKeys
	// HTTP status codes to indicate success: http.StatusOK
	ListKeys func(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, options *armredisenterprise.DatabasesClientListKeysOptions) (resp azfake.Responder[armredisenterprise.DatabasesClientListKeysResponse], errResp azfake.ErrorResponder)

	// BeginRegenerateKey is the fake for method DatabasesClient.BeginRegenerateKey
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginRegenerateKey func(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, parameters armredisenterprise.RegenerateKeyParameters, options *armredisenterprise.DatabasesClientBeginRegenerateKeyOptions) (resp azfake.PollerResponder[armredisenterprise.DatabasesClientRegenerateKeyResponse], errResp azfake.ErrorResponder)

	// BeginUpdate is the fake for method DatabasesClient.BeginUpdate
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginUpdate func(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, parameters armredisenterprise.DatabaseUpdate, options *armredisenterprise.DatabasesClientBeginUpdateOptions) (resp azfake.PollerResponder[armredisenterprise.DatabasesClientUpdateResponse], errResp azfake.ErrorResponder)

	// BeginUpgradeDBRedisVersion is the fake for method DatabasesClient.BeginUpgradeDBRedisVersion
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginUpgradeDBRedisVersion func(ctx context.Context, resourceGroupName string, clusterName string, databaseName string, options *armredisenterprise.DatabasesClientBeginUpgradeDBRedisVersionOptions) (resp azfake.PollerResponder[armredisenterprise.DatabasesClientUpgradeDBRedisVersionResponse], errResp azfake.ErrorResponder)
}

// NewDatabasesServerTransport creates a new instance of DatabasesServerTransport with the provided implementation.
// The returned DatabasesServerTransport instance is connected to an instance of armredisenterprise.DatabasesClient via the
// azcore.ClientOptions.Transporter field in the client's constructor parameters.
func NewDatabasesServerTransport(srv *DatabasesServer) *DatabasesServerTransport {
	return &DatabasesServerTransport{
		srv:                              srv,
		beginCreate:                      newTracker[azfake.PollerResponder[armredisenterprise.DatabasesClientCreateResponse]](),
		beginDelete:                      newTracker[azfake.PollerResponder[armredisenterprise.DatabasesClientDeleteResponse]](),
		beginExport:                      newTracker[azfake.PollerResponder[armredisenterprise.DatabasesClientExportResponse]](),
		beginFlush:                       newTracker[azfake.PollerResponder[armredisenterprise.DatabasesClientFlushResponse]](),
		beginForceLinkToReplicationGroup: newTracker[azfake.PollerResponder[armredisenterprise.DatabasesClientForceLinkToReplicationGroupResponse]](),
		beginForceUnlink:                 newTracker[azfake.PollerResponder[armredisenterprise.DatabasesClientForceUnlinkResponse]](),
		beginImport:                      newTracker[azfake.PollerResponder[armredisenterprise.DatabasesClientImportResponse]](),
		newListByClusterPager:            newTracker[azfake.PagerResponder[armredisenterprise.DatabasesClientListByClusterResponse]](),
		beginRegenerateKey:               newTracker[azfake.PollerResponder[armredisenterprise.DatabasesClientRegenerateKeyResponse]](),
		beginUpdate:                      newTracker[azfake.PollerResponder[armredisenterprise.DatabasesClientUpdateResponse]](),
		beginUpgradeDBRedisVersion:       newTracker[azfake.PollerResponder[armredisenterprise.DatabasesClientUpgradeDBRedisVersionResponse]](),
	}
}

// DatabasesServerTransport connects instances of armredisenterprise.DatabasesClient to instances of DatabasesServer.
// Don't use this type directly, use NewDatabasesServerTransport instead.
type DatabasesServerTransport struct {
	srv                              *DatabasesServer
	beginCreate                      *tracker[azfake.PollerResponder[armredisenterprise.DatabasesClientCreateResponse]]
	beginDelete                      *tracker[azfake.PollerResponder[armredisenterprise.DatabasesClientDeleteResponse]]
	beginExport                      *tracker[azfake.PollerResponder[armredisenterprise.DatabasesClientExportResponse]]
	beginFlush                       *tracker[azfake.PollerResponder[armredisenterprise.DatabasesClientFlushResponse]]
	beginForceLinkToReplicationGroup *tracker[azfake.PollerResponder[armredisenterprise.DatabasesClientForceLinkToReplicationGroupResponse]]
	beginForceUnlink                 *tracker[azfake.PollerResponder[armredisenterprise.DatabasesClientForceUnlinkResponse]]
	beginImport                      *tracker[azfake.PollerResponder[armredisenterprise.DatabasesClientImportResponse]]
	newListByClusterPager            *tracker[azfake.PagerResponder[armredisenterprise.DatabasesClientListByClusterResponse]]
	beginRegenerateKey               *tracker[azfake.PollerResponder[armredisenterprise.DatabasesClientRegenerateKeyResponse]]
	beginUpdate                      *tracker[azfake.PollerResponder[armredisenterprise.DatabasesClientUpdateResponse]]
	beginUpgradeDBRedisVersion       *tracker[azfake.PollerResponder[armredisenterprise.DatabasesClientUpgradeDBRedisVersionResponse]]
}

// Do implements the policy.Transporter interface for DatabasesServerTransport.
func (d *DatabasesServerTransport) Do(req *http.Request) (*http.Response, error) {
	rawMethod := req.Context().Value(runtime.CtxAPINameKey{})
	method, ok := rawMethod.(string)
	if !ok {
		return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")}
	}

	return d.dispatchToMethodFake(req, method)
}

func (d *DatabasesServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) {
	resultChan := make(chan result)
	defer close(resultChan)

	go func() {
		var intercepted bool
		var res result
		if databasesServerTransportInterceptor != nil {
			res.resp, res.err, intercepted = databasesServerTransportInterceptor.Do(req)
		}
		if !intercepted {
			switch method {
			case "DatabasesClient.BeginCreate":
				res.resp, res.err = d.dispatchBeginCreate(req)
			case "DatabasesClient.BeginDelete":
				res.resp, res.err = d.dispatchBeginDelete(req)
			case "DatabasesClient.BeginExport":
				res.resp, res.err = d.dispatchBeginExport(req)
			case "DatabasesClient.BeginFlush":
				res.resp, res.err = d.dispatchBeginFlush(req)
			case "DatabasesClient.BeginForceLinkToReplicationGroup":
				res.resp, res.err = d.dispatchBeginForceLinkToReplicationGroup(req)
			case "DatabasesClient.BeginForceUnlink":
				res.resp, res.err = d.dispatchBeginForceUnlink(req)
			case "DatabasesClient.Get":
				res.resp, res.err = d.dispatchGet(req)
			case "DatabasesClient.BeginImport":
				res.resp, res.err = d.dispatchBeginImport(req)
			case "DatabasesClient.NewListByClusterPager":
				res.resp, res.err = d.dispatchNewListByClusterPager(req)
			case "DatabasesClient.ListKeys":
				res.resp, res.err = d.dispatchListKeys(req)
			case "DatabasesClient.BeginRegenerateKey":
				res.resp, res.err = d.dispatchBeginRegenerateKey(req)
			case "DatabasesClient.BeginUpdate":
				res.resp, res.err = d.dispatchBeginUpdate(req)
			case "DatabasesClient.BeginUpgradeDBRedisVersion":
				res.resp, res.err = d.dispatchBeginUpgradeDBRedisVersion(req)
			default:
				res.err = fmt.Errorf("unhandled API %s", method)
			}

		}
		select {
		case resultChan <- res:
		case <-req.Context().Done():
		}
	}()

	select {
	case <-req.Context().Done():
		return nil, req.Context().Err()
	case res := <-resultChan:
		return res.resp, res.err
	}
}

func (d *DatabasesServerTransport) dispatchBeginCreate(req *http.Request) (*http.Response, error) {
	if d.srv.BeginCreate == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginCreate not implemented")}
	}
	beginCreate := d.beginCreate.get(req)
	if beginCreate == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Cache/redisEnterprise/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/databases/(?P<databaseName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 4 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		body, err := server.UnmarshalRequestAsJSON[armredisenterprise.Database](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
		if err != nil {
			return nil, err
		}
		databaseNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("databaseName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginCreate(req.Context(), resourceGroupNameParam, clusterNameParam, databaseNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginCreate = &respr
		d.beginCreate.add(req, beginCreate)
	}

	resp, err := server.PollerResponderNext(beginCreate, req)
	if err != nil {
		return nil, err
	}

	if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) {
		d.beginCreate.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginCreate) {
		d.beginCreate.remove(req)
	}

	return resp, nil
}

func (d *DatabasesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) {
	if d.srv.BeginDelete == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")}
	}
	beginDelete := d.beginDelete.get(req)
	if beginDelete == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Cache/redisEnterprise/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/databases/(?P<databaseName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 4 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
		if err != nil {
			return nil, err
		}
		databaseNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("databaseName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginDelete(req.Context(), resourceGroupNameParam, clusterNameParam, databaseNameParam, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginDelete = &respr
		d.beginDelete.add(req, beginDelete)
	}

	resp, err := server.PollerResponderNext(beginDelete, req)
	if err != nil {
		return nil, err
	}

	if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		d.beginDelete.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginDelete) {
		d.beginDelete.remove(req)
	}

	return resp, nil
}

func (d *DatabasesServerTransport) dispatchBeginExport(req *http.Request) (*http.Response, error) {
	if d.srv.BeginExport == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginExport not implemented")}
	}
	beginExport := d.beginExport.get(req)
	if beginExport == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Cache/redisEnterprise/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/databases/(?P<databaseName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/export`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 4 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		body, err := server.UnmarshalRequestAsJSON[armredisenterprise.ExportClusterParameters](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
		if err != nil {
			return nil, err
		}
		databaseNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("databaseName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginExport(req.Context(), resourceGroupNameParam, clusterNameParam, databaseNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginExport = &respr
		d.beginExport.add(req, beginExport)
	}

	resp, err := server.PollerResponderNext(beginExport, req)
	if err != nil {
		return nil, err
	}

	if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		d.beginExport.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginExport) {
		d.beginExport.remove(req)
	}

	return resp, nil
}

func (d *DatabasesServerTransport) dispatchBeginFlush(req *http.Request) (*http.Response, error) {
	if d.srv.BeginFlush == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginFlush not implemented")}
	}
	beginFlush := d.beginFlush.get(req)
	if beginFlush == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Cache/redisEnterprise/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/databases/(?P<databaseName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/flush`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 4 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		body, err := server.UnmarshalRequestAsJSON[armredisenterprise.FlushParameters](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
		if err != nil {
			return nil, err
		}
		databaseNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("databaseName")])
		if err != nil {
			return nil, err
		}
		var options *armredisenterprise.DatabasesClientBeginFlushOptions
		if !reflect.ValueOf(body).IsZero() {
			options = &armredisenterprise.DatabasesClientBeginFlushOptions{
				Parameters: &body,
			}
		}
		respr, errRespr := d.srv.BeginFlush(req.Context(), resourceGroupNameParam, clusterNameParam, databaseNameParam, options)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginFlush = &respr
		d.beginFlush.add(req, beginFlush)
	}

	resp, err := server.PollerResponderNext(beginFlush, req)
	if err != nil {
		return nil, err
	}

	if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		d.beginFlush.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginFlush) {
		d.beginFlush.remove(req)
	}

	return resp, nil
}

func (d *DatabasesServerTransport) dispatchBeginForceLinkToReplicationGroup(req *http.Request) (*http.Response, error) {
	if d.srv.BeginForceLinkToReplicationGroup == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginForceLinkToReplicationGroup not implemented")}
	}
	beginForceLinkToReplicationGroup := d.beginForceLinkToReplicationGroup.get(req)
	if beginForceLinkToReplicationGroup == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Cache/redisEnterprise/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/databases/(?P<databaseName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/forceLinkToReplicationGroup`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 4 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		body, err := server.UnmarshalRequestAsJSON[armredisenterprise.ForceLinkParameters](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
		if err != nil {
			return nil, err
		}
		databaseNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("databaseName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginForceLinkToReplicationGroup(req.Context(), resourceGroupNameParam, clusterNameParam, databaseNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginForceLinkToReplicationGroup = &respr
		d.beginForceLinkToReplicationGroup.add(req, beginForceLinkToReplicationGroup)
	}

	resp, err := server.PollerResponderNext(beginForceLinkToReplicationGroup, req)
	if err != nil {
		return nil, err
	}

	if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		d.beginForceLinkToReplicationGroup.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginForceLinkToReplicationGroup) {
		d.beginForceLinkToReplicationGroup.remove(req)
	}

	return resp, nil
}

func (d *DatabasesServerTransport) dispatchBeginForceUnlink(req *http.Request) (*http.Response, error) {
	if d.srv.BeginForceUnlink == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginForceUnlink not implemented")}
	}
	beginForceUnlink := d.beginForceUnlink.get(req)
	if beginForceUnlink == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Cache/redisEnterprise/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/databases/(?P<databaseName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/forceUnlink`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 4 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		body, err := server.UnmarshalRequestAsJSON[armredisenterprise.ForceUnlinkParameters](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
		if err != nil {
			return nil, err
		}
		databaseNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("databaseName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginForceUnlink(req.Context(), resourceGroupNameParam, clusterNameParam, databaseNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginForceUnlink = &respr
		d.beginForceUnlink.add(req, beginForceUnlink)
	}

	resp, err := server.PollerResponderNext(beginForceUnlink, req)
	if err != nil {
		return nil, err
	}

	if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		d.beginForceUnlink.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginForceUnlink) {
		d.beginForceUnlink.remove(req)
	}

	return resp, nil
}

func (d *DatabasesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) {
	if d.srv.Get == nil {
		return nil, &nonRetriableError{errors.New("fake for method Get not implemented")}
	}
	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Cache/redisEnterprise/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/databases/(?P<databaseName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if matches == nil || len(matches) < 4 {
		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
	}
	resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
	if err != nil {
		return nil, err
	}
	clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
	if err != nil {
		return nil, err
	}
	databaseNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("databaseName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameParam, clusterNameParam, databaseNameParam, nil)
	if respErr := server.GetError(errRespr, req); respErr != nil {
		return nil, respErr
	}
	respContent := server.GetResponseContent(respr)
	if !contains([]int{http.StatusOK}, respContent.HTTPStatus) {
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)}
	}
	resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).Database, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (d *DatabasesServerTransport) dispatchBeginImport(req *http.Request) (*http.Response, error) {
	if d.srv.BeginImport == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginImport not implemented")}
	}
	beginImport := d.beginImport.get(req)
	if beginImport == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Cache/redisEnterprise/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/databases/(?P<databaseName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/import`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 4 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		body, err := server.UnmarshalRequestAsJSON[armredisenterprise.ImportClusterParameters](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
		if err != nil {
			return nil, err
		}
		databaseNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("databaseName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginImport(req.Context(), resourceGroupNameParam, clusterNameParam, databaseNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginImport = &respr
		d.beginImport.add(req, beginImport)
	}

	resp, err := server.PollerResponderNext(beginImport, req)
	if err != nil {
		return nil, err
	}

	if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		d.beginImport.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginImport) {
		d.beginImport.remove(req)
	}

	return resp, nil
}

func (d *DatabasesServerTransport) dispatchNewListByClusterPager(req *http.Request) (*http.Response, error) {
	if d.srv.NewListByClusterPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListByClusterPager not implemented")}
	}
	newListByClusterPager := d.newListByClusterPager.get(req)
	if newListByClusterPager == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Cache/redisEnterprise/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/databases`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 3 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
		if err != nil {
			return nil, err
		}
		resp := d.srv.NewListByClusterPager(resourceGroupNameParam, clusterNameParam, nil)
		newListByClusterPager = &resp
		d.newListByClusterPager.add(req, newListByClusterPager)
		server.PagerResponderInjectNextLinks(newListByClusterPager, req, func(page *armredisenterprise.DatabasesClientListByClusterResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListByClusterPager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		d.newListByClusterPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListByClusterPager) {
		d.newListByClusterPager.remove(req)
	}
	return resp, nil
}

func (d *DatabasesServerTransport) dispatchListKeys(req *http.Request) (*http.Response, error) {
	if d.srv.ListKeys == nil {
		return nil, &nonRetriableError{errors.New("fake for method ListKeys not implemented")}
	}
	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Cache/redisEnterprise/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/databases/(?P<databaseName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/listKeys`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if matches == nil || len(matches) < 4 {
		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
	}
	resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
	if err != nil {
		return nil, err
	}
	clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
	if err != nil {
		return nil, err
	}
	databaseNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("databaseName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := d.srv.ListKeys(req.Context(), resourceGroupNameParam, clusterNameParam, databaseNameParam, nil)
	if respErr := server.GetError(errRespr, req); respErr != nil {
		return nil, respErr
	}
	respContent := server.GetResponseContent(respr)
	if !contains([]int{http.StatusOK}, respContent.HTTPStatus) {
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)}
	}
	resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).AccessKeys, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (d *DatabasesServerTransport) dispatchBeginRegenerateKey(req *http.Request) (*http.Response, error) {
	if d.srv.BeginRegenerateKey == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginRegenerateKey not implemented")}
	}
	beginRegenerateKey := d.beginRegenerateKey.get(req)
	if beginRegenerateKey == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Cache/redisEnterprise/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/databases/(?P<databaseName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/regenerateKey`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 4 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		body, err := server.UnmarshalRequestAsJSON[armredisenterprise.RegenerateKeyParameters](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
		if err != nil {
			return nil, err
		}
		databaseNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("databaseName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginRegenerateKey(req.Context(), resourceGroupNameParam, clusterNameParam, databaseNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginRegenerateKey = &respr
		d.beginRegenerateKey.add(req, beginRegenerateKey)
	}

	resp, err := server.PollerResponderNext(beginRegenerateKey, req)
	if err != nil {
		return nil, err
	}

	if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) {
		d.beginRegenerateKey.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginRegenerateKey) {
		d.beginRegenerateKey.remove(req)
	}

	return resp, nil
}

func (d *DatabasesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) {
	if d.srv.BeginUpdate == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")}
	}
	beginUpdate := d.beginUpdate.get(req)
	if beginUpdate == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Cache/redisEnterprise/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/databases/(?P<databaseName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 4 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		body, err := server.UnmarshalRequestAsJSON[armredisenterprise.DatabaseUpdate](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
		if err != nil {
			return nil, err
		}
		databaseNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("databaseName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginUpdate(req.Context(), resourceGroupNameParam, clusterNameParam, databaseNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginUpdate = &respr
		d.beginUpdate.add(req, beginUpdate)
	}

	resp, err := server.PollerResponderNext(beginUpdate, req)
	if err != nil {
		return nil, err
	}

	if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) {
		d.beginUpdate.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginUpdate) {
		d.beginUpdate.remove(req)
	}

	return resp, nil
}

func (d *DatabasesServerTransport) dispatchBeginUpgradeDBRedisVersion(req *http.Request) (*http.Response, error) {
	if d.srv.BeginUpgradeDBRedisVersion == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginUpgradeDBRedisVersion not implemented")}
	}
	beginUpgradeDBRedisVersion := d.beginUpgradeDBRedisVersion.get(req)
	if beginUpgradeDBRedisVersion == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Cache/redisEnterprise/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/databases/(?P<databaseName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/upgradeDBRedisVersion`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 4 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
		if err != nil {
			return nil, err
		}
		databaseNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("databaseName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginUpgradeDBRedisVersion(req.Context(), resourceGroupNameParam, clusterNameParam, databaseNameParam, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginUpgradeDBRedisVersion = &respr
		d.beginUpgradeDBRedisVersion.add(req, beginUpgradeDBRedisVersion)
	}

	resp, err := server.PollerResponderNext(beginUpgradeDBRedisVersion, req)
	if err != nil {
		return nil, err
	}

	if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		d.beginUpgradeDBRedisVersion.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginUpgradeDBRedisVersion) {
		d.beginUpgradeDBRedisVersion.remove(req)
	}

	return resp, nil
}

// set this to conditionally intercept incoming requests to DatabasesServerTransport
var databasesServerTransportInterceptor interface {
	// Do returns true if the server transport should use the returned response/error
	Do(*http.Request) (*http.Response, error, bool)
}
