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

// Server is a fake server for instances of the armextensiontypes.Client type.
type Server struct {
	// ClusterGetVersion is the fake for method Client.ClusterGetVersion
	// HTTP status codes to indicate success: http.StatusOK
	ClusterGetVersion func(ctx context.Context, resourceGroupName string, clusterRp string, clusterResourceName string, clusterName string, extensionTypeName string, versionNumber string, options *armextensiontypes.ClientClusterGetVersionOptions) (resp azfake.Responder[armextensiontypes.ClientClusterGetVersionResponse], errResp azfake.ErrorResponder)

	// NewClusterListVersionsPager is the fake for method Client.NewClusterListVersionsPager
	// HTTP status codes to indicate success: http.StatusOK
	NewClusterListVersionsPager func(resourceGroupName string, clusterRp string, clusterResourceName string, clusterName string, extensionTypeName string, options *armextensiontypes.ClientClusterListVersionsOptions) (resp azfake.PagerResponder[armextensiontypes.ClientClusterListVersionsResponse])

	// Get is the fake for method Client.Get
	// HTTP status codes to indicate success: http.StatusOK
	Get func(ctx context.Context, resourceGroupName string, clusterRp string, clusterResourceName string, clusterName string, extensionTypeName string, options *armextensiontypes.ClientGetOptions) (resp azfake.Responder[armextensiontypes.ClientGetResponse], errResp azfake.ErrorResponder)

	// GetVersion is the fake for method Client.GetVersion
	// HTTP status codes to indicate success: http.StatusOK
	GetVersion func(ctx context.Context, location string, extensionTypeName string, versionNumber string, options *armextensiontypes.ClientGetVersionOptions) (resp azfake.Responder[armextensiontypes.ClientGetVersionResponse], errResp azfake.ErrorResponder)

	// NewListPager is the fake for method Client.NewListPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListPager func(resourceGroupName string, clusterRp string, clusterResourceName string, clusterName string, options *armextensiontypes.ClientListOptions) (resp azfake.PagerResponder[armextensiontypes.ClientListResponse])

	// NewListVersionsPager is the fake for method Client.NewListVersionsPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListVersionsPager func(location string, extensionTypeName string, options *armextensiontypes.ClientListVersionsOptions) (resp azfake.PagerResponder[armextensiontypes.ClientListVersionsResponse])

	// LocationGet is the fake for method Client.LocationGet
	// HTTP status codes to indicate success: http.StatusOK
	LocationGet func(ctx context.Context, location string, extensionTypeName string, options *armextensiontypes.ClientLocationGetOptions) (resp azfake.Responder[armextensiontypes.ClientLocationGetResponse], errResp azfake.ErrorResponder)

	// NewLocationListPager is the fake for method Client.NewLocationListPager
	// HTTP status codes to indicate success: http.StatusOK
	NewLocationListPager func(location string, options *armextensiontypes.ClientLocationListOptions) (resp azfake.PagerResponder[armextensiontypes.ClientLocationListResponse])
}

// NewServerTransport creates a new instance of ServerTransport with the provided implementation.
// The returned ServerTransport instance is connected to an instance of armextensiontypes.Client via the
// azcore.ClientOptions.Transporter field in the client's constructor parameters.
func NewServerTransport(srv *Server) *ServerTransport {
	return &ServerTransport{
		srv:                         srv,
		newClusterListVersionsPager: newTracker[azfake.PagerResponder[armextensiontypes.ClientClusterListVersionsResponse]](),
		newListPager:                newTracker[azfake.PagerResponder[armextensiontypes.ClientListResponse]](),
		newListVersionsPager:        newTracker[azfake.PagerResponder[armextensiontypes.ClientListVersionsResponse]](),
		newLocationListPager:        newTracker[azfake.PagerResponder[armextensiontypes.ClientLocationListResponse]](),
	}
}

// ServerTransport connects instances of armextensiontypes.Client to instances of Server.
// Don't use this type directly, use NewServerTransport instead.
type ServerTransport struct {
	srv                         *Server
	newClusterListVersionsPager *tracker[azfake.PagerResponder[armextensiontypes.ClientClusterListVersionsResponse]]
	newListPager                *tracker[azfake.PagerResponder[armextensiontypes.ClientListResponse]]
	newListVersionsPager        *tracker[azfake.PagerResponder[armextensiontypes.ClientListVersionsResponse]]
	newLocationListPager        *tracker[azfake.PagerResponder[armextensiontypes.ClientLocationListResponse]]
}

