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

// DeploymentOperationsServer is a fake server for instances of the armdeployments.DeploymentOperationsClient type.
type DeploymentOperationsServer struct {
	// Get is the fake for method DeploymentOperationsClient.Get
	// HTTP status codes to indicate success: http.StatusOK
	Get func(ctx context.Context, resourceGroupName string, deploymentName string, operationID string, options *armdeployments.DeploymentOperationsClientGetOptions) (resp azfake.Responder[armdeployments.DeploymentOperationsClientGetResponse], errResp azfake.ErrorResponder)

	// GetAtManagementGroupScope is the fake for method DeploymentOperationsClient.GetAtManagementGroupScope
	// HTTP status codes to indicate success: http.StatusOK
	GetAtManagementGroupScope func(ctx context.Context, groupID string, deploymentName string, operationID string, options *armdeployments.DeploymentOperationsClientGetAtManagementGroupScopeOptions) (resp azfake.Responder[armdeployments.DeploymentOperationsClientGetAtManagementGroupScopeResponse], errResp azfake.ErrorResponder)

	// GetAtScope is the fake for method DeploymentOperationsClient.GetAtScope
	// HTTP status codes to indicate success: http.StatusOK
	GetAtScope func(ctx context.Context, scope string, deploymentName string, operationID string, options *armdeployments.DeploymentOperationsClientGetAtScopeOptions) (resp azfake.Responder[armdeployments.DeploymentOperationsClientGetAtScopeResponse], errResp azfake.ErrorResponder)

	// GetAtSubscriptionScope is the fake for method DeploymentOperationsClient.GetAtSubscriptionScope
	// HTTP status codes to indicate success: http.StatusOK
	GetAtSubscriptionScope func(ctx context.Context, deploymentName string, operationID string, options *armdeployments.DeploymentOperationsClientGetAtSubscriptionScopeOptions) (resp azfake.Responder[armdeployments.DeploymentOperationsClientGetAtSubscriptionScopeResponse], errResp azfake.ErrorResponder)

	// GetAtTenantScope is the fake for method DeploymentOperationsClient.GetAtTenantScope
	// HTTP status codes to indicate success: http.StatusOK
	GetAtTenantScope func(ctx context.Context, deploymentName string, operationID string, options *armdeployments.DeploymentOperationsClientGetAtTenantScopeOptions) (resp azfake.Responder[armdeployments.DeploymentOperationsClientGetAtTenantScopeResponse], errResp azfake.ErrorResponder)

	// NewListPager is the fake for method DeploymentOperationsClient.NewListPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListPager func(resourceGroupName string, deploymentName string, options *armdeployments.DeploymentOperationsClientListOptions) (resp azfake.PagerResponder[armdeployments.DeploymentOperationsClientListResponse])

	// NewListAtManagementGroupScopePager is the fake for method DeploymentOperationsClient.NewListAtManagementGroupScopePager
	// HTTP status codes to indicate success: http.StatusOK
	NewListAtManagementGroupScopePager func(groupID string, deploymentName string, options *armdeployments.DeploymentOperationsClientListAtManagementGroupScopeOptions) (resp azfake.PagerResponder[armdeployments.DeploymentOperationsClientListAtManagementGroupScopeResponse])

	// NewListAtScopePager is the fake for method DeploymentOperationsClient.NewListAtScopePager
	// HTTP status codes to indicate success: http.StatusOK
	NewListAtScopePager func(scope string, deploymentName string, options *armdeployments.DeploymentOperationsClientListAtScopeOptions) (resp azfake.PagerResponder[armdeployments.DeploymentOperationsClientListAtScopeResponse])

	// NewListAtSubscriptionScopePager is the fake for method DeploymentOperationsClient.NewListAtSubscriptionScopePager
	// HTTP status codes to indicate success: http.StatusOK
	NewListAtSubscriptionScopePager func(deploymentName string, options *armdeployments.DeploymentOperationsClientListAtSubscriptionScopeOptions) (resp azfake.PagerResponder[armdeployments.DeploymentOperationsClientListAtSubscriptionScopeResponse])

	// NewListAtTenantScopePager is the fake for method DeploymentOperationsClient.NewListAtTenantScopePager
	// HTTP status codes to indicate success: http.StatusOK
	NewListAtTenantScopePager func(deploymentName string, options *armdeployments.DeploymentOperationsClientListAtTenantScopeOptions) (resp azfake.PagerResponder[armdeployments.DeploymentOperationsClientListAtTenantScopeResponse])
}

