// 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/workloadorchestration/armworkloadorchestration"
	"net/http"
	"net/url"
	"regexp"
	"strconv"
)

// TargetsServer is a fake server for instances of the armworkloadorchestration.TargetsClient type.
type TargetsServer struct {
	// BeginCreateOrUpdate is the fake for method TargetsClient.BeginCreateOrUpdate
	// HTTP status codes to indicate success: http.StatusOK, http.StatusCreated
	BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, targetName string, resource armworkloadorchestration.Target, options *armworkloadorchestration.TargetsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armworkloadorchestration.TargetsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder)

	// BeginDelete is the fake for method TargetsClient.BeginDelete
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginDelete func(ctx context.Context, resourceGroupName string, targetName string, options *armworkloadorchestration.TargetsClientBeginDeleteOptions) (resp azfake.PollerResponder[armworkloadorchestration.TargetsClientDeleteResponse], errResp azfake.ErrorResponder)

	// Get is the fake for method TargetsClient.Get
	// HTTP status codes to indicate success: http.StatusOK
	Get func(ctx context.Context, resourceGroupName string, targetName string, options *armworkloadorchestration.TargetsClientGetOptions) (resp azfake.Responder[armworkloadorchestration.TargetsClientGetResponse], errResp azfake.ErrorResponder)

	// BeginInstallSolution is the fake for method TargetsClient.BeginInstallSolution
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginInstallSolution func(ctx context.Context, resourceGroupName string, targetName string, body armworkloadorchestration.InstallSolutionParameter, options *armworkloadorchestration.TargetsClientBeginInstallSolutionOptions) (resp azfake.PollerResponder[armworkloadorchestration.TargetsClientInstallSolutionResponse], errResp azfake.ErrorResponder)

	// NewListByResourceGroupPager is the fake for method TargetsClient.NewListByResourceGroupPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListByResourceGroupPager func(resourceGroupName string, options *armworkloadorchestration.TargetsClientListByResourceGroupOptions) (resp azfake.PagerResponder[armworkloadorchestration.TargetsClientListByResourceGroupResponse])

	// NewListBySubscriptionPager is the fake for method TargetsClient.NewListBySubscriptionPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListBySubscriptionPager func(options *armworkloadorchestration.TargetsClientListBySubscriptionOptions) (resp azfake.PagerResponder[armworkloadorchestration.TargetsClientListBySubscriptionResponse])

	// BeginPublishSolutionVersion is the fake for method TargetsClient.BeginPublishSolutionVersion
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginPublishSolutionVersion func(ctx context.Context, resourceGroupName string, targetName string, body armworkloadorchestration.SolutionVersionParameter, options *armworkloadorchestration.TargetsClientBeginPublishSolutionVersionOptions) (resp azfake.PollerResponder[armworkloadorchestration.TargetsClientPublishSolutionVersionResponse], errResp azfake.ErrorResponder)

	// BeginRemoveRevision is the fake for method TargetsClient.BeginRemoveRevision
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginRemoveRevision func(ctx context.Context, resourceGroupName string, targetName string, body armworkloadorchestration.RemoveRevisionParameter, options *armworkloadorchestration.TargetsClientBeginRemoveRevisionOptions) (resp azfake.PollerResponder[armworkloadorchestration.TargetsClientRemoveRevisionResponse], errResp azfake.ErrorResponder)

	// BeginResolveConfiguration is the fake for method TargetsClient.BeginResolveConfiguration
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginResolveConfiguration func(ctx context.Context, resourceGroupName string, targetName string, body armworkloadorchestration.SolutionTemplateParameter, options *armworkloadorchestration.TargetsClientBeginResolveConfigurationOptions) (resp azfake.PollerResponder[armworkloadorchestration.TargetsClientResolveConfigurationResponse], errResp azfake.ErrorResponder)

	// BeginReviewSolutionVersion is the fake for method TargetsClient.BeginReviewSolutionVersion
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginReviewSolutionVersion func(ctx context.Context, resourceGroupName string, targetName string, body armworkloadorchestration.SolutionTemplateParameter, options *armworkloadorchestration.TargetsClientBeginReviewSolutionVersionOptions) (resp azfake.PollerResponder[armworkloadorchestration.TargetsClientReviewSolutionVersionResponse], errResp azfake.ErrorResponder)

	// BeginUninstallSolution is the fake for method TargetsClient.BeginUninstallSolution
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginUninstallSolution func(ctx context.Context, resourceGroupName string, targetName string, body armworkloadorchestration.UninstallSolutionParameter, options *armworkloadorchestration.TargetsClientBeginUninstallSolutionOptions) (resp azfake.PollerResponder[armworkloadorchestration.TargetsClientUninstallSolutionResponse], errResp azfake.ErrorResponder)

	// BeginUpdate is the fake for method TargetsClient.BeginUpdate
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginUpdate func(ctx context.Context, resourceGroupName string, targetName string, properties armworkloadorchestration.TargetUpdate, options *armworkloadorchestration.TargetsClientBeginUpdateOptions) (resp azfake.PollerResponder[armworkloadorchestration.TargetsClientUpdateResponse], errResp azfake.ErrorResponder)

	// BeginUpdateExternalValidationStatus is the fake for method TargetsClient.BeginUpdateExternalValidationStatus
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginUpdateExternalValidationStatus func(ctx context.Context, resourceGroupName string, targetName string, body armworkloadorchestration.UpdateExternalValidationStatusParameter, options *armworkloadorchestration.TargetsClientBeginUpdateExternalValidationStatusOptions) (resp azfake.PollerResponder[armworkloadorchestration.TargetsClientUpdateExternalValidationStatusResponse], errResp azfake.ErrorResponder)
}

