// 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 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/enclave/armenclave"
	"net/http"
	"net/url"
	"regexp"
	"slices"
)

// ConnectionServer is a fake server for instances of the armenclave.ConnectionClient type.
type ConnectionServer struct {
	// BeginCreateOrUpdate is the fake for method ConnectionClient.BeginCreateOrUpdate
	// HTTP status codes to indicate success: http.StatusOK, http.StatusCreated
	BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, enclaveConnectionName string, resource armenclave.ConnectionResource, options *armenclave.ConnectionClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armenclave.ConnectionClientCreateOrUpdateResponse], errResp azfake.ErrorResponder)

	// BeginDelete is the fake for method ConnectionClient.BeginDelete
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginDelete func(ctx context.Context, resourceGroupName string, enclaveConnectionName string, options *armenclave.ConnectionClientBeginDeleteOptions) (resp azfake.PollerResponder[armenclave.ConnectionClientDeleteResponse], errResp azfake.ErrorResponder)

	// Get is the fake for method ConnectionClient.Get
	// HTTP status codes to indicate success: http.StatusOK
	Get func(ctx context.Context, resourceGroupName string, enclaveConnectionName string, options *armenclave.ConnectionClientGetOptions) (resp azfake.Responder[armenclave.ConnectionClientGetResponse], errResp azfake.ErrorResponder)

	// BeginHandleApprovalCreation is the fake for method ConnectionClient.BeginHandleApprovalCreation
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginHandleApprovalCreation func(ctx context.Context, resourceGroupName string, enclaveConnectionName string, body armenclave.ApprovalCallbackRequest, options *armenclave.ConnectionClientBeginHandleApprovalCreationOptions) (resp azfake.PollerResponder[armenclave.ConnectionClientHandleApprovalCreationResponse], errResp azfake.ErrorResponder)

	// BeginHandleApprovalDeletion is the fake for method ConnectionClient.BeginHandleApprovalDeletion
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginHandleApprovalDeletion func(ctx context.Context, resourceGroupName string, enclaveConnectionName string, body armenclave.ApprovalDeletionCallbackRequest, options *armenclave.ConnectionClientBeginHandleApprovalDeletionOptions) (resp azfake.PollerResponder[armenclave.ConnectionClientHandleApprovalDeletionResponse], errResp azfake.ErrorResponder)

	// NewListByResourceGroupPager is the fake for method ConnectionClient.NewListByResourceGroupPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListByResourceGroupPager func(resourceGroupName string, options *armenclave.ConnectionClientListByResourceGroupOptions) (resp azfake.PagerResponder[armenclave.ConnectionClientListByResourceGroupResponse])

	// NewListBySubscriptionPager is the fake for method ConnectionClient.NewListBySubscriptionPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListBySubscriptionPager func(options *armenclave.ConnectionClientListBySubscriptionOptions) (resp azfake.PagerResponder[armenclave.ConnectionClientListBySubscriptionResponse])

	// BeginUpdate is the fake for method ConnectionClient.BeginUpdate
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginUpdate func(ctx context.Context, resourceGroupName string, enclaveConnectionName string, properties armenclave.ConnectionPatchModel, options *armenclave.ConnectionClientBeginUpdateOptions) (resp azfake.PollerResponder[armenclave.ConnectionClientUpdateResponse], errResp azfake.ErrorResponder)
}

// NewConnectionServerTransport creates a new instance of ConnectionServerTransport with the provided implementation.
// The returned ConnectionServerTransport instance is connected to an instance of armenclave.ConnectionClient via the
// azcore.ClientOptions.Transporter field in the client's constructor parameters.
func NewConnectionServerTransport(srv *ConnectionServer) *ConnectionServerTransport {
	return &ConnectionServerTransport{
		srv:                         srv,
		beginCreateOrUpdate:         newTracker[azfake.PollerResponder[armenclave.ConnectionClientCreateOrUpdateResponse]](),
		beginDelete:                 newTracker[azfake.PollerResponder[armenclave.ConnectionClientDeleteResponse]](),
		beginHandleApprovalCreation: newTracker[azfake.PollerResponder[armenclave.ConnectionClientHandleApprovalCreationResponse]](),
		beginHandleApprovalDeletion: newTracker[azfake.PollerResponder[armenclave.ConnectionClientHandleApprovalDeletionResponse]](),
		newListByResourceGroupPager: newTracker[azfake.PagerResponder[armenclave.ConnectionClientListByResourceGroupResponse]](),
		newListBySubscriptionPager:  newTracker[azfake.PagerResponder[armenclave.ConnectionClientListBySubscriptionResponse]](),
		beginUpdate:                 newTracker[azfake.PollerResponder[armenclave.ConnectionClientUpdateResponse]](),
	}
}