// NewDeploymentOperationsServerTransport creates a new instance of DeploymentOperationsServerTransport with the provided implementation.
// The returned DeploymentOperationsServerTransport instance is connected to an instance of armdeployments.DeploymentOperationsClient via the
// azcore.ClientOptions.Transporter field in the client's constructor parameters.
func NewDeploymentOperationsServerTransport(srv *DeploymentOperationsServer) *DeploymentOperationsServerTransport {
	return &DeploymentOperationsServerTransport{
		srv:                                srv,
		newListPager:                       newTracker[azfake.PagerResponder[armdeployments.DeploymentOperationsClientListResponse]](),
		newListAtManagementGroupScopePager: newTracker[azfake.PagerResponder[armdeployments.DeploymentOperationsClientListAtManagementGroupScopeResponse]](),
		newListAtScopePager:                newTracker[azfake.PagerResponder[armdeployments.DeploymentOperationsClientListAtScopeResponse]](),
		newListAtSubscriptionScopePager:    newTracker[azfake.PagerResponder[armdeployments.DeploymentOperationsClientListAtSubscriptionScopeResponse]](),
		newListAtTenantScopePager:          newTracker[azfake.PagerResponder[armdeployments.DeploymentOperationsClientListAtTenantScopeResponse]](),
	}
}

// DeploymentOperationsServerTransport connects instances of armdeployments.DeploymentOperationsClient to instances of DeploymentOperationsServer.
// Don't use this type directly, use NewDeploymentOperationsServerTransport instead.
type DeploymentOperationsServerTransport struct {
	srv                                *DeploymentOperationsServer
	newListPager                       *tracker[azfake.PagerResponder[armdeployments.DeploymentOperationsClientListResponse]]
	newListAtManagementGroupScopePager *tracker[azfake.PagerResponder[armdeployments.DeploymentOperationsClientListAtManagementGroupScopeResponse]]
	newListAtScopePager                *tracker[azfake.PagerResponder[armdeployments.DeploymentOperationsClientListAtScopeResponse]]
	newListAtSubscriptionScopePager    *tracker[azfake.PagerResponder[armdeployments.DeploymentOperationsClientListAtSubscriptionScopeResponse]]
	newListAtTenantScopePager          *tracker[azfake.PagerResponder[armdeployments.DeploymentOperationsClientListAtTenantScopeResponse]]
}

