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

// SetDefinitionVersionsServer is a fake server for instances of the armpolicy.SetDefinitionVersionsClient type.
type SetDefinitionVersionsServer struct {
	// CreateOrUpdate is the fake for method SetDefinitionVersionsClient.CreateOrUpdate
	// HTTP status codes to indicate success: http.StatusOK, http.StatusCreated
	CreateOrUpdate func(ctx context.Context, policySetDefinitionName string, policyDefinitionVersion string, parameters armpolicy.SetDefinitionVersion, options *armpolicy.SetDefinitionVersionsClientCreateOrUpdateOptions) (resp azfake.Responder[armpolicy.SetDefinitionVersionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder)

	// CreateOrUpdateAtManagementGroup is the fake for method SetDefinitionVersionsClient.CreateOrUpdateAtManagementGroup
	// HTTP status codes to indicate success: http.StatusOK, http.StatusCreated
	CreateOrUpdateAtManagementGroup func(ctx context.Context, managementGroupName string, policySetDefinitionName string, policyDefinitionVersion string, parameters armpolicy.SetDefinitionVersion, options *armpolicy.SetDefinitionVersionsClientCreateOrUpdateAtManagementGroupOptions) (resp azfake.Responder[armpolicy.SetDefinitionVersionsClientCreateOrUpdateAtManagementGroupResponse], errResp azfake.ErrorResponder)

	// Delete is the fake for method SetDefinitionVersionsClient.Delete
	// HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent
	Delete func(ctx context.Context, policySetDefinitionName string, policyDefinitionVersion string, options *armpolicy.SetDefinitionVersionsClientDeleteOptions) (resp azfake.Responder[armpolicy.SetDefinitionVersionsClientDeleteResponse], errResp azfake.ErrorResponder)

	// DeleteAtManagementGroup is the fake for method SetDefinitionVersionsClient.DeleteAtManagementGroup
	// HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent
	DeleteAtManagementGroup func(ctx context.Context, managementGroupName string, policySetDefinitionName string, policyDefinitionVersion string, options *armpolicy.SetDefinitionVersionsClientDeleteAtManagementGroupOptions) (resp azfake.Responder[armpolicy.SetDefinitionVersionsClientDeleteAtManagementGroupResponse], errResp azfake.ErrorResponder)

	// Get is the fake for method SetDefinitionVersionsClient.Get
	// HTTP status codes to indicate success: http.StatusOK
	Get func(ctx context.Context, policySetDefinitionName string, policyDefinitionVersion string, options *armpolicy.SetDefinitionVersionsClientGetOptions) (resp azfake.Responder[armpolicy.SetDefinitionVersionsClientGetResponse], errResp azfake.ErrorResponder)

	// GetAtManagementGroup is the fake for method SetDefinitionVersionsClient.GetAtManagementGroup
	// HTTP status codes to indicate success: http.StatusOK
	GetAtManagementGroup func(ctx context.Context, managementGroupName string, policySetDefinitionName string, policyDefinitionVersion string, options *armpolicy.SetDefinitionVersionsClientGetAtManagementGroupOptions) (resp azfake.Responder[armpolicy.SetDefinitionVersionsClientGetAtManagementGroupResponse], errResp azfake.ErrorResponder)

	// GetBuiltIn is the fake for method SetDefinitionVersionsClient.GetBuiltIn
	// HTTP status codes to indicate success: http.StatusOK
	GetBuiltIn func(ctx context.Context, policySetDefinitionName string, policyDefinitionVersion string, options *armpolicy.SetDefinitionVersionsClientGetBuiltInOptions) (resp azfake.Responder[armpolicy.SetDefinitionVersionsClientGetBuiltInResponse], errResp azfake.ErrorResponder)

	// NewListPager is the fake for method SetDefinitionVersionsClient.NewListPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListPager func(policySetDefinitionName string, options *armpolicy.SetDefinitionVersionsClientListOptions) (resp azfake.PagerResponder[armpolicy.SetDefinitionVersionsClientListResponse])

	// ListAll is the fake for method SetDefinitionVersionsClient.ListAll
	// HTTP status codes to indicate success: http.StatusOK
	ListAll func(ctx context.Context, options *armpolicy.SetDefinitionVersionsClientListAllOptions) (resp azfake.Responder[armpolicy.SetDefinitionVersionsClientListAllResponse], errResp azfake.ErrorResponder)

	// ListAllAtManagementGroup is the fake for method SetDefinitionVersionsClient.ListAllAtManagementGroup
	// HTTP status codes to indicate success: http.StatusOK
	ListAllAtManagementGroup func(ctx context.Context, managementGroupName string, options *armpolicy.SetDefinitionVersionsClientListAllAtManagementGroupOptions) (resp azfake.Responder[armpolicy.SetDefinitionVersionsClientListAllAtManagementGroupResponse], errResp azfake.ErrorResponder)

	// ListAllBuiltins is the fake for method SetDefinitionVersionsClient.ListAllBuiltins
	// HTTP status codes to indicate success: http.StatusOK
	ListAllBuiltins func(ctx context.Context, options *armpolicy.SetDefinitionVersionsClientListAllBuiltinsOptions) (resp azfake.Responder[armpolicy.SetDefinitionVersionsClientListAllBuiltinsResponse], errResp azfake.ErrorResponder)

	// NewListBuiltInPager is the fake for method SetDefinitionVersionsClient.NewListBuiltInPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListBuiltInPager func(policySetDefinitionName string, options *armpolicy.SetDefinitionVersionsClientListBuiltInOptions) (resp azfake.PagerResponder[armpolicy.SetDefinitionVersionsClientListBuiltInResponse])

	// NewListByManagementGroupPager is the fake for method SetDefinitionVersionsClient.NewListByManagementGroupPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListByManagementGroupPager func(managementGroupName string, policySetDefinitionName string, options *armpolicy.SetDefinitionVersionsClientListByManagementGroupOptions) (resp azfake.PagerResponder[armpolicy.SetDefinitionVersionsClientListByManagementGroupResponse])
}

// NewSetDefinitionVersionsServerTransport creates a new instance of SetDefinitionVersionsServerTransport with the provided implementation.
// The returned SetDefinitionVersionsServerTransport instance is connected to an instance of armpolicy.SetDefinitionVersionsClient via the
// azcore.ClientOptions.Transporter field in the client's constructor parameters.
func NewSetDefinitionVersionsServerTransport(srv *SetDefinitionVersionsServer) *SetDefinitionVersionsServerTransport {
	return &SetDefinitionVersionsServerTransport{
		srv:                           srv,
		newListPager:                  newTracker[azfake.PagerResponder[armpolicy.SetDefinitionVersionsClientListResponse]](),
		newListBuiltInPager:           newTracker[azfake.PagerResponder[armpolicy.SetDefinitionVersionsClientListBuiltInResponse]](),
		newListByManagementGroupPager: newTracker[azfake.PagerResponder[armpolicy.SetDefinitionVersionsClientListByManagementGroupResponse]](),
	}
}

// SetDefinitionVersionsServerTransport connects instances of armpolicy.SetDefinitionVersionsClient to instances of SetDefinitionVersionsServer.
// Don't use this type directly, use NewSetDefinitionVersionsServerTransport instead.
type SetDefinitionVersionsServerTransport struct {
	srv                           *SetDefinitionVersionsServer
	newListPager                  *tracker[azfake.PagerResponder[armpolicy.SetDefinitionVersionsClientListResponse]]
	newListBuiltInPager           *tracker[azfake.PagerResponder[armpolicy.SetDefinitionVersionsClientListBuiltInResponse]]
	newListByManagementGroupPager *tracker[azfake.PagerResponder[armpolicy.SetDefinitionVersionsClientListByManagementGroupResponse]]
}

// Do implements the policy.Transporter interface for SetDefinitionVersionsServerTransport.
func (s *SetDefinitionVersionsServerTransport) 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 *SetDefinitionVersionsServerTransport) 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 setDefinitionVersionsServerTransportInterceptor != nil {
			res.resp, res.err, intercepted = setDefinitionVersionsServerTransportInterceptor.Do(req)
		}
		if !intercepted {
			switch method {
			case "SetDefinitionVersionsClient.CreateOrUpdate":
				res.resp, res.err = s.dispatchCreateOrUpdate(req)
			case "SetDefinitionVersionsClient.CreateOrUpdateAtManagementGroup":
				res.resp, res.err = s.dispatchCreateOrUpdateAtManagementGroup(req)
			case "SetDefinitionVersionsClient.Delete":
				res.resp, res.err = s.dispatchDelete(req)
			case "SetDefinitionVersionsClient.DeleteAtManagementGroup":
				res.resp, res.err = s.dispatchDeleteAtManagementGroup(req)
			case "SetDefinitionVersionsClient.Get":
				res.resp, res.err = s.dispatchGet(req)
			case "SetDefinitionVersionsClient.GetAtManagementGroup":
				res.resp, res.err = s.dispatchGetAtManagementGroup(req)
			case "SetDefinitionVersionsClient.GetBuiltIn":
				res.resp, res.err = s.dispatchGetBuiltIn(req)
			case "SetDefinitionVersionsClient.NewListPager":
				res.resp, res.err = s.dispatchNewListPager(req)
			case "SetDefinitionVersionsClient.ListAll":
				res.resp, res.err = s.dispatchListAll(req)
			case "SetDefinitionVersionsClient.ListAllAtManagementGroup":
				res.resp, res.err = s.dispatchListAllAtManagementGroup(req)
			case "SetDefinitionVersionsClient.ListAllBuiltins":
				res.resp, res.err = s.dispatchListAllBuiltins(req)
			case "SetDefinitionVersionsClient.NewListBuiltInPager":
				res.resp, res.err = s.dispatchNewListBuiltInPager(req)
			case "SetDefinitionVersionsClient.NewListByManagementGroupPager":
				res.resp, res.err = s.dispatchNewListByManagementGroupPager(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 *SetDefinitionVersionsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) {
	if s.srv.CreateOrUpdate == nil {
		return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")}
	}
	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions/(?P<policySetDefinitionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?P<policyDefinitionVersion>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if matches == nil || len(matches) < 3 {
		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
	}
	body, err := server.UnmarshalRequestAsJSON[armpolicy.SetDefinitionVersion](req)
	if err != nil {
		return nil, err
	}
	policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")])
	if err != nil {
		return nil, err
	}
	policyDefinitionVersionParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyDefinitionVersion")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := s.srv.CreateOrUpdate(req.Context(), policySetDefinitionNameParam, policyDefinitionVersionParam, body, nil)
	if respErr := server.GetError(errRespr, req); respErr != nil {
		return nil, respErr
	}
	respContent := server.GetResponseContent(respr)
	if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) {
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)}
	}
	resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).SetDefinitionVersion, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *SetDefinitionVersionsServerTransport) dispatchCreateOrUpdateAtManagementGroup(req *http.Request) (*http.Response, error) {
	if s.srv.CreateOrUpdateAtManagementGroup == nil {
		return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdateAtManagementGroup not implemented")}
	}
	const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P<managementGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions/(?P<policySetDefinitionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?P<policyDefinitionVersion>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if matches == nil || len(matches) < 3 {
		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
	}
	body, err := server.UnmarshalRequestAsJSON[armpolicy.SetDefinitionVersion](req)
	if err != nil {
		return nil, err
	}
	managementGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupName")])
	if err != nil {
		return nil, err
	}
	policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")])
	if err != nil {
		return nil, err
	}
	policyDefinitionVersionParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyDefinitionVersion")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := s.srv.CreateOrUpdateAtManagementGroup(req.Context(), managementGroupNameParam, policySetDefinitionNameParam, policyDefinitionVersionParam, body, nil)
	if respErr := server.GetError(errRespr, req); respErr != nil {
		return nil, respErr
	}
	respContent := server.GetResponseContent(respr)
	if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) {
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)}
	}
	resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).SetDefinitionVersion, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *SetDefinitionVersionsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) {
	if s.srv.Delete == nil {
		return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")}
	}
	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions/(?P<policySetDefinitionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?P<policyDefinitionVersion>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if matches == nil || len(matches) < 3 {
		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
	}
	policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")])
	if err != nil {
		return nil, err
	}
	policyDefinitionVersionParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyDefinitionVersion")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := s.srv.Delete(req.Context(), policySetDefinitionNameParam, policyDefinitionVersionParam, nil)
	if respErr := server.GetError(errRespr, req); respErr != nil {
		return nil, respErr
	}
	respContent := server.GetResponseContent(respr)
	if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) {
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)}
	}
	resp, err := server.NewResponse(respContent, req, nil)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *SetDefinitionVersionsServerTransport) dispatchDeleteAtManagementGroup(req *http.Request) (*http.Response, error) {
	if s.srv.DeleteAtManagementGroup == nil {
		return nil, &nonRetriableError{errors.New("fake for method DeleteAtManagementGroup not implemented")}
	}
	const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P<managementGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions/(?P<policySetDefinitionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?P<policyDefinitionVersion>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if matches == nil || len(matches) < 3 {
		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
	}
	managementGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupName")])
	if err != nil {
		return nil, err
	}
	policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")])
	if err != nil {
		return nil, err
	}
	policyDefinitionVersionParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyDefinitionVersion")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := s.srv.DeleteAtManagementGroup(req.Context(), managementGroupNameParam, policySetDefinitionNameParam, policyDefinitionVersionParam, nil)
	if respErr := server.GetError(errRespr, req); respErr != nil {
		return nil, respErr
	}
	respContent := server.GetResponseContent(respr)
	if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) {
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)}
	}
	resp, err := server.NewResponse(respContent, req, nil)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *SetDefinitionVersionsServerTransport) 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~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions/(?P<policySetDefinitionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?P<policyDefinitionVersion>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if matches == nil || len(matches) < 3 {
		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
	}
	qp := req.URL.Query()
	policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")])
	if err != nil {
		return nil, err
	}
	policyDefinitionVersionParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyDefinitionVersion")])
	if err != nil {
		return nil, err
	}
	expandUnescaped, err := url.QueryUnescape(qp.Get("$expand"))
	if err != nil {
		return nil, err
	}
	expandParam := getOptional(expandUnescaped)
	var options *armpolicy.SetDefinitionVersionsClientGetOptions
	if expandParam != nil {
		options = &armpolicy.SetDefinitionVersionsClientGetOptions{
			Expand: expandParam,
		}
	}
	respr, errRespr := s.srv.Get(req.Context(), policySetDefinitionNameParam, policyDefinitionVersionParam, options)
	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).SetDefinitionVersion, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *SetDefinitionVersionsServerTransport) dispatchGetAtManagementGroup(req *http.Request) (*http.Response, error) {
	if s.srv.GetAtManagementGroup == nil {
		return nil, &nonRetriableError{errors.New("fake for method GetAtManagementGroup not implemented")}
	}
	const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P<managementGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions/(?P<policySetDefinitionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?P<policyDefinitionVersion>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if matches == nil || len(matches) < 3 {
		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
	}
	qp := req.URL.Query()
	managementGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupName")])
	if err != nil {
		return nil, err
	}
	policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")])
	if err != nil {
		return nil, err
	}
	policyDefinitionVersionParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyDefinitionVersion")])
	if err != nil {
		return nil, err
	}
	expandUnescaped, err := url.QueryUnescape(qp.Get("$expand"))
	if err != nil {
		return nil, err
	}
	expandParam := getOptional(expandUnescaped)
	var options *armpolicy.SetDefinitionVersionsClientGetAtManagementGroupOptions
	if expandParam != nil {
		options = &armpolicy.SetDefinitionVersionsClientGetAtManagementGroupOptions{
			Expand: expandParam,
		}
	}
	respr, errRespr := s.srv.GetAtManagementGroup(req.Context(), managementGroupNameParam, policySetDefinitionNameParam, policyDefinitionVersionParam, options)
	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).SetDefinitionVersion, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *SetDefinitionVersionsServerTransport) dispatchGetBuiltIn(req *http.Request) (*http.Response, error) {
	if s.srv.GetBuiltIn == nil {
		return nil, &nonRetriableError{errors.New("fake for method GetBuiltIn not implemented")}
	}
	const regexStr = `/providers/Microsoft\.Authorization/policySetDefinitions/(?P<policySetDefinitionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?P<policyDefinitionVersion>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if matches == nil || len(matches) < 2 {
		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
	}
	qp := req.URL.Query()
	policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")])
	if err != nil {
		return nil, err
	}
	policyDefinitionVersionParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyDefinitionVersion")])
	if err != nil {
		return nil, err
	}
	expandUnescaped, err := url.QueryUnescape(qp.Get("$expand"))
	if err != nil {
		return nil, err
	}
	expandParam := getOptional(expandUnescaped)
	var options *armpolicy.SetDefinitionVersionsClientGetBuiltInOptions
	if expandParam != nil {
		options = &armpolicy.SetDefinitionVersionsClientGetBuiltInOptions{
			Expand: expandParam,
		}
	}
	respr, errRespr := s.srv.GetBuiltIn(req.Context(), policySetDefinitionNameParam, policyDefinitionVersionParam, options)
	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).SetDefinitionVersion, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *SetDefinitionVersionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) {
	if s.srv.NewListPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")}
	}
	newListPager := s.newListPager.get(req)
	if newListPager == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions/(?P<policySetDefinitionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 2 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		qp := req.URL.Query()
		policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")])
		if err != nil {
			return nil, err
		}
		expandUnescaped, err := url.QueryUnescape(qp.Get("$expand"))
		if err != nil {
			return nil, err
		}
		expandParam := getOptional(expandUnescaped)
		topUnescaped, err := url.QueryUnescape(qp.Get("$top"))
		if err != nil {
			return nil, err
		}
		topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) {
			p, parseErr := strconv.ParseInt(v, 10, 32)
			if parseErr != nil {
				return 0, parseErr
			}
			return int32(p), nil
		})
		if err != nil {
			return nil, err
		}
		var options *armpolicy.SetDefinitionVersionsClientListOptions
		if expandParam != nil || topParam != nil {
			options = &armpolicy.SetDefinitionVersionsClientListOptions{
				Expand: expandParam,
				Top:    topParam,
			}
		}
		resp := s.srv.NewListPager(policySetDefinitionNameParam, options)
		newListPager = &resp
		s.newListPager.add(req, newListPager)
		server.PagerResponderInjectNextLinks(newListPager, req, func(page *armpolicy.SetDefinitionVersionsClientListResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListPager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		s.newListPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListPager) {
		s.newListPager.remove(req)
	}
	return resp, nil
}

func (s *SetDefinitionVersionsServerTransport) dispatchListAll(req *http.Request) (*http.Response, error) {
	if s.srv.ListAll == nil {
		return nil, &nonRetriableError{errors.New("fake for method ListAll not implemented")}
	}
	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/listPolicySetDefinitionVersions`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if matches == nil || len(matches) < 1 {
		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
	}
	respr, errRespr := s.srv.ListAll(req.Context(), 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).SetDefinitionVersionListResult, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *SetDefinitionVersionsServerTransport) dispatchListAllAtManagementGroup(req *http.Request) (*http.Response, error) {
	if s.srv.ListAllAtManagementGroup == nil {
		return nil, &nonRetriableError{errors.New("fake for method ListAllAtManagementGroup not implemented")}
	}
	const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P<managementGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/listPolicySetDefinitionVersions`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if matches == nil || len(matches) < 1 {
		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
	}
	managementGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := s.srv.ListAllAtManagementGroup(req.Context(), managementGroupNameParam, 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).SetDefinitionVersionListResult, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *SetDefinitionVersionsServerTransport) dispatchListAllBuiltins(req *http.Request) (*http.Response, error) {
	if s.srv.ListAllBuiltins == nil {
		return nil, &nonRetriableError{errors.New("fake for method ListAllBuiltins not implemented")}
	}
	respr, errRespr := s.srv.ListAllBuiltins(req.Context(), 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).SetDefinitionVersionListResult, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *SetDefinitionVersionsServerTransport) dispatchNewListBuiltInPager(req *http.Request) (*http.Response, error) {
	if s.srv.NewListBuiltInPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListBuiltInPager not implemented")}
	}
	newListBuiltInPager := s.newListBuiltInPager.get(req)
	if newListBuiltInPager == nil {
		const regexStr = `/providers/Microsoft\.Authorization/policySetDefinitions/(?P<policySetDefinitionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 1 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		qp := req.URL.Query()
		policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")])
		if err != nil {
			return nil, err
		}
		expandUnescaped, err := url.QueryUnescape(qp.Get("$expand"))
		if err != nil {
			return nil, err
		}
		expandParam := getOptional(expandUnescaped)
		topUnescaped, err := url.QueryUnescape(qp.Get("$top"))
		if err != nil {
			return nil, err
		}
		topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) {
			p, parseErr := strconv.ParseInt(v, 10, 32)
			if parseErr != nil {
				return 0, parseErr
			}
			return int32(p), nil
		})
		if err != nil {
			return nil, err
		}
		var options *armpolicy.SetDefinitionVersionsClientListBuiltInOptions
		if expandParam != nil || topParam != nil {
			options = &armpolicy.SetDefinitionVersionsClientListBuiltInOptions{
				Expand: expandParam,
				Top:    topParam,
			}
		}
		resp := s.srv.NewListBuiltInPager(policySetDefinitionNameParam, options)
		newListBuiltInPager = &resp
		s.newListBuiltInPager.add(req, newListBuiltInPager)
		server.PagerResponderInjectNextLinks(newListBuiltInPager, req, func(page *armpolicy.SetDefinitionVersionsClientListBuiltInResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListBuiltInPager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		s.newListBuiltInPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListBuiltInPager) {
		s.newListBuiltInPager.remove(req)
	}
	return resp, nil
}

