// 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/resiliencemanagement/armresiliencemanagement"
	"net/http"
	"net/url"
	"regexp"
	"slices"
)

// DrillRunsServer is a fake server for instances of the armresiliencemanagement.DrillRunsClient type.
type DrillRunsServer struct {
	// BeginAddNotes is the fake for method DrillRunsClient.BeginAddNotes
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginAddNotes func(ctx context.Context, serviceGroupName string, operationID string, drillName string, drillRunName string, body armresiliencemanagement.DrillRunAddNotesRequest, options *armresiliencemanagement.DrillRunsClientBeginAddNotesOptions) (resp azfake.PollerResponder[armresiliencemanagement.DrillRunsClientAddNotesResponse], errResp azfake.ErrorResponder)

	// BeginFailOver is the fake for method DrillRunsClient.BeginFailOver
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginFailOver func(ctx context.Context, serviceGroupName string, operationID string, drillName string, drillRunName string, body armresiliencemanagement.DrillRunFailoverRequest, options *armresiliencemanagement.DrillRunsClientBeginFailOverOptions) (resp azfake.PollerResponder[armresiliencemanagement.DrillRunsClientFailOverResponse], errResp azfake.ErrorResponder)

	// Get is the fake for method DrillRunsClient.Get
	// HTTP status codes to indicate success: http.StatusOK
	Get func(ctx context.Context, serviceGroupName string, drillName string, drillRunName string, options *armresiliencemanagement.DrillRunsClientGetOptions) (resp azfake.Responder[armresiliencemanagement.DrillRunsClientGetResponse], errResp azfake.ErrorResponder)

	// NewListPager is the fake for method DrillRunsClient.NewListPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListPager func(serviceGroupName string, drillName string, options *armresiliencemanagement.DrillRunsClientListOptions) (resp azfake.PagerResponder[armresiliencemanagement.DrillRunsClientListResponse])

	// BeginMarkAsComplete is the fake for method DrillRunsClient.BeginMarkAsComplete
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginMarkAsComplete func(ctx context.Context, serviceGroupName string, operationID string, drillName string, drillRunName string, body armresiliencemanagement.MarkAsCompleteRequest, options *armresiliencemanagement.DrillRunsClientBeginMarkAsCompleteOptions) (resp azfake.PollerResponder[armresiliencemanagement.DrillRunsClientMarkAsCompleteResponse], errResp azfake.ErrorResponder)

	// BeginReprotect is the fake for method DrillRunsClient.BeginReprotect
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginReprotect func(ctx context.Context, serviceGroupName string, operationID string, drillName string, drillRunName string, options *armresiliencemanagement.DrillRunsClientBeginReprotectOptions) (resp azfake.PollerResponder[armresiliencemanagement.DrillRunsClientReprotectResponse], errResp azfake.ErrorResponder)

	// BeginResume is the fake for method DrillRunsClient.BeginResume
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginResume func(ctx context.Context, serviceGroupName string, operationID string, drillName string, drillRunName string, options *armresiliencemanagement.DrillRunsClientBeginResumeOptions) (resp azfake.PollerResponder[armresiliencemanagement.DrillRunsClientResumeResponse], errResp azfake.ErrorResponder)
}

// NewDrillRunsServerTransport creates a new instance of DrillRunsServerTransport with the provided implementation.
// The returned DrillRunsServerTransport instance is connected to an instance of armresiliencemanagement.DrillRunsClient via the
// azcore.ClientOptions.Transporter field in the client's constructor parameters.
func NewDrillRunsServerTransport(srv *DrillRunsServer) *DrillRunsServerTransport {
	return &DrillRunsServerTransport{
		srv:                 srv,
		beginAddNotes:       newTracker[azfake.PollerResponder[armresiliencemanagement.DrillRunsClientAddNotesResponse]](),
		beginFailOver:       newTracker[azfake.PollerResponder[armresiliencemanagement.DrillRunsClientFailOverResponse]](),
		newListPager:        newTracker[azfake.PagerResponder[armresiliencemanagement.DrillRunsClientListResponse]](),
		beginMarkAsComplete: newTracker[azfake.PollerResponder[armresiliencemanagement.DrillRunsClientMarkAsCompleteResponse]](),
		beginReprotect:      newTracker[azfake.PollerResponder[armresiliencemanagement.DrillRunsClientReprotectResponse]](),
		beginResume:         newTracker[azfake.PollerResponder[armresiliencemanagement.DrillRunsClientResumeResponse]](),
	}
}