// Do implements the policy.Transporter interface for DeploymentOperationsServerTransport.
func (d *DeploymentOperationsServerTransport) 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 *DeploymentOperationsServerTransport) 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 deploymentOperationsServerTransportInterceptor != nil {
			res.resp, res.err, intercepted = deploymentOperationsServerTransportInterceptor.Do(req)
		}
		if !intercepted {
			switch method {
			case "DeploymentOperationsClient.Get":
				res.resp, res.err = d.dispatchGet(req)
			case "DeploymentOperationsClient.GetAtManagementGroupScope":
				res.resp, res.err = d.dispatchGetAtManagementGroupScope(req)
			case "DeploymentOperationsClient.GetAtScope":
				res.resp, res.err = d.dispatchGetAtScope(req)
			case "DeploymentOperationsClient.GetAtSubscriptionScope":
				res.resp, res.err = d.dispatchGetAtSubscriptionScope(req)
			case "DeploymentOperationsClient.GetAtTenantScope":
				res.resp, res.err = d.dispatchGetAtTenantScope(req)
			case "DeploymentOperationsClient.NewListPager":
				res.resp, res.err = d.dispatchNewListPager(req)
			case "DeploymentOperationsClient.NewListAtManagementGroupScopePager":
				res.resp, res.err = d.dispatchNewListAtManagementGroupScopePager(req)
			case "DeploymentOperationsClient.NewListAtScopePager":
				res.resp, res.err = d.dispatchNewListAtScopePager(req)
			case "DeploymentOperationsClient.NewListAtSubscriptionScopePager":
				res.resp, res.err = d.dispatchNewListAtSubscriptionScopePager(req)
			case "DeploymentOperationsClient.NewListAtTenantScopePager":
				res.resp, res.err = d.dispatchNewListAtTenantScopePager(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 (d *DeploymentOperationsServerTransport) 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 = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/deployments/(?P<deploymentName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P<operationId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	regex := regexp.MustCompile(regexStr)
	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
	if len(matches) < 5 {
		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
	}
	deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")])
	if err != nil {
		return nil, err
	}
	operationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameParam, deploymentNameParam, operationIDParam, 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).DeploymentOperation, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (d *DeploymentOperationsServerTransport) dispatchGetAtManagementGroupScope(req *http.Request) (*http.Response, error) {
	if d.srv.GetAtManagementGroupScope == nil {
		return nil, &nonRetriableError{errors.New("fake for method GetAtManagementGroupScope not implemented")}
	}
	const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P<groupId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P<deploymentName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P<operationId>[!#&$-;=?-\[\]_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)
	}
	groupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")])
	if err != nil {
		return nil, err
	}
	deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")])
	if err != nil {
		return nil, err
	}
	operationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := d.srv.GetAtManagementGroupScope(req.Context(), groupIDParam, deploymentNameParam, operationIDParam, 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).DeploymentOperation, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (d *DeploymentOperationsServerTransport) dispatchGetAtScope(req *http.Request) (*http.Response, error) {
	if d.srv.GetAtScope == nil {
		return nil, &nonRetriableError{errors.New("fake for method GetAtScope not implemented")}
	}
	const regexStr = `/(?P<scope>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P<deploymentName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P<operationId>[!#&$-;=?-\[\]_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)
	}
	scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")])
	if err != nil {
		return nil, err
	}
	deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")])
	if err != nil {
		return nil, err
	}
	operationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := d.srv.GetAtScope(req.Context(), scopeParam, deploymentNameParam, operationIDParam, 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).DeploymentOperation, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (d *DeploymentOperationsServerTransport) dispatchGetAtSubscriptionScope(req *http.Request) (*http.Response, error) {
	if d.srv.GetAtSubscriptionScope == nil {
		return nil, &nonRetriableError{errors.New("fake for method GetAtSubscriptionScope not implemented")}
	}
	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P<deploymentName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P<operationId>[!#&$-;=?-\[\]_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)
	}
	deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")])
	if err != nil {
		return nil, err
	}
	operationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := d.srv.GetAtSubscriptionScope(req.Context(), deploymentNameParam, operationIDParam, 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).DeploymentOperation, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (d *DeploymentOperationsServerTransport) dispatchGetAtTenantScope(req *http.Request) (*http.Response, error) {
	if d.srv.GetAtTenantScope == nil {
		return nil, &nonRetriableError{errors.New("fake for method GetAtTenantScope not implemented")}
	}
	const regexStr = `/providers/Microsoft\.Resources/deployments/(?P<deploymentName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations/(?P<operationId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	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)
	}
	deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")])
	if err != nil {
		return nil, err
	}
	operationIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("operationId")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := d.srv.GetAtTenantScope(req.Context(), deploymentNameParam, operationIDParam, 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).DeploymentOperation, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (d *DeploymentOperationsServerTransport) 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 = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/deployments/(?P<deploymentName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if len(matches) < 4 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		qp := req.URL.Query()
		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
		if err != nil {
			return nil, err
		}
		deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")])
		if err != nil {
			return nil, err
		}
		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 *armdeployments.DeploymentOperationsClientListOptions
		if topParam != nil {
			options = &armdeployments.DeploymentOperationsClientListOptions{
				Top: topParam,
			}
		}
		resp := d.srv.NewListPager(resourceGroupNameParam, deploymentNameParam, options)
		newListPager = &resp
		d.newListPager.add(req, newListPager)
		server.PagerResponderInjectNextLinks(newListPager, req, func(page *armdeployments.DeploymentOperationsClientListResponse, 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) {
		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 *DeploymentOperationsServerTransport) dispatchNewListAtManagementGroupScopePager(req *http.Request) (*http.Response, error) {
	if d.srv.NewListAtManagementGroupScopePager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListAtManagementGroupScopePager not implemented")}
	}
	newListAtManagementGroupScopePager := d.newListAtManagementGroupScopePager.get(req)
	if newListAtManagementGroupScopePager == nil {
		const regexStr = `/providers/Microsoft\.Management/managementGroups/(?P<groupId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P<deploymentName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations`
		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)
		}
		qp := req.URL.Query()
		groupIDParam, err := url.PathUnescape(matches[regex.SubexpIndex("groupId")])
		if err != nil {
			return nil, err
		}
		deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")])
		if err != nil {
			return nil, err
		}
		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 *armdeployments.DeploymentOperationsClientListAtManagementGroupScopeOptions
		if topParam != nil {
			options = &armdeployments.DeploymentOperationsClientListAtManagementGroupScopeOptions{
				Top: topParam,
			}
		}
		resp := d.srv.NewListAtManagementGroupScopePager(groupIDParam, deploymentNameParam, options)
		newListAtManagementGroupScopePager = &resp
		d.newListAtManagementGroupScopePager.add(req, newListAtManagementGroupScopePager)
		server.PagerResponderInjectNextLinks(newListAtManagementGroupScopePager, req, func(page *armdeployments.DeploymentOperationsClientListAtManagementGroupScopeResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListAtManagementGroupScopePager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		d.newListAtManagementGroupScopePager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListAtManagementGroupScopePager) {
		d.newListAtManagementGroupScopePager.remove(req)
	}
	return resp, nil
}

func (d *DeploymentOperationsServerTransport) dispatchNewListAtScopePager(req *http.Request) (*http.Response, error) {
	if d.srv.NewListAtScopePager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListAtScopePager not implemented")}
	}
	newListAtScopePager := d.newListAtScopePager.get(req)
	if newListAtScopePager == nil {
		const regexStr = `/(?P<scope>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P<deploymentName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations`
		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)
		}
		qp := req.URL.Query()
		scopeParam, err := url.PathUnescape(matches[regex.SubexpIndex("scope")])
		if err != nil {
			return nil, err
		}
		deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")])
		if err != nil {
			return nil, err
		}
		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 *armdeployments.DeploymentOperationsClientListAtScopeOptions
		if topParam != nil {
			options = &armdeployments.DeploymentOperationsClientListAtScopeOptions{
				Top: topParam,
			}
		}
		resp := d.srv.NewListAtScopePager(scopeParam, deploymentNameParam, options)
		newListAtScopePager = &resp
		d.newListAtScopePager.add(req, newListAtScopePager)
		server.PagerResponderInjectNextLinks(newListAtScopePager, req, func(page *armdeployments.DeploymentOperationsClientListAtScopeResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListAtScopePager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		d.newListAtScopePager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListAtScopePager) {
		d.newListAtScopePager.remove(req)
	}
	return resp, nil
}

func (d *DeploymentOperationsServerTransport) dispatchNewListAtSubscriptionScopePager(req *http.Request) (*http.Response, error) {
	if d.srv.NewListAtSubscriptionScopePager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListAtSubscriptionScopePager not implemented")}
	}
	newListAtSubscriptionScopePager := d.newListAtSubscriptionScopePager.get(req)
	if newListAtSubscriptionScopePager == nil {
		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Resources/deployments/(?P<deploymentName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations`
		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)
		}
		qp := req.URL.Query()
		deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")])
		if err != nil {
			return nil, err
		}
		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 *armdeployments.DeploymentOperationsClientListAtSubscriptionScopeOptions
		if topParam != nil {
			options = &armdeployments.DeploymentOperationsClientListAtSubscriptionScopeOptions{
				Top: topParam,
			}
		}
		resp := d.srv.NewListAtSubscriptionScopePager(deploymentNameParam, options)
		newListAtSubscriptionScopePager = &resp
		d.newListAtSubscriptionScopePager.add(req, newListAtSubscriptionScopePager)
		server.PagerResponderInjectNextLinks(newListAtSubscriptionScopePager, req, func(page *armdeployments.DeploymentOperationsClientListAtSubscriptionScopeResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListAtSubscriptionScopePager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		d.newListAtSubscriptionScopePager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListAtSubscriptionScopePager) {
		d.newListAtSubscriptionScopePager.remove(req)
	}
	return resp, nil
}

func (d *DeploymentOperationsServerTransport) dispatchNewListAtTenantScopePager(req *http.Request) (*http.Response, error) {
	if d.srv.NewListAtTenantScopePager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListAtTenantScopePager not implemented")}
	}
	newListAtTenantScopePager := d.newListAtTenantScopePager.get(req)
	if newListAtTenantScopePager == nil {
		const regexStr = `/providers/Microsoft\.Resources/deployments/(?P<deploymentName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/operations`
		regex := regexp.MustCompile(regexStr)
		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
		if len(matches) < 2 {
			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
		}
		qp := req.URL.Query()
		deploymentNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("deploymentName")])
		if err != nil {
			return nil, err
		}
		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 *armdeployments.DeploymentOperationsClientListAtTenantScopeOptions
		if topParam != nil {
			options = &armdeployments.DeploymentOperationsClientListAtTenantScopeOptions{
				Top: topParam,
			}
		}
		resp := d.srv.NewListAtTenantScopePager(deploymentNameParam, options)
		newListAtTenantScopePager = &resp
		d.newListAtTenantScopePager.add(req, newListAtTenantScopePager)
		server.PagerResponderInjectNextLinks(newListAtTenantScopePager, req, func(page *armdeployments.DeploymentOperationsClientListAtTenantScopeResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListAtTenantScopePager, req)
	if err != nil {
		return nil, err
	}
	if !contains([]int{http.StatusOK}, resp.StatusCode) {
		d.newListAtTenantScopePager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListAtTenantScopePager) {
		d.newListAtTenantScopePager.remove(req)
	}
	return resp, nil
}

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