// 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/postgresql/armpostgresqlflexibleservers/v5"
	"net/http"
	"net/url"
	"regexp"
)

// TuningConfigurationServer is a fake server for instances of the armpostgresqlflexibleservers.TuningConfigurationClient type.
type TuningConfigurationServer struct {
	// BeginDisable is the fake for method TuningConfigurationClient.BeginDisable
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginDisable func(ctx context.Context, resourceGroupName string, serverName string, tuningOption armpostgresqlflexibleservers.TuningOptionEnum, options *armpostgresqlflexibleservers.TuningConfigurationClientBeginDisableOptions) (resp azfake.PollerResponder[armpostgresqlflexibleservers.TuningConfigurationClientDisableResponse], errResp azfake.ErrorResponder)

	// BeginEnable is the fake for method TuningConfigurationClient.BeginEnable
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginEnable func(ctx context.Context, resourceGroupName string, serverName string, tuningOption armpostgresqlflexibleservers.TuningOptionEnum, options *armpostgresqlflexibleservers.TuningConfigurationClientBeginEnableOptions) (resp azfake.PollerResponder[armpostgresqlflexibleservers.TuningConfigurationClientEnableResponse], errResp azfake.ErrorResponder)

	// NewListSessionDetailsPager is the fake for method TuningConfigurationClient.NewListSessionDetailsPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListSessionDetailsPager func(resourceGroupName string, serverName string, tuningOption armpostgresqlflexibleservers.TuningOptionEnum, sessionID string, options *armpostgresqlflexibleservers.TuningConfigurationClientListSessionDetailsOptions) (resp azfake.PagerResponder[armpostgresqlflexibleservers.TuningConfigurationClientListSessionDetailsResponse])

	// NewListSessionsPager is the fake for method TuningConfigurationClient.NewListSessionsPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListSessionsPager func(resourceGroupName string, serverName string, tuningOption armpostgresqlflexibleservers.TuningOptionEnum, options *armpostgresqlflexibleservers.TuningConfigurationClientListSessionsOptions) (resp azfake.PagerResponder[armpostgresqlflexibleservers.TuningConfigurationClientListSessionsResponse])

	// BeginStartSession is the fake for method TuningConfigurationClient.BeginStartSession
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginStartSession func(ctx context.Context, resourceGroupName string, serverName string, tuningOption armpostgresqlflexibleservers.TuningOptionEnum, configTuningRequest armpostgresqlflexibleservers.ConfigTuningRequestParameter, options *armpostgresqlflexibleservers.TuningConfigurationClientBeginStartSessionOptions) (resp azfake.PollerResponder[armpostgresqlflexibleservers.TuningConfigurationClientStartSessionResponse], errResp azfake.ErrorResponder)

	// BeginStopSession is the fake for method TuningConfigurationClient.BeginStopSession
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginStopSession func(ctx context.Context, resourceGroupName string, serverName string, tuningOption armpostgresqlflexibleservers.TuningOptionEnum, options *armpostgresqlflexibleservers.TuningConfigurationClientBeginStopSessionOptions) (resp azfake.PollerResponder[armpostgresqlflexibleservers.TuningConfigurationClientStopSessionResponse], errResp azfake.ErrorResponder)
}

// NewTuningConfigurationServerTransport creates a new instance of TuningConfigurationServerTransport with the provided implementation.
// The returned TuningConfigurationServerTransport instance is connected to an instance of armpostgresqlflexibleservers.TuningConfigurationClient via the
// azcore.ClientOptions.Transporter field in the client's constructor parameters.
func NewTuningConfigurationServerTransport(srv *TuningConfigurationServer) *TuningConfigurationServerTransport {
	return &TuningConfigurationServerTransport{
		srv:                        srv,
		beginDisable:               newTracker[azfake.PollerResponder[armpostgresqlflexibleservers.TuningConfigurationClientDisableResponse]](),
		beginEnable:                newTracker[azfake.PollerResponder[armpostgresqlflexibleservers.TuningConfigurationClientEnableResponse]](),
		newListSessionDetailsPager: newTracker[azfake.PagerResponder[armpostgresqlflexibleservers.TuningConfigurationClientListSessionDetailsResponse]](),
		newListSessionsPager:       newTracker[azfake.PagerResponder[armpostgresqlflexibleservers.TuningConfigurationClientListSessionsResponse]](),
		beginStartSession:          newTracker[azfake.PollerResponder[armpostgresqlflexibleservers.TuningConfigurationClientStartSessionResponse]](),
		beginStopSession:           newTracker[azfake.PollerResponder[armpostgresqlflexibleservers.TuningConfigurationClientStopSessionResponse]](),
	}
}