// DrillRunsServerTransport connects instances of armresiliencemanagement.DrillRunsClient to instances of DrillRunsServer.
// Don't use this type directly, use NewDrillRunsServerTransport instead.
type DrillRunsServerTransport struct {
	srv                 *DrillRunsServer
	beginAddNotes       *tracker[azfake.PollerResponder[armresiliencemanagement.DrillRunsClientAddNotesResponse]]
	beginFailOver       *tracker[azfake.PollerResponder[armresiliencemanagement.DrillRunsClientFailOverResponse]]
	newListPager        *tracker[azfake.PagerResponder[armresiliencemanagement.DrillRunsClientListResponse]]
	beginMarkAsComplete *tracker[azfake.PollerResponder[armresiliencemanagement.DrillRunsClientMarkAsCompleteResponse]]
	beginReprotect      *tracker[azfake.PollerResponder[armresiliencemanagement.DrillRunsClientReprotectResponse]]
	beginResume         *tracker[azfake.PollerResponder[armresiliencemanagement.DrillRunsClientResumeResponse]]
}

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

func (d *DrillRunsServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) {
	resultChan := make(chan result, 1)
	go func() {
		var intercepted bool
		var res result
		if drillRunsServerTransportInterceptor != nil {
			res.resp, res.err, intercepted = drillRunsServerTransportInterceptor.Do(req)
		}
		if !intercepted {
			switch method {
			case "DrillRunsClient.BeginAddNotes":
				res.resp, res.err = d.dispatchBeginAddNotes(req)
			case "DrillRunsClient.BeginFailOver":
				res.resp, res.err = d.dispatchBeginFailOver(req)
			case "DrillRunsClient.Get":
				res.resp, res.err = d.dispatchGet(req)
			case "DrillRunsClient.NewListPager":
				res.resp, res.err = d.dispatchNewListPager(req)
			case "DrillRunsClient.BeginMarkAsComplete":
				res.resp, res.err = d.dispatchBeginMarkAsComplete(req)
			case "DrillRunsClient.BeginReprotect":
				res.resp, res.err = d.dispatchBeginReprotect(req)
			case "DrillRunsClient.BeginResume":
				res.resp, res.err = d.dispatchBeginResume(req)
			default:
				res.err = fmt.Errorf("unhandled API %s", method)
			}

		}
		resultChan <- res
	}()

	select {
	case <-req.Context().Done():
		return nil, req.Context().Err()
	case res := <-resultChan:
		return res.resp, res.err
	}
}

func (d *DrillRunsServerTransport) dispatchBeginAddNotes(req *http.Request) (*http.Response, error) {
	if d.srv.BeginAddNotes == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginAddNotes not implemented")}
	}
	beginAddNotes := d.beginAddNotes.get(req)
	if beginAddNotes == nil {
		const regexStr = `/providers/Microsoft\.Management/serviceGroups/(?P<serviceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.AzureResilienceManagement/drills/(?P<drillName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/drillRuns/(?P<drillRunName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/addNotes`
		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[armresiliencemanagement.DrillRunAddNotesRequest](req)
		if err != nil {
			return nil, err
		}
		serviceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("serviceGroupName")])
		if err != nil {
			return nil, err
		}
		drillNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("drillName")])
		if err != nil {
			return nil, err
		}
		drillRunNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("drillRunName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginAddNotes(req.Context(), serviceGroupNameParam, getHeaderValue(req.Header, "operation-id"), drillNameParam, drillRunNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginAddNotes = &respr
		d.beginAddNotes.add(req, beginAddNotes)
	}

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

	if !slices.Contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		d.beginAddNotes.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(beginAddNotes) {
		d.beginAddNotes.remove(req)
	}

	return resp, nil
}

func (d *DrillRunsServerTransport) dispatchBeginFailOver(req *http.Request) (*http.Response, error) {
	if d.srv.BeginFailOver == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginFailOver not implemented")}
	}
	beginFailOver := d.beginFailOver.get(req)
	if beginFailOver == nil {
		const regexStr = `/providers/Microsoft\.Management/serviceGroups/(?P<serviceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.AzureResilienceManagement/drills/(?P<drillName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/drillRuns/(?P<drillRunName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/failOver`
		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[armresiliencemanagement.DrillRunFailoverRequest](req)
		if err != nil {
			return nil, err
		}
		serviceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("serviceGroupName")])
		if err != nil {
			return nil, err
		}
		drillNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("drillName")])
		if err != nil {
			return nil, err
		}
		drillRunNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("drillRunName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginFailOver(req.Context(), serviceGroupNameParam, getHeaderValue(req.Header, "operation-id"), drillNameParam, drillRunNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginFailOver = &respr
		d.beginFailOver.add(req, beginFailOver)
	}

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

	if !slices.Contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		d.beginFailOver.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(beginFailOver) {
		d.beginFailOver.remove(req)
	}

	return resp, nil
}