// Do implements the policy.Transporter interface for ServerTransport.
func (s *ServerTransport) 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 *ServerTransport) 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 serverTransportInterceptor != nil {
			res.resp, res.err, intercepted = serverTransportInterceptor.Do(req)
		}
		if !intercepted {
			switch method {
			case "Client.ClusterGetVersion":
				res.resp, res.err = s.dispatchClusterGetVersion(req)
			case "Client.NewClusterListVersionsPager":
				res.resp, res.err = s.dispatchNewClusterListVersionsPager(req)
			case "Client.Get":
				res.resp, res.err = s.dispatchGet(req)
			case "Client.GetVersion":
				res.resp, res.err = s.dispatchGetVersion(req)
			case "Client.NewListPager":
				res.resp, res.err = s.dispatchNewListPager(req)
			case "Client.NewListVersionsPager":
				res.resp, res.err = s.dispatchNewListVersionsPager(req)
			case "Client.LocationGet":
				res.resp, res.err = s.dispatchLocationGet(req)
			case "Client.NewLocationListPager":
				res.resp, res.err = s.dispatchNewLocationListPager(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 *ServerTransport) dispatchClusterGetVersion(req *http.Request) (*http.Response, error) {
	if s.srv.ClusterGetVersion == nil {
		return nil, &nonRetriableError{errors.New("fake for method ClusterGetVersion not implemented")}
	}
	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P<clusterRp>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P<clusterResourceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.KubernetesConfiguration/extensionTypes/(?P<extensionTypeName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?P<versionNumber>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if matches == nil || len(matches) < 7 {
		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
	}
	clusterRpParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterRp")])
	if err != nil {
		return nil, err
	}
	clusterResourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterResourceName")])
	if err != nil {
		return nil, err
	}
	clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
	if err != nil {
		return nil, err
	}
	extensionTypeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("extensionTypeName")])
	if err != nil {
		return nil, err
	}
	versionNumberParam, err := url.PathUnescape(matches[regex.SubexpIndex("versionNumber")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := s.srv.ClusterGetVersion(req.Context(), resourceGroupNameParam, clusterRpParam, clusterResourceNameParam, clusterNameParam, extensionTypeNameParam, versionNumberParam, 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).ExtensionTypeVersionForReleaseTrain, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *ServerTransport) dispatchNewClusterListVersionsPager(req *http.Request) (*http.Response, error) {
	if s.srv.NewClusterListVersionsPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewClusterListVersionsPager not implemented")}
	}
	newClusterListVersionsPager := s.newClusterListVersionsPager.get(req)
	if newClusterListVersionsPager == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P<clusterRp>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P<clusterResourceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.KubernetesConfiguration/extensionTypes/(?P<extensionTypeName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 6 {
			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
		}
		clusterRpParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterRp")])
		if err != nil {
			return nil, err
		}
		clusterResourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterResourceName")])
		if err != nil {
			return nil, err
		}
		clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
		if err != nil {
			return nil, err
		}
		extensionTypeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("extensionTypeName")])
		if err != nil {
			return nil, err
		}
		releaseTrainUnescaped, err := url.QueryUnescape(qp.Get("releaseTrain"))
		if err != nil {
			return nil, err
		}
		releaseTrainParam := getOptional(releaseTrainUnescaped)
		majorVersionUnescaped, err := url.QueryUnescape(qp.Get("majorVersion"))
		if err != nil {
			return nil, err
		}
		majorVersionParam := getOptional(majorVersionUnescaped)
		showLatestUnescaped, err := url.QueryUnescape(qp.Get("showLatest"))
		if err != nil {
			return nil, err
		}
		showLatestParam, err := parseOptional(showLatestUnescaped, strconv.ParseBool)
		if err != nil {
			return nil, err
		}
		var options *armextensiontypes.ClientClusterListVersionsOptions
		if releaseTrainParam != nil || majorVersionParam != nil || showLatestParam != nil {
			options = &armextensiontypes.ClientClusterListVersionsOptions{
				ReleaseTrain: releaseTrainParam,
				MajorVersion: majorVersionParam,
				ShowLatest:   showLatestParam,
			}
		}
		resp := s.srv.NewClusterListVersionsPager(resourceGroupNameParam, clusterRpParam, clusterResourceNameParam, clusterNameParam, extensionTypeNameParam, options)
		newClusterListVersionsPager = &resp
		s.newClusterListVersionsPager.add(req, newClusterListVersionsPager)
		server.PagerResponderInjectNextLinks(newClusterListVersionsPager, req, func(page *armextensiontypes.ClientClusterListVersionsResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newClusterListVersionsPager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		s.newClusterListVersionsPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newClusterListVersionsPager) {
		s.newClusterListVersionsPager.remove(req)
	}
	return resp, nil
}

func (s *ServerTransport) 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/(?P<clusterRp>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P<clusterResourceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.KubernetesConfiguration/extensionTypes/(?P<extensionTypeName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if matches == nil || len(matches) < 6 {
		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
	}
	clusterRpParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterRp")])
	if err != nil {
		return nil, err
	}
	clusterResourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterResourceName")])
	if err != nil {
		return nil, err
	}
	clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
	if err != nil {
		return nil, err
	}
	extensionTypeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("extensionTypeName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := s.srv.Get(req.Context(), resourceGroupNameParam, clusterRpParam, clusterResourceNameParam, clusterNameParam, extensionTypeNameParam, 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).ExtensionType, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *ServerTransport) dispatchGetVersion(req *http.Request) (*http.Response, error) {
	if s.srv.GetVersion == nil {
		return nil, &nonRetriableError{errors.New("fake for method GetVersion not implemented")}
	}
	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.KubernetesConfiguration/locations/(?P<location>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensionTypes/(?P<extensionTypeName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions/(?P<versionNumber>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if matches == nil || len(matches) < 4 {
		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
	}
	locationParam, err := url.PathUnescape(matches[regex.SubexpIndex("location")])
	if err != nil {
		return nil, err
	}
	extensionTypeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("extensionTypeName")])
	if err != nil {
		return nil, err
	}
	versionNumberParam, err := url.PathUnescape(matches[regex.SubexpIndex("versionNumber")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := s.srv.GetVersion(req.Context(), locationParam, extensionTypeNameParam, versionNumberParam, 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).ExtensionTypeVersionForReleaseTrain, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *ServerTransport) 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~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P<clusterRp>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P<clusterResourceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/(?P<clusterName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.KubernetesConfiguration/extensionTypes`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if matches == nil || len(matches) < 5 {
			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
		}
		clusterRpParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterRp")])
		if err != nil {
			return nil, err
		}
		clusterResourceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterResourceName")])
		if err != nil {
			return nil, err
		}
		clusterNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("clusterName")])
		if err != nil {
			return nil, err
		}
		publisherIDUnescaped, err := url.QueryUnescape(qp.Get("publisherId"))
		if err != nil {
			return nil, err
		}
		publisherIDParam := getOptional(publisherIDUnescaped)
		offerIDUnescaped, err := url.QueryUnescape(qp.Get("offerId"))
		if err != nil {
			return nil, err
		}
		offerIDParam := getOptional(offerIDUnescaped)
		planIDUnescaped, err := url.QueryUnescape(qp.Get("planId"))
		if err != nil {
			return nil, err
		}
		planIDParam := getOptional(planIDUnescaped)
		releaseTrainUnescaped, err := url.QueryUnescape(qp.Get("releaseTrain"))
		if err != nil {
			return nil, err
		}
		releaseTrainParam := getOptional(releaseTrainUnescaped)
		var options *armextensiontypes.ClientListOptions
		if publisherIDParam != nil || offerIDParam != nil || planIDParam != nil || releaseTrainParam != nil {
			options = &armextensiontypes.ClientListOptions{
				PublisherID:  publisherIDParam,
				OfferID:      offerIDParam,
				PlanID:       planIDParam,
				ReleaseTrain: releaseTrainParam,
			}
		}
		resp := s.srv.NewListPager(resourceGroupNameParam, clusterRpParam, clusterResourceNameParam, clusterNameParam, options)
		newListPager = &resp
		s.newListPager.add(req, newListPager)
		server.PagerResponderInjectNextLinks(newListPager, req, func(page *armextensiontypes.ClientListResponse, 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 *ServerTransport) dispatchNewListVersionsPager(req *http.Request) (*http.Response, error) {
	if s.srv.NewListVersionsPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListVersionsPager not implemented")}
	}
	newListVersionsPager := s.newListVersionsPager.get(req)
	if newListVersionsPager == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.KubernetesConfiguration/locations/(?P<location>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensionTypes/(?P<extensionTypeName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/versions`
		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()
		locationParam, err := url.PathUnescape(matches[regex.SubexpIndex("location")])
		if err != nil {
			return nil, err
		}
		extensionTypeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("extensionTypeName")])
		if err != nil {
			return nil, err
		}
		releaseTrainUnescaped, err := url.QueryUnescape(qp.Get("releaseTrain"))
		if err != nil {
			return nil, err
		}
		releaseTrainParam := getOptional(releaseTrainUnescaped)
		clusterTypeUnescaped, err := url.QueryUnescape(qp.Get("clusterType"))
		if err != nil {
			return nil, err
		}
		clusterTypeParam := getOptional(clusterTypeUnescaped)
		majorVersionUnescaped, err := url.QueryUnescape(qp.Get("majorVersion"))
		if err != nil {
			return nil, err
		}
		majorVersionParam := getOptional(majorVersionUnescaped)
		showLatestUnescaped, err := url.QueryUnescape(qp.Get("showLatest"))
		if err != nil {
			return nil, err
		}
		showLatestParam, err := parseOptional(showLatestUnescaped, strconv.ParseBool)
		if err != nil {
			return nil, err
		}
		var options *armextensiontypes.ClientListVersionsOptions
		if releaseTrainParam != nil || clusterTypeParam != nil || majorVersionParam != nil || showLatestParam != nil {
			options = &armextensiontypes.ClientListVersionsOptions{
				ReleaseTrain: releaseTrainParam,
				ClusterType:  clusterTypeParam,
				MajorVersion: majorVersionParam,
				ShowLatest:   showLatestParam,
			}
		}
		resp := s.srv.NewListVersionsPager(locationParam, extensionTypeNameParam, options)
		newListVersionsPager = &resp
		s.newListVersionsPager.add(req, newListVersionsPager)
		server.PagerResponderInjectNextLinks(newListVersionsPager, req, func(page *armextensiontypes.ClientListVersionsResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListVersionsPager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		s.newListVersionsPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListVersionsPager) {
		s.newListVersionsPager.remove(req)
	}
	return resp, nil
}

func (s *ServerTransport) dispatchLocationGet(req *http.Request) (*http.Response, error) {
	if s.srv.LocationGet == nil {
		return nil, &nonRetriableError{errors.New("fake for method LocationGet not implemented")}
	}
	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.KubernetesConfiguration/locations/(?P<location>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensionTypes/(?P<extensionTypeName>[!#&$-;=?-\[\]_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)
	}
	locationParam, err := url.PathUnescape(matches[regex.SubexpIndex("location")])
	if err != nil {
		return nil, err
	}
	extensionTypeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("extensionTypeName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := s.srv.LocationGet(req.Context(), locationParam, extensionTypeNameParam, 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).ExtensionType, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *ServerTransport) dispatchNewLocationListPager(req *http.Request) (*http.Response, error) {
	if s.srv.NewLocationListPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewLocationListPager not implemented")}
	}
	newLocationListPager := s.newLocationListPager.get(req)
	if newLocationListPager == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.KubernetesConfiguration/locations/(?P<location>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/extensionTypes`
		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()
		locationParam, err := url.PathUnescape(matches[regex.SubexpIndex("location")])
		if err != nil {
			return nil, err
		}
		publisherIDUnescaped, err := url.QueryUnescape(qp.Get("publisherId"))
		if err != nil {
			return nil, err
		}
		publisherIDParam := getOptional(publisherIDUnescaped)
		offerIDUnescaped, err := url.QueryUnescape(qp.Get("offerId"))
		if err != nil {
			return nil, err
		}
		offerIDParam := getOptional(offerIDUnescaped)
		planIDUnescaped, err := url.QueryUnescape(qp.Get("planId"))
		if err != nil {
			return nil, err
		}
		planIDParam := getOptional(planIDUnescaped)
		releaseTrainUnescaped, err := url.QueryUnescape(qp.Get("releaseTrain"))
		if err != nil {
			return nil, err
		}
		releaseTrainParam := getOptional(releaseTrainUnescaped)
		clusterTypeUnescaped, err := url.QueryUnescape(qp.Get("clusterType"))
		if err != nil {
			return nil, err
		}
		clusterTypeParam := getOptional(clusterTypeUnescaped)
		var options *armextensiontypes.ClientLocationListOptions
		if publisherIDParam != nil || offerIDParam != nil || planIDParam != nil || releaseTrainParam != nil || clusterTypeParam != nil {
			options = &armextensiontypes.ClientLocationListOptions{
				PublisherID:  publisherIDParam,
				OfferID:      offerIDParam,
				PlanID:       planIDParam,
				ReleaseTrain: releaseTrainParam,
				ClusterType:  clusterTypeParam,
			}
		}
		resp := s.srv.NewLocationListPager(locationParam, options)
		newLocationListPager = &resp
		s.newLocationListPager.add(req, newLocationListPager)
		server.PagerResponderInjectNextLinks(newLocationListPager, req, func(page *armextensiontypes.ClientLocationListResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newLocationListPager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		s.newLocationListPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newLocationListPager) {
		s.newLocationListPager.remove(req)
	}
	return resp, nil
}

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