// TuningConfigurationServerTransport connects instances of armpostgresqlflexibleservers.TuningConfigurationClient to instances of TuningConfigurationServer.
// Don't use this type directly, use NewTuningConfigurationServerTransport instead.
type TuningConfigurationServerTransport struct {
	srv                        *TuningConfigurationServer
	beginDisable               *tracker[azfake.PollerResponder[armpostgresqlflexibleservers.TuningConfigurationClientDisableResponse]]
	beginEnable                *tracker[azfake.PollerResponder[armpostgresqlflexibleservers.TuningConfigurationClientEnableResponse]]
	newListSessionDetailsPager *tracker[azfake.PagerResponder[armpostgresqlflexibleservers.TuningConfigurationClientListSessionDetailsResponse]]
	newListSessionsPager       *tracker[azfake.PagerResponder[armpostgresqlflexibleservers.TuningConfigurationClientListSessionsResponse]]
	beginStartSession          *tracker[azfake.PollerResponder[armpostgresqlflexibleservers.TuningConfigurationClientStartSessionResponse]]
	beginStopSession           *tracker[azfake.PollerResponder[armpostgresqlflexibleservers.TuningConfigurationClientStopSessionResponse]]
}

// Do implements the policy.Transporter interface for TuningConfigurationServerTransport.
func (t *TuningConfigurationServerTransport) 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 *TuningConfigurationServerTransport) 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 tuningConfigurationServerTransportInterceptor != nil {
			res.resp, res.err, intercepted = tuningConfigurationServerTransportInterceptor.Do(req)
		}
		if !intercepted {
			switch method {
			case "TuningConfigurationClient.BeginDisable":
				res.resp, res.err = t.dispatchBeginDisable(req)
			case "TuningConfigurationClient.BeginEnable":
				res.resp, res.err = t.dispatchBeginEnable(req)
			case "TuningConfigurationClient.NewListSessionDetailsPager":
				res.resp, res.err = t.dispatchNewListSessionDetailsPager(req)
			case "TuningConfigurationClient.NewListSessionsPager":
				res.resp, res.err = t.dispatchNewListSessionsPager(req)
			case "TuningConfigurationClient.BeginStartSession":
				res.resp, res.err = t.dispatchBeginStartSession(req)
			case "TuningConfigurationClient.BeginStopSession":
				res.resp, res.err = t.dispatchBeginStopSession(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 *TuningConfigurationServerTransport) dispatchBeginDisable(req *http.Request) (*http.Response, error) {
	if t.srv.BeginDisable == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginDisable not implemented")}
	}
	beginDisable := t.beginDisable.get(req)
	if beginDisable == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DBforPostgreSQL/flexibleServers/(?P<serverName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tuningOptions/(?P<tuningOption>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/disable`
		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)
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		serverNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("serverName")])
		if err != nil {
			return nil, err
		}
		tuningOptionParam, err := parseWithCast(matches[regex.SubexpIndex("tuningOption")], func(v string) (armpostgresqlflexibleservers.TuningOptionEnum, error) {
			p, unescapeErr := url.PathUnescape(v)
			if unescapeErr != nil {
				return "", unescapeErr
			}
			return armpostgresqlflexibleservers.TuningOptionEnum(p), nil
		})
		if err != nil {
			return nil, err
		}
		respr, errRespr := t.srv.BeginDisable(req.Context(), resourceGroupNameParam, serverNameParam, tuningOptionParam, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginDisable = &respr
		t.beginDisable.add(req, beginDisable)
	}

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

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

	return resp, nil
}

func (t *TuningConfigurationServerTransport) dispatchBeginEnable(req *http.Request) (*http.Response, error) {
	if t.srv.BeginEnable == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginEnable not implemented")}
	}
	beginEnable := t.beginEnable.get(req)
	if beginEnable == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DBforPostgreSQL/flexibleServers/(?P<serverName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tuningOptions/(?P<tuningOption>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/enable`
		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)
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		serverNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("serverName")])
		if err != nil {
			return nil, err
		}
		tuningOptionParam, err := parseWithCast(matches[regex.SubexpIndex("tuningOption")], func(v string) (armpostgresqlflexibleservers.TuningOptionEnum, error) {
			p, unescapeErr := url.PathUnescape(v)
			if unescapeErr != nil {
				return "", unescapeErr
			}
			return armpostgresqlflexibleservers.TuningOptionEnum(p), nil
		})
		if err != nil {
			return nil, err
		}
		respr, errRespr := t.srv.BeginEnable(req.Context(), resourceGroupNameParam, serverNameParam, tuningOptionParam, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginEnable = &respr
		t.beginEnable.add(req, beginEnable)
	}

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

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

	return resp, nil
}