// NewTargetsServerTransport creates a new instance of TargetsServerTransport with the provided implementation.
// The returned TargetsServerTransport instance is connected to an instance of armworkloadorchestration.TargetsClient via the
// azcore.ClientOptions.Transporter field in the client's constructor parameters.
func NewTargetsServerTransport(srv *TargetsServer) *TargetsServerTransport {
	return &TargetsServerTransport{
		srv:                                 srv,
		beginCreateOrUpdate:                 newTracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientCreateOrUpdateResponse]](),
		beginDelete:                         newTracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientDeleteResponse]](),
		beginInstallSolution:                newTracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientInstallSolutionResponse]](),
		newListByResourceGroupPager:         newTracker[azfake.PagerResponder[armworkloadorchestration.TargetsClientListByResourceGroupResponse]](),
		newListBySubscriptionPager:          newTracker[azfake.PagerResponder[armworkloadorchestration.TargetsClientListBySubscriptionResponse]](),
		beginPublishSolutionVersion:         newTracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientPublishSolutionVersionResponse]](),
		beginRemoveRevision:                 newTracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientRemoveRevisionResponse]](),
		beginResolveConfiguration:           newTracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientResolveConfigurationResponse]](),
		beginReviewSolutionVersion:          newTracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientReviewSolutionVersionResponse]](),
		beginUninstallSolution:              newTracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientUninstallSolutionResponse]](),
		beginUpdate:                         newTracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientUpdateResponse]](),
		beginUpdateExternalValidationStatus: newTracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientUpdateExternalValidationStatusResponse]](),
	}
}

// TargetsServerTransport connects instances of armworkloadorchestration.TargetsClient to instances of TargetsServer.
// Don't use this type directly, use NewTargetsServerTransport instead.
type TargetsServerTransport struct {
	srv                                 *TargetsServer
	beginCreateOrUpdate                 *tracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientCreateOrUpdateResponse]]
	beginDelete                         *tracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientDeleteResponse]]
	beginInstallSolution                *tracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientInstallSolutionResponse]]
	newListByResourceGroupPager         *tracker[azfake.PagerResponder[armworkloadorchestration.TargetsClientListByResourceGroupResponse]]
	newListBySubscriptionPager          *tracker[azfake.PagerResponder[armworkloadorchestration.TargetsClientListBySubscriptionResponse]]
	beginPublishSolutionVersion         *tracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientPublishSolutionVersionResponse]]
	beginRemoveRevision                 *tracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientRemoveRevisionResponse]]
	beginResolveConfiguration           *tracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientResolveConfigurationResponse]]
	beginReviewSolutionVersion          *tracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientReviewSolutionVersionResponse]]
	beginUninstallSolution              *tracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientUninstallSolutionResponse]]
	beginUpdate                         *tracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientUpdateResponse]]
	beginUpdateExternalValidationStatus *tracker[azfake.PollerResponder[armworkloadorchestration.TargetsClientUpdateExternalValidationStatusResponse]]
}

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