func (d *DrillRunsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) {
	if d.srv.Get == nil {
		return nil, &nonRetriableError{errors.New("fake for method Get not implemented")}
	}
	const regexStr = `/providers/Microsoft\.Management/serviceGroups/(?P<serviceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.AzureResilienceManagement/drills/(?P<drillName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/drillRuns/(?P<drillRunName>[!#&$-;=?-\[\]_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)
	}
	serviceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("serviceGroupName")])
	if err != nil {
		return nil, err
	}
	drillNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("drillName")])
	if err != nil {
		return nil, err
	}
	drillRunNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("drillRunName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := d.srv.Get(req.Context(), serviceGroupNameParam, drillNameParam, drillRunNameParam, nil)
	if respErr := server.GetError(errRespr, req); respErr != nil {
		return nil, respErr
	}
	respContent := server.GetResponseContent(respr)
	if !slices.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).DrillRun, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (d *DrillRunsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) {
	if d.srv.NewListPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")}
	}
	newListPager := d.newListPager.get(req)
	if newListPager == nil {
		const regexStr = `/providers/Microsoft\.Management/serviceGroups/(?P<serviceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.AzureResilienceManagement/drills/(?P<drillName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/drillRuns`
		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)
		}
		serviceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("serviceGroupName")])
		if err != nil {
			return nil, err
		}
		drillNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("drillName")])
		if err != nil {
			return nil, err
		}
		resp := d.srv.NewListPager(serviceGroupNameParam, drillNameParam, nil)
		newListPager = &resp
		d.newListPager.add(req, newListPager)
		server.PagerResponderInjectNextLinks(newListPager, req, func(page *armresiliencemanagement.DrillRunsClientListResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListPager, req)
	if err != nil {
		return nil, err
	}
	if !slices.Contains([]int{http.StatusOK}, resp.StatusCode) {
		d.newListPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListPager) {
		d.newListPager.remove(req)
	}
	return resp, nil
}

func (d *DrillRunsServerTransport) dispatchBeginMarkAsComplete(req *http.Request) (*http.Response, error) {
	if d.srv.BeginMarkAsComplete == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginMarkAsComplete not implemented")}
	}
	beginMarkAsComplete := d.beginMarkAsComplete.get(req)
	if beginMarkAsComplete == nil {
		const regexStr = `/providers/Microsoft\.Management/serviceGroups/(?P<serviceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.AzureResilienceManagement/drills/(?P<drillName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/drillRuns/(?P<drillRunName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/markAsComplete`
		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[armresiliencemanagement.MarkAsCompleteRequest](req)
		if err != nil {
			return nil, err
		}
		serviceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("serviceGroupName")])
		if err != nil {
			return nil, err
		}
		drillNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("drillName")])
		if err != nil {
			return nil, err
		}
		drillRunNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("drillRunName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginMarkAsComplete(req.Context(), serviceGroupNameParam, getHeaderValue(req.Header, "operation-id"), drillNameParam, drillRunNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginMarkAsComplete = &respr
		d.beginMarkAsComplete.add(req, beginMarkAsComplete)
	}

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

	if !slices.Contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		d.beginMarkAsComplete.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(beginMarkAsComplete) {
		d.beginMarkAsComplete.remove(req)
	}

	return resp, nil
}

func (d *DrillRunsServerTransport) dispatchBeginReprotect(req *http.Request) (*http.Response, error) {
	if d.srv.BeginReprotect == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginReprotect not implemented")}
	}
	beginReprotect := d.beginReprotect.get(req)
	if beginReprotect == nil {
		const regexStr = `/providers/Microsoft\.Management/serviceGroups/(?P<serviceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.AzureResilienceManagement/drills/(?P<drillName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/drillRuns/(?P<drillRunName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/reprotect`
		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)
		}
		serviceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("serviceGroupName")])
		if err != nil {
			return nil, err
		}
		drillNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("drillName")])
		if err != nil {
			return nil, err
		}
		drillRunNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("drillRunName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginReprotect(req.Context(), serviceGroupNameParam, getHeaderValue(req.Header, "operation-id"), drillNameParam, drillRunNameParam, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginReprotect = &respr
		d.beginReprotect.add(req, beginReprotect)
	}

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

	if !slices.Contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		d.beginReprotect.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(beginReprotect) {
		d.beginReprotect.remove(req)
	}

	return resp, nil
}

func (d *DrillRunsServerTransport) dispatchBeginResume(req *http.Request) (*http.Response, error) {
	if d.srv.BeginResume == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginResume not implemented")}
	}
	beginResume := d.beginResume.get(req)
	if beginResume == nil {
		const regexStr = `/providers/Microsoft\.Management/serviceGroups/(?P<serviceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.AzureResilienceManagement/drills/(?P<drillName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/drillRuns/(?P<drillRunName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resume`
		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)
		}
		serviceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("serviceGroupName")])
		if err != nil {
			return nil, err
		}
		drillNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("drillName")])
		if err != nil {
			return nil, err
		}
		drillRunNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("drillRunName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := d.srv.BeginResume(req.Context(), serviceGroupNameParam, getHeaderValue(req.Header, "operation-id"), drillNameParam, drillRunNameParam, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginResume = &respr
		d.beginResume.add(req, beginResume)
	}

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

	if !slices.Contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
		d.beginResume.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(beginResume) {
		d.beginResume.remove(req)
	}

	return resp, nil
}

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