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

// SQLMigrationServicesServer is a fake server for instances of the armdatamigration.SQLMigrationServicesClient type.
type SQLMigrationServicesServer struct {
	// BeginCreateOrUpdate is the fake for method SQLMigrationServicesClient.BeginCreateOrUpdate
	// HTTP status codes to indicate success: http.StatusOK, http.StatusCreated
	BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, sqlMigrationServiceName string, parameters armdatamigration.SQLMigrationService, options *armdatamigration.SQLMigrationServicesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armdatamigration.SQLMigrationServicesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder)

	// BeginDelete is the fake for method SQLMigrationServicesClient.BeginDelete
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginDelete func(ctx context.Context, resourceGroupName string, sqlMigrationServiceName string, options *armdatamigration.SQLMigrationServicesClientBeginDeleteOptions) (resp azfake.PollerResponder[armdatamigration.SQLMigrationServicesClientDeleteResponse], errResp azfake.ErrorResponder)

	// DeleteNode is the fake for method SQLMigrationServicesClient.DeleteNode
	// HTTP status codes to indicate success: http.StatusOK
	DeleteNode func(ctx context.Context, resourceGroupName string, sqlMigrationServiceName string, parameters armdatamigration.DeleteNode, options *armdatamigration.SQLMigrationServicesClientDeleteNodeOptions) (resp azfake.Responder[armdatamigration.SQLMigrationServicesClientDeleteNodeResponse], errResp azfake.ErrorResponder)

	// Get is the fake for method SQLMigrationServicesClient.Get
	// HTTP status codes to indicate success: http.StatusOK
	Get func(ctx context.Context, resourceGroupName string, sqlMigrationServiceName string, options *armdatamigration.SQLMigrationServicesClientGetOptions) (resp azfake.Responder[armdatamigration.SQLMigrationServicesClientGetResponse], errResp azfake.ErrorResponder)

	// ListAuthKeys is the fake for method SQLMigrationServicesClient.ListAuthKeys
	// HTTP status codes to indicate success: http.StatusOK
	ListAuthKeys func(ctx context.Context, resourceGroupName string, sqlMigrationServiceName string, options *armdatamigration.SQLMigrationServicesClientListAuthKeysOptions) (resp azfake.Responder[armdatamigration.SQLMigrationServicesClientListAuthKeysResponse], errResp azfake.ErrorResponder)

	// NewListByResourceGroupPager is the fake for method SQLMigrationServicesClient.NewListByResourceGroupPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListByResourceGroupPager func(resourceGroupName string, options *armdatamigration.SQLMigrationServicesClientListByResourceGroupOptions) (resp azfake.PagerResponder[armdatamigration.SQLMigrationServicesClientListByResourceGroupResponse])

	// NewListBySubscriptionPager is the fake for method SQLMigrationServicesClient.NewListBySubscriptionPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListBySubscriptionPager func(options *armdatamigration.SQLMigrationServicesClientListBySubscriptionOptions) (resp azfake.PagerResponder[armdatamigration.SQLMigrationServicesClientListBySubscriptionResponse])

	// NewListMigrationsPager is the fake for method SQLMigrationServicesClient.NewListMigrationsPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListMigrationsPager func(resourceGroupName string, sqlMigrationServiceName string, options *armdatamigration.SQLMigrationServicesClientListMigrationsOptions) (resp azfake.PagerResponder[armdatamigration.SQLMigrationServicesClientListMigrationsResponse])

	// ListMonitoringData is the fake for method SQLMigrationServicesClient.ListMonitoringData
	// HTTP status codes to indicate success: http.StatusOK
	ListMonitoringData func(ctx context.Context, resourceGroupName string, sqlMigrationServiceName string, options *armdatamigration.SQLMigrationServicesClientListMonitoringDataOptions) (resp azfake.Responder[armdatamigration.SQLMigrationServicesClientListMonitoringDataResponse], errResp azfake.ErrorResponder)

	// RegenerateAuthKeys is the fake for method SQLMigrationServicesClient.RegenerateAuthKeys
	// HTTP status codes to indicate success: http.StatusOK
	RegenerateAuthKeys func(ctx context.Context, resourceGroupName string, sqlMigrationServiceName string, parameters armdatamigration.RegenAuthKeys, options *armdatamigration.SQLMigrationServicesClientRegenerateAuthKeysOptions) (resp azfake.Responder[armdatamigration.SQLMigrationServicesClientRegenerateAuthKeysResponse], errResp azfake.ErrorResponder)

	// BeginUpdate is the fake for method SQLMigrationServicesClient.BeginUpdate
	// HTTP status codes to indicate success: http.StatusOK, http.StatusCreated
	BeginUpdate func(ctx context.Context, resourceGroupName string, sqlMigrationServiceName string, parameters armdatamigration.SQLMigrationServiceUpdate, options *armdatamigration.SQLMigrationServicesClientBeginUpdateOptions) (resp azfake.PollerResponder[armdatamigration.SQLMigrationServicesClientUpdateResponse], errResp azfake.ErrorResponder)
}