func (s *SetDefinitionVersionsServerTransport) dispatchNewListByManagementGroupPager(req *http.Request) (*http.Response, error) {
	if s.srv.NewListByManagementGroupPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListByManagementGroupPager not implemented")}
	}
	newListByManagementGroupPager := s.newListByManagementGroupPager.get(req)
	if newListByManagementGroupPager == nil {
		const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P<managementGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Authorization/policySetDefinitions/(?P<policySetDefinitionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 2 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		qp := req.URL.Query()
		managementGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("managementGroupName")])
		if err != nil {
			return nil, err
		}
		policySetDefinitionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policySetDefinitionName")])
		if err != nil {
			return nil, err
		}
		expandUnescaped, err := url.QueryUnescape(qp.Get("$expand"))
		if err != nil {
			return nil, err
		}
		expandParam := getOptional(expandUnescaped)
		topUnescaped, err := url.QueryUnescape(qp.Get("$top"))
		if err != nil {
			return nil, err
		}
		topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) {
			p, parseErr := strconv.ParseInt(v, 10, 32)
			if parseErr != nil {
				return 0, parseErr
			}
			return int32(p), nil
		})
		if err != nil {
			return nil, err
		}
		var options *armpolicy.SetDefinitionVersionsClientListByManagementGroupOptions
		if expandParam != nil || topParam != nil {
			options = &armpolicy.SetDefinitionVersionsClientListByManagementGroupOptions{
				Expand: expandParam,
				Top:    topParam,
			}
		}
		resp := s.srv.NewListByManagementGroupPager(managementGroupNameParam, policySetDefinitionNameParam, options)
		newListByManagementGroupPager = &resp
		s.newListByManagementGroupPager.add(req, newListByManagementGroupPager)
		server.PagerResponderInjectNextLinks(newListByManagementGroupPager, req, func(page *armpolicy.SetDefinitionVersionsClientListByManagementGroupResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListByManagementGroupPager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		s.newListByManagementGroupPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListByManagementGroupPager) {
		s.newListByManagementGroupPager.remove(req)
	}
	return resp, nil
}

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