// ConnectionServerTransport connects instances of armenclave.ConnectionClient to instances of ConnectionServer.
// Don't use this type directly, use NewConnectionServerTransport instead.
type ConnectionServerTransport struct {
	srv                         *ConnectionServer
	beginCreateOrUpdate         *tracker[azfake.PollerResponder[armenclave.ConnectionClientCreateOrUpdateResponse]]
	beginDelete                 *tracker[azfake.PollerResponder[armenclave.ConnectionClientDeleteResponse]]
	beginHandleApprovalCreation *tracker[azfake.PollerResponder[armenclave.ConnectionClientHandleApprovalCreationResponse]]
	beginHandleApprovalDeletion *tracker[azfake.PollerResponder[armenclave.ConnectionClientHandleApprovalDeletionResponse]]
	newListByResourceGroupPager *tracker[azfake.PagerResponder[armenclave.ConnectionClientListByResourceGroupResponse]]
	newListBySubscriptionPager  *tracker[azfake.PagerResponder[armenclave.ConnectionClientListBySubscriptionResponse]]
	beginUpdate                 *tracker[azfake.PollerResponder[armenclave.ConnectionClientUpdateResponse]]
}

// Do implements the policy.Transporter interface for ConnectionServerTransport.
func (c *ConnectionServerTransport) 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 c.dispatchToMethodFake(req, method)
}

func (c *ConnectionServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) {
	resultChan := make(chan result, 1)
	go func() {
		var intercepted bool
		var res result
		if connectionServerTransportInterceptor != nil {
			res.resp, res.err, intercepted = connectionServerTransportInterceptor.Do(req)
		}
		if !intercepted {
			switch method {
			case "ConnectionClient.BeginCreateOrUpdate":
				res.resp, res.err = c.dispatchBeginCreateOrUpdate(req)
			case "ConnectionClient.BeginDelete":
				res.resp, res.err = c.dispatchBeginDelete(req)
			case "ConnectionClient.Get":
				res.resp, res.err = c.dispatchGet(req)
			case "ConnectionClient.BeginHandleApprovalCreation":
				res.resp, res.err = c.dispatchBeginHandleApprovalCreation(req)
			case "ConnectionClient.BeginHandleApprovalDeletion":
				res.resp, res.err = c.dispatchBeginHandleApprovalDeletion(req)
			case "ConnectionClient.NewListByResourceGroupPager":
				res.resp, res.err = c.dispatchNewListByResourceGroupPager(req)
			case "ConnectionClient.NewListBySubscriptionPager":
				res.resp, res.err = c.dispatchNewListBySubscriptionPager(req)
			case "ConnectionClient.BeginUpdate":
				res.resp, res.err = c.dispatchBeginUpdate(req)
			default:
				res.err = fmt.Errorf("unhandled API %s", method)
			}

		}
		resultChan <- res
	}()

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

func (c *ConnectionServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) {
	if c.srv.BeginCreateOrUpdate == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")}
	}
	beginCreateOrUpdate := c.beginCreateOrUpdate.get(req)
	if beginCreateOrUpdate == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Mission/enclaveConnections/(?P<enclaveConnectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
		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)
		}
		body, err := server.UnmarshalRequestAsJSON[armenclave.ConnectionResource](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		enclaveConnectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("enclaveConnectionName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := c.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, enclaveConnectionNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginCreateOrUpdate = &respr
		c.beginCreateOrUpdate.add(req, beginCreateOrUpdate)
	}

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

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

	return resp, nil
}

func (c *ConnectionServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) {
	if c.srv.BeginDelete == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")}
	}
	beginDelete := c.beginDelete.get(req)
	if beginDelete == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Mission/enclaveConnections/(?P<enclaveConnectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
		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
		}
		enclaveConnectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("enclaveConnectionName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := c.srv.BeginDelete(req.Context(), resourceGroupNameParam, enclaveConnectionNameParam, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginDelete = &respr
		c.beginDelete.add(req, beginDelete)
	}

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

	if !slices.Contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		c.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) {
		c.beginDelete.remove(req)
	}

	return resp, nil
}