// NewSQLMigrationServicesServerTransport creates a new instance of SQLMigrationServicesServerTransport with the provided implementation.
// The returned SQLMigrationServicesServerTransport instance is connected to an instance of armdatamigration.SQLMigrationServicesClient via the
// azcore.ClientOptions.Transporter field in the client's constructor parameters.
func NewSQLMigrationServicesServerTransport(srv *SQLMigrationServicesServer) *SQLMigrationServicesServerTransport {
	return &SQLMigrationServicesServerTransport{
		srv:                         srv,
		beginCreateOrUpdate:         newTracker[azfake.PollerResponder[armdatamigration.SQLMigrationServicesClientCreateOrUpdateResponse]](),
		beginDelete:                 newTracker[azfake.PollerResponder[armdatamigration.SQLMigrationServicesClientDeleteResponse]](),
		newListByResourceGroupPager: newTracker[azfake.PagerResponder[armdatamigration.SQLMigrationServicesClientListByResourceGroupResponse]](),
		newListBySubscriptionPager:  newTracker[azfake.PagerResponder[armdatamigration.SQLMigrationServicesClientListBySubscriptionResponse]](),
		newListMigrationsPager:      newTracker[azfake.PagerResponder[armdatamigration.SQLMigrationServicesClientListMigrationsResponse]](),
		beginUpdate:                 newTracker[azfake.PollerResponder[armdatamigration.SQLMigrationServicesClientUpdateResponse]](),
	}
}

// SQLMigrationServicesServerTransport connects instances of armdatamigration.SQLMigrationServicesClient to instances of SQLMigrationServicesServer.
// Don't use this type directly, use NewSQLMigrationServicesServerTransport instead.
type SQLMigrationServicesServerTransport struct {
	srv                         *SQLMigrationServicesServer
	beginCreateOrUpdate         *tracker[azfake.PollerResponder[armdatamigration.SQLMigrationServicesClientCreateOrUpdateResponse]]
	beginDelete                 *tracker[azfake.PollerResponder[armdatamigration.SQLMigrationServicesClientDeleteResponse]]
	newListByResourceGroupPager *tracker[azfake.PagerResponder[armdatamigration.SQLMigrationServicesClientListByResourceGroupResponse]]
	newListBySubscriptionPager  *tracker[azfake.PagerResponder[armdatamigration.SQLMigrationServicesClientListBySubscriptionResponse]]
	newListMigrationsPager      *tracker[azfake.PagerResponder[armdatamigration.SQLMigrationServicesClientListMigrationsResponse]]
	beginUpdate                 *tracker[azfake.PollerResponder[armdatamigration.SQLMigrationServicesClientUpdateResponse]]
}

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

func (s *SQLMigrationServicesServerTransport) 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 sqlMigrationServicesServerTransportInterceptor != nil {
			res.resp, res.err, intercepted = sqlMigrationServicesServerTransportInterceptor.Do(req)
		}
		if !intercepted {
			switch method {
			case "SQLMigrationServicesClient.BeginCreateOrUpdate":
				res.resp, res.err = s.dispatchBeginCreateOrUpdate(req)
			case "SQLMigrationServicesClient.BeginDelete":
				res.resp, res.err = s.dispatchBeginDelete(req)
			case "SQLMigrationServicesClient.DeleteNode":
				res.resp, res.err = s.dispatchDeleteNode(req)
			case "SQLMigrationServicesClient.Get":
				res.resp, res.err = s.dispatchGet(req)
			case "SQLMigrationServicesClient.ListAuthKeys":
				res.resp, res.err = s.dispatchListAuthKeys(req)
			case "SQLMigrationServicesClient.NewListByResourceGroupPager":
				res.resp, res.err = s.dispatchNewListByResourceGroupPager(req)
			case "SQLMigrationServicesClient.NewListBySubscriptionPager":
				res.resp, res.err = s.dispatchNewListBySubscriptionPager(req)
			case "SQLMigrationServicesClient.NewListMigrationsPager":
				res.resp, res.err = s.dispatchNewListMigrationsPager(req)
			case "SQLMigrationServicesClient.ListMonitoringData":
				res.resp, res.err = s.dispatchListMonitoringData(req)
			case "SQLMigrationServicesClient.RegenerateAuthKeys":
				res.resp, res.err = s.dispatchRegenerateAuthKeys(req)
			case "SQLMigrationServicesClient.BeginUpdate":
				res.resp, res.err = s.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 (s *SQLMigrationServicesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) {
	if s.srv.BeginCreateOrUpdate == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")}
	}
	beginCreateOrUpdate := s.beginCreateOrUpdate.get(req)
	if beginCreateOrUpdate == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DataMigration/sqlMigrationServices/(?P<sqlMigrationServiceName>[!#&$-;=?-\[\]_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[armdatamigration.SQLMigrationService](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		sqlMigrationServiceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("sqlMigrationServiceName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, sqlMigrationServiceNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginCreateOrUpdate = &respr
		s.beginCreateOrUpdate.add(req, beginCreateOrUpdate)
	}

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

	if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) {
		s.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) {
		s.beginCreateOrUpdate.remove(req)
	}

	return resp, nil
}

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

	return resp, nil
}