func (t *TargetsServerTransport) 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 targetsServerTransportInterceptor != nil {
			res.resp, res.err, intercepted = targetsServerTransportInterceptor.Do(req)
		}
		if !intercepted {
			switch method {
			case "TargetsClient.BeginCreateOrUpdate":
				res.resp, res.err = t.dispatchBeginCreateOrUpdate(req)
			case "TargetsClient.BeginDelete":
				res.resp, res.err = t.dispatchBeginDelete(req)
			case "TargetsClient.Get":
				res.resp, res.err = t.dispatchGet(req)
			case "TargetsClient.BeginInstallSolution":
				res.resp, res.err = t.dispatchBeginInstallSolution(req)
			case "TargetsClient.NewListByResourceGroupPager":
				res.resp, res.err = t.dispatchNewListByResourceGroupPager(req)
			case "TargetsClient.NewListBySubscriptionPager":
				res.resp, res.err = t.dispatchNewListBySubscriptionPager(req)
			case "TargetsClient.BeginPublishSolutionVersion":
				res.resp, res.err = t.dispatchBeginPublishSolutionVersion(req)
			case "TargetsClient.BeginRemoveRevision":
				res.resp, res.err = t.dispatchBeginRemoveRevision(req)
			case "TargetsClient.BeginResolveConfiguration":
				res.resp, res.err = t.dispatchBeginResolveConfiguration(req)
			case "TargetsClient.BeginReviewSolutionVersion":
				res.resp, res.err = t.dispatchBeginReviewSolutionVersion(req)
			case "TargetsClient.BeginUninstallSolution":
				res.resp, res.err = t.dispatchBeginUninstallSolution(req)
			case "TargetsClient.BeginUpdate":
				res.resp, res.err = t.dispatchBeginUpdate(req)
			case "TargetsClient.BeginUpdateExternalValidationStatus":
				res.resp, res.err = t.dispatchBeginUpdateExternalValidationStatus(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 (t *TargetsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) {
	if t.srv.BeginCreateOrUpdate == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")}
	}
	beginCreateOrUpdate := t.beginCreateOrUpdate.get(req)
	if beginCreateOrUpdate == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Edge/targets/(?P<targetName>[!#&$-;=?-\[\]_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[armworkloadorchestration.Target](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		targetNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("targetName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := t.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, targetNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginCreateOrUpdate = &respr
		t.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) {
		t.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) {
		t.beginCreateOrUpdate.remove(req)
	}

	return resp, nil
}

func (t *TargetsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) {
	if t.srv.BeginDelete == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")}
	}
	beginDelete := t.beginDelete.get(req)
	if beginDelete == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Edge/targets/(?P<targetName>[!#&$-;=?-\[\]_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)
		}
		qp := req.URL.Query()
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		forceDeleteUnescaped, err := url.QueryUnescape(qp.Get("forceDelete"))
		if err != nil {
			return nil, err
		}
		forceDeleteParam, err := parseOptional(forceDeleteUnescaped, strconv.ParseBool)
		if err != nil {
			return nil, err
		}
		targetNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("targetName")])
		if err != nil {
			return nil, err
		}
		var options *armworkloadorchestration.TargetsClientBeginDeleteOptions
		if forceDeleteParam != nil {
			options = &armworkloadorchestration.TargetsClientBeginDeleteOptions{
				ForceDelete: forceDeleteParam,
			}
		}
		respr, errRespr := t.srv.BeginDelete(req.Context(), resourceGroupNameParam, targetNameParam, options)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginDelete = &respr
		t.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) {
		t.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) {
		t.beginDelete.remove(req)
	}

	return resp, nil
}

