// 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/sql/armsql/v2"
	"net/http"
	"net/url"
	"regexp"
)

// DistributedAvailabilityGroupsServer is a fake server for instances of the armsql.DistributedAvailabilityGroupsClient type.
type DistributedAvailabilityGroupsServer struct {
	// BeginCreateOrUpdate is the fake for method DistributedAvailabilityGroupsClient.BeginCreateOrUpdate
	// HTTP status codes to indicate success: http.StatusOK, http.StatusCreated, http.StatusAccepted
	BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, managedInstanceName string, distributedAvailabilityGroupName string, parameters armsql.DistributedAvailabilityGroup, options *armsql.DistributedAvailabilityGroupsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder)

	// BeginDelete is the fake for method DistributedAvailabilityGroupsClient.BeginDelete
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginDelete func(ctx context.Context, resourceGroupName string, managedInstanceName string, distributedAvailabilityGroupName string, options *armsql.DistributedAvailabilityGroupsClientBeginDeleteOptions) (resp azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientDeleteResponse], errResp azfake.ErrorResponder)

	// BeginFailover is the fake for method DistributedAvailabilityGroupsClient.BeginFailover
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginFailover func(ctx context.Context, resourceGroupName string, managedInstanceName string, distributedAvailabilityGroupName string, parameters armsql.DistributedAvailabilityGroupsFailoverRequest, options *armsql.DistributedAvailabilityGroupsClientBeginFailoverOptions) (resp azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientFailoverResponse], errResp azfake.ErrorResponder)

	// Get is the fake for method DistributedAvailabilityGroupsClient.Get
	// HTTP status codes to indicate success: http.StatusOK
	Get func(ctx context.Context, resourceGroupName string, managedInstanceName string, distributedAvailabilityGroupName string, options *armsql.DistributedAvailabilityGroupsClientGetOptions) (resp azfake.Responder[armsql.DistributedAvailabilityGroupsClientGetResponse], errResp azfake.ErrorResponder)

	// NewListByInstancePager is the fake for method DistributedAvailabilityGroupsClient.NewListByInstancePager
	// HTTP status codes to indicate success: http.StatusOK
	NewListByInstancePager func(resourceGroupName string, managedInstanceName string, options *armsql.DistributedAvailabilityGroupsClientListByInstanceOptions) (resp azfake.PagerResponder[armsql.DistributedAvailabilityGroupsClientListByInstanceResponse])

	// BeginSetRole is the fake for method DistributedAvailabilityGroupsClient.BeginSetRole
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginSetRole func(ctx context.Context, resourceGroupName string, managedInstanceName string, distributedAvailabilityGroupName string, parameters armsql.DistributedAvailabilityGroupSetRole, options *armsql.DistributedAvailabilityGroupsClientBeginSetRoleOptions) (resp azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientSetRoleResponse], errResp azfake.ErrorResponder)

	// BeginUpdate is the fake for method DistributedAvailabilityGroupsClient.BeginUpdate
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginUpdate func(ctx context.Context, resourceGroupName string, managedInstanceName string, distributedAvailabilityGroupName string, parameters armsql.DistributedAvailabilityGroup, options *armsql.DistributedAvailabilityGroupsClientBeginUpdateOptions) (resp azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientUpdateResponse], errResp azfake.ErrorResponder)
}

// NewDistributedAvailabilityGroupsServerTransport creates a new instance of DistributedAvailabilityGroupsServerTransport with the provided implementation.
// The returned DistributedAvailabilityGroupsServerTransport instance is connected to an instance of armsql.DistributedAvailabilityGroupsClient via the
// azcore.ClientOptions.Transporter field in the client's constructor parameters.
func NewDistributedAvailabilityGroupsServerTransport(srv *DistributedAvailabilityGroupsServer) *DistributedAvailabilityGroupsServerTransport {
	return &DistributedAvailabilityGroupsServerTransport{
		srv:                    srv,
		beginCreateOrUpdate:    newTracker[azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientCreateOrUpdateResponse]](),
		beginDelete:            newTracker[azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientDeleteResponse]](),
		beginFailover:          newTracker[azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientFailoverResponse]](),
		newListByInstancePager: newTracker[azfake.PagerResponder[armsql.DistributedAvailabilityGroupsClientListByInstanceResponse]](),
		beginSetRole:           newTracker[azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientSetRoleResponse]](),
		beginUpdate:            newTracker[azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientUpdateResponse]](),
	}
}