func (s *SQLMigrationServicesServerTransport) dispatchDeleteNode(req *http.Request) (*http.Response, error) {
	if s.srv.DeleteNode == nil {
		return nil, &nonRetriableError{errors.New("fake for method DeleteNode not implemented")}
	}
	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DataMigration/sqlMigrationServices/(?P<sqlMigrationServiceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/deleteNode`
	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[armdatamigration.DeleteNode](req)
	if err != nil {
		return nil, err
	}
	resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
	if err != nil {
		return nil, err
	}
	sqlMigrationServiceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("sqlMigrationServiceName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := s.srv.DeleteNode(req.Context(), resourceGroupNameParam, sqlMigrationServiceNameParam, body, 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).DeleteNode, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *SQLMigrationServicesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) {
	if s.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\.DataMigration/sqlMigrationServices/(?P<sqlMigrationServiceName>[!#&$-;=?-\[\]_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
	}
	sqlMigrationServiceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("sqlMigrationServiceName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameParam, sqlMigrationServiceNameParam, 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).SQLMigrationService, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *SQLMigrationServicesServerTransport) dispatchListAuthKeys(req *http.Request) (*http.Response, error) {
	if s.srv.ListAuthKeys == nil {
		return nil, &nonRetriableError{errors.New("fake for method ListAuthKeys not implemented")}
	}
	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DataMigration/sqlMigrationServices/(?P<sqlMigrationServiceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/listAuthKeys`
	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
	}
	sqlMigrationServiceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("sqlMigrationServiceName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := s.srv.ListAuthKeys(req.Context(), resourceGroupNameParam, sqlMigrationServiceNameParam, 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).AuthenticationKeys, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

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

func (s *SQLMigrationServicesServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) {
	if s.srv.NewListBySubscriptionPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")}
	}
	newListBySubscriptionPager := s.newListBySubscriptionPager.get(req)
	if newListBySubscriptionPager == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DataMigration/sqlMigrationServices`
		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 := s.srv.NewListBySubscriptionPager(nil)
		newListBySubscriptionPager = &resp
		s.newListBySubscriptionPager.add(req, newListBySubscriptionPager)
		server.PagerResponderInjectNextLinks(newListBySubscriptionPager, req, func(page *armdatamigration.SQLMigrationServicesClientListBySubscriptionResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListBySubscriptionPager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		s.newListBySubscriptionPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListBySubscriptionPager) {
		s.newListBySubscriptionPager.remove(req)
	}
	return resp, nil
}

func (s *SQLMigrationServicesServerTransport) dispatchNewListMigrationsPager(req *http.Request) (*http.Response, error) {
	if s.srv.NewListMigrationsPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListMigrationsPager not implemented")}
	}
	newListMigrationsPager := s.newListMigrationsPager.get(req)
	if newListMigrationsPager == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DataMigration/sqlMigrationServices/(?P<sqlMigrationServiceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/listMigrations`
		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
		}
		sqlMigrationServiceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("sqlMigrationServiceName")])
		if err != nil {
			return nil, err
		}
		resp := s.srv.NewListMigrationsPager(resourceGroupNameParam, sqlMigrationServiceNameParam, nil)
		newListMigrationsPager = &resp
		s.newListMigrationsPager.add(req, newListMigrationsPager)
		server.PagerResponderInjectNextLinks(newListMigrationsPager, req, func(page *armdatamigration.SQLMigrationServicesClientListMigrationsResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListMigrationsPager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		s.newListMigrationsPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListMigrationsPager) {
		s.newListMigrationsPager.remove(req)
	}
	return resp, nil
}

func (s *SQLMigrationServicesServerTransport) dispatchListMonitoringData(req *http.Request) (*http.Response, error) {
	if s.srv.ListMonitoringData == nil {
		return nil, &nonRetriableError{errors.New("fake for method ListMonitoringData not implemented")}
	}
	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DataMigration/sqlMigrationServices/(?P<sqlMigrationServiceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/listMonitoringData`
	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
	}
	sqlMigrationServiceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("sqlMigrationServiceName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := s.srv.ListMonitoringData(req.Context(), resourceGroupNameParam, sqlMigrationServiceNameParam, 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).IntegrationRuntimeMonitoringData, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *SQLMigrationServicesServerTransport) dispatchRegenerateAuthKeys(req *http.Request) (*http.Response, error) {
	if s.srv.RegenerateAuthKeys == nil {
		return nil, &nonRetriableError{errors.New("fake for method RegenerateAuthKeys not implemented")}
	}
	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DataMigration/sqlMigrationServices/(?P<sqlMigrationServiceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/regenerateAuthKeys`
	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[armdatamigration.RegenAuthKeys](req)
	if err != nil {
		return nil, err
	}
	resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
	if err != nil {
		return nil, err
	}
	sqlMigrationServiceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("sqlMigrationServiceName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := s.srv.RegenerateAuthKeys(req.Context(), resourceGroupNameParam, sqlMigrationServiceNameParam, body, 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).RegenAuthKeys, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

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

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

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

	return resp, nil
}

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