func (t *TargetsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) {
	if t.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\.Edge/targets/(?P<targetName>[!#&$-;=?-\[\]_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
	}
	targetNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("targetName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := t.srv.Get(req.Context(), resourceGroupNameParam, targetNameParam, 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).Target, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (t *TargetsServerTransport) dispatchBeginInstallSolution(req *http.Request) (*http.Response, error) {
	if t.srv.BeginInstallSolution == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginInstallSolution not implemented")}
	}
	beginInstallSolution := t.beginInstallSolution.get(req)
	if beginInstallSolution == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Edge/targets/(?P<targetName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/installSolution`
		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[armworkloadorchestration.InstallSolutionParameter](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		targetNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("targetName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := t.srv.BeginInstallSolution(req.Context(), resourceGroupNameParam, targetNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginInstallSolution = &respr
		t.beginInstallSolution.add(req, beginInstallSolution)
	}

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

	if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		t.beginInstallSolution.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(beginInstallSolution) {
		t.beginInstallSolution.remove(req)
	}

	return resp, nil
}

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

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

func (t *TargetsServerTransport) dispatchBeginPublishSolutionVersion(req *http.Request) (*http.Response, error) {
	if t.srv.BeginPublishSolutionVersion == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginPublishSolutionVersion not implemented")}
	}
	beginPublishSolutionVersion := t.beginPublishSolutionVersion.get(req)
	if beginPublishSolutionVersion == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Edge/targets/(?P<targetName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/publishSolutionVersion`
		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[armworkloadorchestration.SolutionVersionParameter](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		targetNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("targetName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := t.srv.BeginPublishSolutionVersion(req.Context(), resourceGroupNameParam, targetNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginPublishSolutionVersion = &respr
		t.beginPublishSolutionVersion.add(req, beginPublishSolutionVersion)
	}

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

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

	return resp, nil
}

func (t *TargetsServerTransport) dispatchBeginRemoveRevision(req *http.Request) (*http.Response, error) {
	if t.srv.BeginRemoveRevision == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginRemoveRevision not implemented")}
	}
	beginRemoveRevision := t.beginRemoveRevision.get(req)
	if beginRemoveRevision == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Edge/targets/(?P<targetName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/removeRevision`
		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[armworkloadorchestration.RemoveRevisionParameter](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		targetNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("targetName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := t.srv.BeginRemoveRevision(req.Context(), resourceGroupNameParam, targetNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginRemoveRevision = &respr
		t.beginRemoveRevision.add(req, beginRemoveRevision)
	}

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

	if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		t.beginRemoveRevision.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(beginRemoveRevision) {
		t.beginRemoveRevision.remove(req)
	}

	return resp, nil
}

func (t *TargetsServerTransport) dispatchBeginResolveConfiguration(req *http.Request) (*http.Response, error) {
	if t.srv.BeginResolveConfiguration == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginResolveConfiguration not implemented")}
	}
	beginResolveConfiguration := t.beginResolveConfiguration.get(req)
	if beginResolveConfiguration == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Edge/targets/(?P<targetName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resolveConfiguration`
		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[armworkloadorchestration.SolutionTemplateParameter](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		targetNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("targetName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := t.srv.BeginResolveConfiguration(req.Context(), resourceGroupNameParam, targetNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginResolveConfiguration = &respr
		t.beginResolveConfiguration.add(req, beginResolveConfiguration)
	}

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

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

	return resp, nil
}

func (t *TargetsServerTransport) dispatchBeginReviewSolutionVersion(req *http.Request) (*http.Response, error) {
	if t.srv.BeginReviewSolutionVersion == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginReviewSolutionVersion not implemented")}
	}
	beginReviewSolutionVersion := t.beginReviewSolutionVersion.get(req)
	if beginReviewSolutionVersion == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Edge/targets/(?P<targetName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/reviewSolutionVersion`
		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[armworkloadorchestration.SolutionTemplateParameter](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		targetNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("targetName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := t.srv.BeginReviewSolutionVersion(req.Context(), resourceGroupNameParam, targetNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginReviewSolutionVersion = &respr
		t.beginReviewSolutionVersion.add(req, beginReviewSolutionVersion)
	}

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

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

	return resp, nil
}

func (t *TargetsServerTransport) dispatchBeginUninstallSolution(req *http.Request) (*http.Response, error) {
	if t.srv.BeginUninstallSolution == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginUninstallSolution not implemented")}
	}
	beginUninstallSolution := t.beginUninstallSolution.get(req)
	if beginUninstallSolution == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Edge/targets/(?P<targetName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/uninstallSolution`
		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[armworkloadorchestration.UninstallSolutionParameter](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		targetNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("targetName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := t.srv.BeginUninstallSolution(req.Context(), resourceGroupNameParam, targetNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginUninstallSolution = &respr
		t.beginUninstallSolution.add(req, beginUninstallSolution)
	}

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

	if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		t.beginUninstallSolution.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(beginUninstallSolution) {
		t.beginUninstallSolution.remove(req)
	}

	return resp, nil
}

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

	return resp, nil
}

func (t *TargetsServerTransport) dispatchBeginUpdateExternalValidationStatus(req *http.Request) (*http.Response, error) {
	if t.srv.BeginUpdateExternalValidationStatus == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginUpdateExternalValidationStatus not implemented")}
	}
	beginUpdateExternalValidationStatus := t.beginUpdateExternalValidationStatus.get(req)
	if beginUpdateExternalValidationStatus == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Edge/targets/(?P<targetName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/updateExternalValidationStatus`
		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[armworkloadorchestration.UpdateExternalValidationStatusParameter](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		targetNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("targetName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := t.srv.BeginUpdateExternalValidationStatus(req.Context(), resourceGroupNameParam, targetNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginUpdateExternalValidationStatus = &respr
		t.beginUpdateExternalValidationStatus.add(req, beginUpdateExternalValidationStatus)
	}

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

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

	return resp, nil
}

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