func (c *ConnectionServerTransport) dispatchGet(req *http.Request) (*http.Response, error) {
	if c.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\.Mission/enclaveConnections/(?P<enclaveConnectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	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
	}
	enclaveConnectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("enclaveConnectionName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := c.srv.Get(req.Context(), resourceGroupNameParam, enclaveConnectionNameParam, nil)
	if respErr := server.GetError(errRespr, req); respErr != nil {
		return nil, respErr
	}
	respContent := server.GetResponseContent(respr)
	if !slices.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).ConnectionResource, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (c *ConnectionServerTransport) dispatchBeginHandleApprovalCreation(req *http.Request) (*http.Response, error) {
	if c.srv.BeginHandleApprovalCreation == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginHandleApprovalCreation not implemented")}
	}
	beginHandleApprovalCreation := c.beginHandleApprovalCreation.get(req)
	if beginHandleApprovalCreation == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Mission/enclaveConnections/(?P<enclaveConnectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/handleApprovalCreation`
		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)
		}
		body, err := server.UnmarshalRequestAsJSON[armenclave.ApprovalCallbackRequest](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		enclaveConnectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("enclaveConnectionName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := c.srv.BeginHandleApprovalCreation(req.Context(), resourceGroupNameParam, enclaveConnectionNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginHandleApprovalCreation = &respr
		c.beginHandleApprovalCreation.add(req, beginHandleApprovalCreation)
	}

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

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

	return resp, nil
}

func (c *ConnectionServerTransport) dispatchBeginHandleApprovalDeletion(req *http.Request) (*http.Response, error) {
	if c.srv.BeginHandleApprovalDeletion == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginHandleApprovalDeletion not implemented")}
	}
	beginHandleApprovalDeletion := c.beginHandleApprovalDeletion.get(req)
	if beginHandleApprovalDeletion == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Mission/enclaveConnections/(?P<enclaveConnectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/handleApprovalDeletion`
		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)
		}
		body, err := server.UnmarshalRequestAsJSON[armenclave.ApprovalDeletionCallbackRequest](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		enclaveConnectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("enclaveConnectionName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := c.srv.BeginHandleApprovalDeletion(req.Context(), resourceGroupNameParam, enclaveConnectionNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginHandleApprovalDeletion = &respr
		c.beginHandleApprovalDeletion.add(req, beginHandleApprovalDeletion)
	}

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

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

	return resp, nil
}

func (c *ConnectionServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) {
	if c.srv.NewListByResourceGroupPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")}
	}
	newListByResourceGroupPager := c.newListByResourceGroupPager.get(req)
	if newListByResourceGroupPager == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Mission/enclaveConnections`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if 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
		}
		resp := c.srv.NewListByResourceGroupPager(resourceGroupNameParam, nil)
		newListByResourceGroupPager = &resp
		c.newListByResourceGroupPager.add(req, newListByResourceGroupPager)
		server.PagerResponderInjectNextLinks(newListByResourceGroupPager, req, func(page *armenclave.ConnectionClientListByResourceGroupResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListByResourceGroupPager, req)
	if err != nil {
		return nil, err
	}
	if !slices.Contains([]int{http.StatusOK}, resp.StatusCode) {
		c.newListByResourceGroupPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListByResourceGroupPager) {
		c.newListByResourceGroupPager.remove(req)
	}
	return resp, nil
}

func (c *ConnectionServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) {
	if c.srv.NewListBySubscriptionPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")}
	}
	newListBySubscriptionPager := c.newListBySubscriptionPager.get(req)
	if newListBySubscriptionPager == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Mission/enclaveConnections`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if len(matches) < 2 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		resp := c.srv.NewListBySubscriptionPager(nil)
		newListBySubscriptionPager = &resp
		c.newListBySubscriptionPager.add(req, newListBySubscriptionPager)
		server.PagerResponderInjectNextLinks(newListBySubscriptionPager, req, func(page *armenclave.ConnectionClientListBySubscriptionResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListBySubscriptionPager, req)
	if err != nil {
		return nil, err
	}
	if !slices.Contains([]int{http.StatusOK}, resp.StatusCode) {
		c.newListBySubscriptionPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListBySubscriptionPager) {
		c.newListBySubscriptionPager.remove(req)
	}
	return resp, nil
}

func (c *ConnectionServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) {
	if c.srv.BeginUpdate == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")}
	}
	beginUpdate := c.beginUpdate.get(req)
	if beginUpdate == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Mission/enclaveConnections/(?P<enclaveConnectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
		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)
		}
		body, err := server.UnmarshalRequestAsJSON[armenclave.ConnectionPatchModel](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		enclaveConnectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("enclaveConnectionName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := c.srv.BeginUpdate(req.Context(), resourceGroupNameParam, enclaveConnectionNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginUpdate = &respr
		c.beginUpdate.add(req, beginUpdate)
	}

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

	if !slices.Contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) {
		c.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) {
		c.beginUpdate.remove(req)
	}

	return resp, nil
}

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