// DistributedAvailabilityGroupsServerTransport connects instances of armsql.DistributedAvailabilityGroupsClient to instances of DistributedAvailabilityGroupsServer.
// Don't use this type directly, use NewDistributedAvailabilityGroupsServerTransport instead.
type DistributedAvailabilityGroupsServerTransport struct {
	srv                    *DistributedAvailabilityGroupsServer
	beginCreateOrUpdate    *tracker[azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientCreateOrUpdateResponse]]
	beginDelete            *tracker[azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientDeleteResponse]]
	beginFailover          *tracker[azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientFailoverResponse]]
	newListByInstancePager *tracker[azfake.PagerResponder[armsql.DistributedAvailabilityGroupsClientListByInstanceResponse]]
	beginSetRole           *tracker[azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientSetRoleResponse]]
	beginUpdate            *tracker[azfake.PollerResponder[armsql.DistributedAvailabilityGroupsClientUpdateResponse]]
}

// Do implements the policy.Transporter interface for DistributedAvailabilityGroupsServerTransport.
func (d *DistributedAvailabilityGroupsServerTransport) 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 *DistributedAvailabilityGroupsServerTransport) 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 distributedAvailabilityGroupsServerTransportInterceptor != nil {
			res.resp, res.err, intercepted = distributedAvailabilityGroupsServerTransportInterceptor.Do(req)
		}
		if !intercepted {
			switch method {
			case "DistributedAvailabilityGroupsClient.BeginCreateOrUpdate":
				res.resp, res.err = d.dispatchBeginCreateOrUpdate(req)
			case "DistributedAvailabilityGroupsClient.BeginDelete":
				res.resp, res.err = d.dispatchBeginDelete(req)
			case "DistributedAvailabilityGroupsClient.BeginFailover":
				res.resp, res.err = d.dispatchBeginFailover(req)
			case "DistributedAvailabilityGroupsClient.Get":
				res.resp, res.err = d.dispatchGet(req)
			case "DistributedAvailabilityGroupsClient.NewListByInstancePager":
				res.resp, res.err = d.dispatchNewListByInstancePager(req)
			case "DistributedAvailabilityGroupsClient.BeginSetRole":
				res.resp, res.err = d.dispatchBeginSetRole(req)
			case "DistributedAvailabilityGroupsClient.BeginUpdate":
				res.resp, res.err = d.dispatchBeginUpdate(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 *DistributedAvailabilityGroupsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) {
	if d.srv.BeginCreateOrUpdate == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")}
	}
	beginCreateOrUpdate := d.beginCreateOrUpdate.get(req)
	if beginCreateOrUpdate == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Sql/managedInstances/(?P<managedInstanceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/distributedAvailabilityGroups/(?P<distributedAvailabilityGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if len(matches) < 5 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		body, err := server.UnmarshalRequestAsJSON[armsql.DistributedAvailabilityGroup](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		managedInstanceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("managedInstanceName")])
		if err != nil {
			return nil, err
		}
		distributedAvailabilityGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("distributedAvailabilityGroupName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, managedInstanceNameParam, distributedAvailabilityGroupNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginCreateOrUpdate = &respr
		d.beginCreateOrUpdate.add(req, beginCreateOrUpdate)
	}

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

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

	return resp, nil
}

func (d *DistributedAvailabilityGroupsServerTransport) 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\.Sql/managedInstances/(?P<managedInstanceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/distributedAvailabilityGroups/(?P<distributedAvailabilityGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if len(matches) < 5 {
			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
		}
		managedInstanceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("managedInstanceName")])
		if err != nil {
			return nil, err
		}
		distributedAvailabilityGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("distributedAvailabilityGroupName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginDelete(req.Context(), resourceGroupNameParam, managedInstanceNameParam, distributedAvailabilityGroupNameParam, 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 *DistributedAvailabilityGroupsServerTransport) dispatchBeginFailover(req *http.Request) (*http.Response, error) {
	if d.srv.BeginFailover == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginFailover not implemented")}
	}
	beginFailover := d.beginFailover.get(req)
	if beginFailover == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Sql/managedInstances/(?P<managedInstanceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/distributedAvailabilityGroups/(?P<distributedAvailabilityGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/failover`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if len(matches) < 5 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		body, err := server.UnmarshalRequestAsJSON[armsql.DistributedAvailabilityGroupsFailoverRequest](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		managedInstanceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("managedInstanceName")])
		if err != nil {
			return nil, err
		}
		distributedAvailabilityGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("distributedAvailabilityGroupName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginFailover(req.Context(), resourceGroupNameParam, managedInstanceNameParam, distributedAvailabilityGroupNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginFailover = &respr
		d.beginFailover.add(req, beginFailover)
	}

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

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

	return resp, nil
}

func (d *DistributedAvailabilityGroupsServerTransport) 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\.Sql/managedInstances/(?P<managedInstanceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/distributedAvailabilityGroups/(?P<distributedAvailabilityGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if len(matches) < 5 {
		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
	}
	managedInstanceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("managedInstanceName")])
	if err != nil {
		return nil, err
	}
	distributedAvailabilityGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("distributedAvailabilityGroupName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameParam, managedInstanceNameParam, distributedAvailabilityGroupNameParam, 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).DistributedAvailabilityGroup, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (d *DistributedAvailabilityGroupsServerTransport) dispatchNewListByInstancePager(req *http.Request) (*http.Response, error) {
	if d.srv.NewListByInstancePager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListByInstancePager not implemented")}
	}
	newListByInstancePager := d.newListByInstancePager.get(req)
	if newListByInstancePager == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Sql/managedInstances/(?P<managedInstanceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/distributedAvailabilityGroups`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if 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
		}
		managedInstanceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("managedInstanceName")])
		if err != nil {
			return nil, err
		}
		resp := d.srv.NewListByInstancePager(resourceGroupNameParam, managedInstanceNameParam, nil)
		newListByInstancePager = &resp
		d.newListByInstancePager.add(req, newListByInstancePager)
		server.PagerResponderInjectNextLinks(newListByInstancePager, req, func(page *armsql.DistributedAvailabilityGroupsClientListByInstanceResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListByInstancePager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		d.newListByInstancePager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListByInstancePager) {
		d.newListByInstancePager.remove(req)
	}
	return resp, nil
}

func (d *DistributedAvailabilityGroupsServerTransport) dispatchBeginSetRole(req *http.Request) (*http.Response, error) {
	if d.srv.BeginSetRole == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginSetRole not implemented")}
	}
	beginSetRole := d.beginSetRole.get(req)
	if beginSetRole == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Sql/managedInstances/(?P<managedInstanceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/distributedAvailabilityGroups/(?P<distributedAvailabilityGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/setRole`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if len(matches) < 5 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		body, err := server.UnmarshalRequestAsJSON[armsql.DistributedAvailabilityGroupSetRole](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		managedInstanceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("managedInstanceName")])
		if err != nil {
			return nil, err
		}
		distributedAvailabilityGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("distributedAvailabilityGroupName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginSetRole(req.Context(), resourceGroupNameParam, managedInstanceNameParam, distributedAvailabilityGroupNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginSetRole = &respr
		d.beginSetRole.add(req, beginSetRole)
	}

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

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

	return resp, nil
}

func (d *DistributedAvailabilityGroupsServerTransport) 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\.Sql/managedInstances/(?P<managedInstanceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/distributedAvailabilityGroups/(?P<distributedAvailabilityGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if len(matches) < 5 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		body, err := server.UnmarshalRequestAsJSON[armsql.DistributedAvailabilityGroup](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		managedInstanceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("managedInstanceName")])
		if err != nil {
			return nil, err
		}
		distributedAvailabilityGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("distributedAvailabilityGroupName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginUpdate(req.Context(), resourceGroupNameParam, managedInstanceNameParam, distributedAvailabilityGroupNameParam, 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
}

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