func (t *TuningConfigurationServerTransport) dispatchNewListSessionDetailsPager(req *http.Request) (*http.Response, error) {
	if t.srv.NewListSessionDetailsPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListSessionDetailsPager not implemented")}
	}
	newListSessionDetailsPager := t.newListSessionDetailsPager.get(req)
	if newListSessionDetailsPager == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DBforPostgreSQL/flexibleServers/(?P<serverName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tuningOptions/(?P<tuningOption>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/sessionDetails`
		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)
		}
		qp := req.URL.Query()
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		serverNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("serverName")])
		if err != nil {
			return nil, err
		}
		tuningOptionParam, err := parseWithCast(matches[regex.SubexpIndex("tuningOption")], func(v string) (armpostgresqlflexibleservers.TuningOptionEnum, error) {
			p, unescapeErr := url.PathUnescape(v)
			if unescapeErr != nil {
				return "", unescapeErr
			}
			return armpostgresqlflexibleservers.TuningOptionEnum(p), nil
		})
		if err != nil {
			return nil, err
		}
		sessionIDParam, err := url.QueryUnescape(qp.Get("sessionId"))
		if err != nil {
			return nil, err
		}
		resp := t.srv.NewListSessionDetailsPager(resourceGroupNameParam, serverNameParam, tuningOptionParam, sessionIDParam, nil)
		newListSessionDetailsPager = &resp
		t.newListSessionDetailsPager.add(req, newListSessionDetailsPager)
		server.PagerResponderInjectNextLinks(newListSessionDetailsPager, req, func(page *armpostgresqlflexibleservers.TuningConfigurationClientListSessionDetailsResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListSessionDetailsPager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		t.newListSessionDetailsPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListSessionDetailsPager) {
		t.newListSessionDetailsPager.remove(req)
	}
	return resp, nil
}

func (t *TuningConfigurationServerTransport) dispatchNewListSessionsPager(req *http.Request) (*http.Response, error) {
	if t.srv.NewListSessionsPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListSessionsPager not implemented")}
	}
	newListSessionsPager := t.newListSessionsPager.get(req)
	if newListSessionsPager == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DBforPostgreSQL/flexibleServers/(?P<serverName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tuningOptions/(?P<tuningOption>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/sessions`
		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)
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		serverNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("serverName")])
		if err != nil {
			return nil, err
		}
		tuningOptionParam, err := parseWithCast(matches[regex.SubexpIndex("tuningOption")], func(v string) (armpostgresqlflexibleservers.TuningOptionEnum, error) {
			p, unescapeErr := url.PathUnescape(v)
			if unescapeErr != nil {
				return "", unescapeErr
			}
			return armpostgresqlflexibleservers.TuningOptionEnum(p), nil
		})
		if err != nil {
			return nil, err
		}
		resp := t.srv.NewListSessionsPager(resourceGroupNameParam, serverNameParam, tuningOptionParam, nil)
		newListSessionsPager = &resp
		t.newListSessionsPager.add(req, newListSessionsPager)
		server.PagerResponderInjectNextLinks(newListSessionsPager, req, func(page *armpostgresqlflexibleservers.TuningConfigurationClientListSessionsResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListSessionsPager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		t.newListSessionsPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListSessionsPager) {
		t.newListSessionsPager.remove(req)
	}
	return resp, nil
}

func (t *TuningConfigurationServerTransport) dispatchBeginStartSession(req *http.Request) (*http.Response, error) {
	if t.srv.BeginStartSession == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginStartSession not implemented")}
	}
	beginStartSession := t.beginStartSession.get(req)
	if beginStartSession == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DBforPostgreSQL/flexibleServers/(?P<serverName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tuningOptions/(?P<tuningOption>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/startSession`
		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)
		}
		body, err := server.UnmarshalRequestAsJSON[armpostgresqlflexibleservers.ConfigTuningRequestParameter](req)
		if err != nil {
			return nil, err
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		serverNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("serverName")])
		if err != nil {
			return nil, err
		}
		tuningOptionParam, err := parseWithCast(matches[regex.SubexpIndex("tuningOption")], func(v string) (armpostgresqlflexibleservers.TuningOptionEnum, error) {
			p, unescapeErr := url.PathUnescape(v)
			if unescapeErr != nil {
				return "", unescapeErr
			}
			return armpostgresqlflexibleservers.TuningOptionEnum(p), nil
		})
		if err != nil {
			return nil, err
		}
		respr, errRespr := t.srv.BeginStartSession(req.Context(), resourceGroupNameParam, serverNameParam, tuningOptionParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginStartSession = &respr
		t.beginStartSession.add(req, beginStartSession)
	}

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

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

	return resp, nil
}

func (t *TuningConfigurationServerTransport) dispatchBeginStopSession(req *http.Request) (*http.Response, error) {
	if t.srv.BeginStopSession == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginStopSession not implemented")}
	}
	beginStopSession := t.beginStopSession.get(req)
	if beginStopSession == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.DBforPostgreSQL/flexibleServers/(?P<serverName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/tuningOptions/(?P<tuningOption>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/stopSession`
		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)
		}
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		serverNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("serverName")])
		if err != nil {
			return nil, err
		}
		tuningOptionParam, err := parseWithCast(matches[regex.SubexpIndex("tuningOption")], func(v string) (armpostgresqlflexibleservers.TuningOptionEnum, error) {
			p, unescapeErr := url.PathUnescape(v)
			if unescapeErr != nil {
				return "", unescapeErr
			}
			return armpostgresqlflexibleservers.TuningOptionEnum(p), nil
		})
		if err != nil {
			return nil, err
		}
		respr, errRespr := t.srv.BeginStopSession(req.Context(), resourceGroupNameParam, serverNameParam, tuningOptionParam, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginStopSession = &respr
		t.beginStopSession.add(req, beginStopSession)
	}

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

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

	return resp, nil
}

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