// 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/billing/armbilling/v2"
	"net/http"
	"net/url"
	"regexp"
	"slices"
	"strconv"
	"time"
)

// InvoicesServer is a fake server for instances of the armbilling.InvoicesClient type.
type InvoicesServer struct {
	// BeginAmend is the fake for method InvoicesClient.BeginAmend
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
	BeginAmend func(ctx context.Context, billingAccountName string, invoiceName string, options *armbilling.InvoicesClientBeginAmendOptions) (resp azfake.PollerResponder[armbilling.InvoicesClientAmendResponse], errResp azfake.ErrorResponder)

	// BeginDownloadByBillingAccount is the fake for method InvoicesClient.BeginDownloadByBillingAccount
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginDownloadByBillingAccount func(ctx context.Context, billingAccountName string, invoiceName string, options *armbilling.InvoicesClientBeginDownloadByBillingAccountOptions) (resp azfake.PollerResponder[armbilling.InvoicesClientDownloadByBillingAccountResponse], errResp azfake.ErrorResponder)

	// BeginDownloadByBillingSubscription is the fake for method InvoicesClient.BeginDownloadByBillingSubscription
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginDownloadByBillingSubscription func(ctx context.Context, invoiceName string, options *armbilling.InvoicesClientBeginDownloadByBillingSubscriptionOptions) (resp azfake.PollerResponder[armbilling.InvoicesClientDownloadByBillingSubscriptionResponse], errResp azfake.ErrorResponder)

	// BeginDownloadDocumentsByBillingAccount is the fake for method InvoicesClient.BeginDownloadDocumentsByBillingAccount
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginDownloadDocumentsByBillingAccount func(ctx context.Context, billingAccountName string, parameters []*armbilling.DocumentDownloadRequest, options *armbilling.InvoicesClientBeginDownloadDocumentsByBillingAccountOptions) (resp azfake.PollerResponder[armbilling.InvoicesClientDownloadDocumentsByBillingAccountResponse], errResp azfake.ErrorResponder)

	// BeginDownloadDocumentsByBillingSubscription is the fake for method InvoicesClient.BeginDownloadDocumentsByBillingSubscription
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginDownloadDocumentsByBillingSubscription func(ctx context.Context, parameters []*armbilling.DocumentDownloadRequest, options *armbilling.InvoicesClientBeginDownloadDocumentsByBillingSubscriptionOptions) (resp azfake.PollerResponder[armbilling.InvoicesClientDownloadDocumentsByBillingSubscriptionResponse], errResp azfake.ErrorResponder)

	// BeginDownloadSummaryByBillingAccount is the fake for method InvoicesClient.BeginDownloadSummaryByBillingAccount
	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
	BeginDownloadSummaryByBillingAccount func(ctx context.Context, billingAccountName string, invoiceName string, options *armbilling.InvoicesClientBeginDownloadSummaryByBillingAccountOptions) (resp azfake.PollerResponder[armbilling.InvoicesClientDownloadSummaryByBillingAccountResponse], errResp azfake.ErrorResponder)

	// Get is the fake for method InvoicesClient.Get
	// HTTP status codes to indicate success: http.StatusOK
	Get func(ctx context.Context, invoiceName string, options *armbilling.InvoicesClientGetOptions) (resp azfake.Responder[armbilling.InvoicesClientGetResponse], errResp azfake.ErrorResponder)

	// GetByBillingAccount is the fake for method InvoicesClient.GetByBillingAccount
	// HTTP status codes to indicate success: http.StatusOK
	GetByBillingAccount func(ctx context.Context, billingAccountName string, invoiceName string, options *armbilling.InvoicesClientGetByBillingAccountOptions) (resp azfake.Responder[armbilling.InvoicesClientGetByBillingAccountResponse], errResp azfake.ErrorResponder)

	// GetByBillingSubscription is the fake for method InvoicesClient.GetByBillingSubscription
	// HTTP status codes to indicate success: http.StatusOK
	GetByBillingSubscription func(ctx context.Context, invoiceName string, options *armbilling.InvoicesClientGetByBillingSubscriptionOptions) (resp azfake.Responder[armbilling.InvoicesClientGetByBillingSubscriptionResponse], errResp azfake.ErrorResponder)

	// NewListByBillingAccountPager is the fake for method InvoicesClient.NewListByBillingAccountPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListByBillingAccountPager func(billingAccountName string, options *armbilling.InvoicesClientListByBillingAccountOptions) (resp azfake.PagerResponder[armbilling.InvoicesClientListByBillingAccountResponse])

	// NewListByBillingProfilePager is the fake for method InvoicesClient.NewListByBillingProfilePager
	// HTTP status codes to indicate success: http.StatusOK
	NewListByBillingProfilePager func(billingAccountName string, billingProfileName string, options *armbilling.InvoicesClientListByBillingProfileOptions) (resp azfake.PagerResponder[armbilling.InvoicesClientListByBillingProfileResponse])

	// NewListByBillingSubscriptionPager is the fake for method InvoicesClient.NewListByBillingSubscriptionPager
	// HTTP status codes to indicate success: http.StatusOK
	NewListByBillingSubscriptionPager func(options *armbilling.InvoicesClientListByBillingSubscriptionOptions) (resp azfake.PagerResponder[armbilling.InvoicesClientListByBillingSubscriptionResponse])
}

// NewInvoicesServerTransport creates a new instance of InvoicesServerTransport with the provided implementation.
// The returned InvoicesServerTransport instance is connected to an instance of armbilling.InvoicesClient via the
// azcore.ClientOptions.Transporter field in the client's constructor parameters.
func NewInvoicesServerTransport(srv *InvoicesServer) *InvoicesServerTransport {
	return &InvoicesServerTransport{
		srv:                                    srv,
		beginAmend:                             newTracker[azfake.PollerResponder[armbilling.InvoicesClientAmendResponse]](),
		beginDownloadByBillingAccount:          newTracker[azfake.PollerResponder[armbilling.InvoicesClientDownloadByBillingAccountResponse]](),
		beginDownloadByBillingSubscription:     newTracker[azfake.PollerResponder[armbilling.InvoicesClientDownloadByBillingSubscriptionResponse]](),
		beginDownloadDocumentsByBillingAccount: newTracker[azfake.PollerResponder[armbilling.InvoicesClientDownloadDocumentsByBillingAccountResponse]](),
		beginDownloadDocumentsByBillingSubscription: newTracker[azfake.PollerResponder[armbilling.InvoicesClientDownloadDocumentsByBillingSubscriptionResponse]](),
		beginDownloadSummaryByBillingAccount:        newTracker[azfake.PollerResponder[armbilling.InvoicesClientDownloadSummaryByBillingAccountResponse]](),
		newListByBillingAccountPager:                newTracker[azfake.PagerResponder[armbilling.InvoicesClientListByBillingAccountResponse]](),
		newListByBillingProfilePager:                newTracker[azfake.PagerResponder[armbilling.InvoicesClientListByBillingProfileResponse]](),
		newListByBillingSubscriptionPager:           newTracker[azfake.PagerResponder[armbilling.InvoicesClientListByBillingSubscriptionResponse]](),
	}
}

// InvoicesServerTransport connects instances of armbilling.InvoicesClient to instances of InvoicesServer.
// Don't use this type directly, use NewInvoicesServerTransport instead.
type InvoicesServerTransport struct {
	srv                                         *InvoicesServer
	beginAmend                                  *tracker[azfake.PollerResponder[armbilling.InvoicesClientAmendResponse]]
	beginDownloadByBillingAccount               *tracker[azfake.PollerResponder[armbilling.InvoicesClientDownloadByBillingAccountResponse]]
	beginDownloadByBillingSubscription          *tracker[azfake.PollerResponder[armbilling.InvoicesClientDownloadByBillingSubscriptionResponse]]
	beginDownloadDocumentsByBillingAccount      *tracker[azfake.PollerResponder[armbilling.InvoicesClientDownloadDocumentsByBillingAccountResponse]]
	beginDownloadDocumentsByBillingSubscription *tracker[azfake.PollerResponder[armbilling.InvoicesClientDownloadDocumentsByBillingSubscriptionResponse]]
	beginDownloadSummaryByBillingAccount        *tracker[azfake.PollerResponder[armbilling.InvoicesClientDownloadSummaryByBillingAccountResponse]]
	newListByBillingAccountPager                *tracker[azfake.PagerResponder[armbilling.InvoicesClientListByBillingAccountResponse]]
	newListByBillingProfilePager                *tracker[azfake.PagerResponder[armbilling.InvoicesClientListByBillingProfileResponse]]
	newListByBillingSubscriptionPager           *tracker[azfake.PagerResponder[armbilling.InvoicesClientListByBillingSubscriptionResponse]]
}

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

func (i *InvoicesServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) {
	resultChan := make(chan result, 1)
	go func() {
		var intercepted bool
		var res result
		if invoicesServerTransportInterceptor != nil {
			res.resp, res.err, intercepted = invoicesServerTransportInterceptor.Do(req)
		}
		if !intercepted {
			switch method {
			case "InvoicesClient.BeginAmend":
				res.resp, res.err = i.dispatchBeginAmend(req)
			case "InvoicesClient.BeginDownloadByBillingAccount":
				res.resp, res.err = i.dispatchBeginDownloadByBillingAccount(req)
			case "InvoicesClient.BeginDownloadByBillingSubscription":
				res.resp, res.err = i.dispatchBeginDownloadByBillingSubscription(req)
			case "InvoicesClient.BeginDownloadDocumentsByBillingAccount":
				res.resp, res.err = i.dispatchBeginDownloadDocumentsByBillingAccount(req)
			case "InvoicesClient.BeginDownloadDocumentsByBillingSubscription":
				res.resp, res.err = i.dispatchBeginDownloadDocumentsByBillingSubscription(req)
			case "InvoicesClient.BeginDownloadSummaryByBillingAccount":
				res.resp, res.err = i.dispatchBeginDownloadSummaryByBillingAccount(req)
			case "InvoicesClient.Get":
				res.resp, res.err = i.dispatchGet(req)
			case "InvoicesClient.GetByBillingAccount":
				res.resp, res.err = i.dispatchGetByBillingAccount(req)
			case "InvoicesClient.GetByBillingSubscription":
				res.resp, res.err = i.dispatchGetByBillingSubscription(req)
			case "InvoicesClient.NewListByBillingAccountPager":
				res.resp, res.err = i.dispatchNewListByBillingAccountPager(req)
			case "InvoicesClient.NewListByBillingProfilePager":
				res.resp, res.err = i.dispatchNewListByBillingProfilePager(req)
			case "InvoicesClient.NewListByBillingSubscriptionPager":
				res.resp, res.err = i.dispatchNewListByBillingSubscriptionPager(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 (i *InvoicesServerTransport) dispatchBeginAmend(req *http.Request) (*http.Response, error) {
	if i.srv.BeginAmend == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginAmend not implemented")}
	}
	beginAmend := i.beginAmend.get(req)
	if beginAmend == nil {
		const regexStr = `/providers/Microsoft\.Billing/billingAccounts/(?P<billingAccountName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/invoices/(?P<invoiceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/amend`
		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)
		}
		billingAccountNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("billingAccountName")])
		if err != nil {
			return nil, err
		}
		invoiceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("invoiceName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := i.srv.BeginAmend(req.Context(), billingAccountNameParam, invoiceNameParam, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginAmend = &respr
		i.beginAmend.add(req, beginAmend)
	}

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

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

	return resp, nil
}

func (i *InvoicesServerTransport) dispatchBeginDownloadByBillingAccount(req *http.Request) (*http.Response, error) {
	if i.srv.BeginDownloadByBillingAccount == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginDownloadByBillingAccount not implemented")}
	}
	beginDownloadByBillingAccount := i.beginDownloadByBillingAccount.get(req)
	if beginDownloadByBillingAccount == nil {
		const regexStr = `/providers/Microsoft\.Billing/billingAccounts/(?P<billingAccountName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/invoices/(?P<invoiceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/download`
		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()
		billingAccountNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("billingAccountName")])
		if err != nil {
			return nil, err
		}
		invoiceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("invoiceName")])
		if err != nil {
			return nil, err
		}
		documentNameParam := getOptional(qp.Get("documentName"))
		var options *armbilling.InvoicesClientBeginDownloadByBillingAccountOptions
		if documentNameParam != nil {
			options = &armbilling.InvoicesClientBeginDownloadByBillingAccountOptions{
				DocumentName: documentNameParam,
			}
		}
		respr, errRespr := i.srv.BeginDownloadByBillingAccount(req.Context(), billingAccountNameParam, invoiceNameParam, options)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginDownloadByBillingAccount = &respr
		i.beginDownloadByBillingAccount.add(req, beginDownloadByBillingAccount)
	}

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

	if !slices.Contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) {
		i.beginDownloadByBillingAccount.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginDownloadByBillingAccount) {
		i.beginDownloadByBillingAccount.remove(req)
	}

	return resp, nil
}

func (i *InvoicesServerTransport) dispatchBeginDownloadByBillingSubscription(req *http.Request) (*http.Response, error) {
	if i.srv.BeginDownloadByBillingSubscription == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginDownloadByBillingSubscription not implemented")}
	}
	beginDownloadByBillingSubscription := i.beginDownloadByBillingSubscription.get(req)
	if beginDownloadByBillingSubscription == nil {
		const regexStr = `/providers/Microsoft\.Billing/billingAccounts/default/billingSubscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/invoices/(?P<invoiceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/download`
		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()
		invoiceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("invoiceName")])
		if err != nil {
			return nil, err
		}
		documentNameParam := getOptional(qp.Get("documentName"))
		var options *armbilling.InvoicesClientBeginDownloadByBillingSubscriptionOptions
		if documentNameParam != nil {
			options = &armbilling.InvoicesClientBeginDownloadByBillingSubscriptionOptions{
				DocumentName: documentNameParam,
			}
		}
		respr, errRespr := i.srv.BeginDownloadByBillingSubscription(req.Context(), invoiceNameParam, options)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginDownloadByBillingSubscription = &respr
		i.beginDownloadByBillingSubscription.add(req, beginDownloadByBillingSubscription)
	}

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

	if !slices.Contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) {
		i.beginDownloadByBillingSubscription.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginDownloadByBillingSubscription) {
		i.beginDownloadByBillingSubscription.remove(req)
	}

	return resp, nil
}

func (i *InvoicesServerTransport) dispatchBeginDownloadDocumentsByBillingAccount(req *http.Request) (*http.Response, error) {
	if i.srv.BeginDownloadDocumentsByBillingAccount == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginDownloadDocumentsByBillingAccount not implemented")}
	}
	beginDownloadDocumentsByBillingAccount := i.beginDownloadDocumentsByBillingAccount.get(req)
	if beginDownloadDocumentsByBillingAccount == nil {
		const regexStr = `/providers/Microsoft\.Billing/billingAccounts/(?P<billingAccountName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/downloadDocuments`
		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)
		}
		body, err := server.UnmarshalRequestAsJSON[[]*armbilling.DocumentDownloadRequest](req)
		if err != nil {
			return nil, err
		}
		billingAccountNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("billingAccountName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := i.srv.BeginDownloadDocumentsByBillingAccount(req.Context(), billingAccountNameParam, body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginDownloadDocumentsByBillingAccount = &respr
		i.beginDownloadDocumentsByBillingAccount.add(req, beginDownloadDocumentsByBillingAccount)
	}

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

	if !slices.Contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) {
		i.beginDownloadDocumentsByBillingAccount.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginDownloadDocumentsByBillingAccount) {
		i.beginDownloadDocumentsByBillingAccount.remove(req)
	}

	return resp, nil
}

func (i *InvoicesServerTransport) dispatchBeginDownloadDocumentsByBillingSubscription(req *http.Request) (*http.Response, error) {
	if i.srv.BeginDownloadDocumentsByBillingSubscription == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginDownloadDocumentsByBillingSubscription not implemented")}
	}
	beginDownloadDocumentsByBillingSubscription := i.beginDownloadDocumentsByBillingSubscription.get(req)
	if beginDownloadDocumentsByBillingSubscription == nil {
		const regexStr = `/providers/Microsoft\.Billing/billingAccounts/default/billingSubscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/downloadDocuments`
		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)
		}
		body, err := server.UnmarshalRequestAsJSON[[]*armbilling.DocumentDownloadRequest](req)
		if err != nil {
			return nil, err
		}
		respr, errRespr := i.srv.BeginDownloadDocumentsByBillingSubscription(req.Context(), body, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginDownloadDocumentsByBillingSubscription = &respr
		i.beginDownloadDocumentsByBillingSubscription.add(req, beginDownloadDocumentsByBillingSubscription)
	}

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

	if !slices.Contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) {
		i.beginDownloadDocumentsByBillingSubscription.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginDownloadDocumentsByBillingSubscription) {
		i.beginDownloadDocumentsByBillingSubscription.remove(req)
	}

	return resp, nil
}

func (i *InvoicesServerTransport) dispatchBeginDownloadSummaryByBillingAccount(req *http.Request) (*http.Response, error) {
	if i.srv.BeginDownloadSummaryByBillingAccount == nil {
		return nil, &nonRetriableError{errors.New("fake for method BeginDownloadSummaryByBillingAccount not implemented")}
	}
	beginDownloadSummaryByBillingAccount := i.beginDownloadSummaryByBillingAccount.get(req)
	if beginDownloadSummaryByBillingAccount == nil {
		const regexStr = `/providers/Microsoft\.Billing/billingAccounts/(?P<billingAccountName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/invoices/(?P<invoiceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/downloadSummary`
		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)
		}
		billingAccountNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("billingAccountName")])
		if err != nil {
			return nil, err
		}
		invoiceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("invoiceName")])
		if err != nil {
			return nil, err
		}
		respr, errRespr := i.srv.BeginDownloadSummaryByBillingAccount(req.Context(), billingAccountNameParam, invoiceNameParam, nil)
		if respErr := server.GetError(errRespr, req); respErr != nil {
			return nil, respErr
		}
		beginDownloadSummaryByBillingAccount = &respr
		i.beginDownloadSummaryByBillingAccount.add(req, beginDownloadSummaryByBillingAccount)
	}

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

	if !slices.Contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) {
		i.beginDownloadSummaryByBillingAccount.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)}
	}
	if !server.PollerResponderMore(beginDownloadSummaryByBillingAccount) {
		i.beginDownloadSummaryByBillingAccount.remove(req)
	}

	return resp, nil
}

func (i *InvoicesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) {
	if i.srv.Get == nil {
		return nil, &nonRetriableError{errors.New("fake for method Get not implemented")}
	}
	const regexStr = `/providers/Microsoft\.Billing/billingAccounts/default/invoices/(?P<invoiceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
	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)
	}
	invoiceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("invoiceName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := i.srv.Get(req.Context(), invoiceNameParam, 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).Invoice, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (i *InvoicesServerTransport) dispatchGetByBillingAccount(req *http.Request) (*http.Response, error) {
	if i.srv.GetByBillingAccount == nil {
		return nil, &nonRetriableError{errors.New("fake for method GetByBillingAccount not implemented")}
	}
	const regexStr = `/providers/Microsoft\.Billing/billingAccounts/(?P<billingAccountName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/invoices/(?P<invoiceName>[!#&$-;=?-\[\]_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)
	}
	billingAccountNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("billingAccountName")])
	if err != nil {
		return nil, err
	}
	invoiceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("invoiceName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := i.srv.GetByBillingAccount(req.Context(), billingAccountNameParam, invoiceNameParam, 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).Invoice, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (i *InvoicesServerTransport) dispatchGetByBillingSubscription(req *http.Request) (*http.Response, error) {
	if i.srv.GetByBillingSubscription == nil {
		return nil, &nonRetriableError{errors.New("fake for method GetByBillingSubscription not implemented")}
	}
	const regexStr = `/providers/Microsoft\.Billing/billingAccounts/default/billingSubscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/invoices/(?P<invoiceName>[!#&$-;=?-\[\]_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)
	}
	invoiceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("invoiceName")])
	if err != nil {
		return nil, err
	}
	respr, errRespr := i.srv.GetByBillingSubscription(req.Context(), invoiceNameParam, 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).Invoice, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (i *InvoicesServerTransport) dispatchNewListByBillingAccountPager(req *http.Request) (*http.Response, error) {
	if i.srv.NewListByBillingAccountPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListByBillingAccountPager not implemented")}
	}
	newListByBillingAccountPager := i.newListByBillingAccountPager.get(req)
	if newListByBillingAccountPager == nil {
		const regexStr = `/providers/Microsoft\.Billing/billingAccounts/(?P<billingAccountName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/invoices`
		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()
		billingAccountNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("billingAccountName")])
		if err != nil {
			return nil, err
		}
		periodStartDateParam, err := parseOptional(qp.Get("periodStartDate"), func(v string) (time.Time, error) { return time.Parse(time.DateOnly, v) })
		if err != nil {
			return nil, err
		}
		periodEndDateParam, err := parseOptional(qp.Get("periodEndDate"), func(v string) (time.Time, error) { return time.Parse(time.DateOnly, v) })
		if err != nil {
			return nil, err
		}
		filterParam := getOptional(qp.Get("filter"))
		orderByParam := getOptional(qp.Get("orderBy"))
		topParam, err := parseOptional(qp.Get("top"), func(v string) (int64, error) {
			p, parseErr := strconv.ParseInt(v, 10, 64)
			if parseErr != nil {
				return 0, parseErr
			}
			return p, nil
		})
		if err != nil {
			return nil, err
		}
		skipParam, err := parseOptional(qp.Get("skip"), func(v string) (int64, error) {
			p, parseErr := strconv.ParseInt(v, 10, 64)
			if parseErr != nil {
				return 0, parseErr
			}
			return p, nil
		})
		if err != nil {
			return nil, err
		}
		countParam, err := parseOptional(qp.Get("count"), strconv.ParseBool)
		if err != nil {
			return nil, err
		}
		searchParam := getOptional(qp.Get("search"))
		var options *armbilling.InvoicesClientListByBillingAccountOptions
		if periodStartDateParam != nil || periodEndDateParam != nil || filterParam != nil || orderByParam != nil || topParam != nil || skipParam != nil || countParam != nil || searchParam != nil {
			options = &armbilling.InvoicesClientListByBillingAccountOptions{
				PeriodStartDate: periodStartDateParam,
				PeriodEndDate:   periodEndDateParam,
				Filter:          filterParam,
				OrderBy:         orderByParam,
				Top:             topParam,
				Skip:            skipParam,
				Count:           countParam,
				Search:          searchParam,
			}
		}
		resp := i.srv.NewListByBillingAccountPager(billingAccountNameParam, options)
		newListByBillingAccountPager = &resp
		i.newListByBillingAccountPager.add(req, newListByBillingAccountPager)
		server.PagerResponderInjectNextLinks(newListByBillingAccountPager, req, func(page *armbilling.InvoicesClientListByBillingAccountResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListByBillingAccountPager, req)
	if err != nil {
		return nil, err
	}
	if !slices.Contains([]int{http.StatusOK}, resp.StatusCode) {
		i.newListByBillingAccountPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListByBillingAccountPager) {
		i.newListByBillingAccountPager.remove(req)
	}
	return resp, nil
}

func (i *InvoicesServerTransport) dispatchNewListByBillingProfilePager(req *http.Request) (*http.Response, error) {
	if i.srv.NewListByBillingProfilePager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListByBillingProfilePager not implemented")}
	}
	newListByBillingProfilePager := i.newListByBillingProfilePager.get(req)
	if newListByBillingProfilePager == nil {
		const regexStr = `/providers/Microsoft\.Billing/billingAccounts/(?P<billingAccountName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/billingProfiles/(?P<billingProfileName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/invoices`
		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()
		billingAccountNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("billingAccountName")])
		if err != nil {
			return nil, err
		}
		billingProfileNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("billingProfileName")])
		if err != nil {
			return nil, err
		}
		periodStartDateParam, err := parseOptional(qp.Get("periodStartDate"), func(v string) (time.Time, error) { return time.Parse(time.DateOnly, v) })
		if err != nil {
			return nil, err
		}
		periodEndDateParam, err := parseOptional(qp.Get("periodEndDate"), func(v string) (time.Time, error) { return time.Parse(time.DateOnly, v) })
		if err != nil {
			return nil, err
		}
		filterParam := getOptional(qp.Get("filter"))
		orderByParam := getOptional(qp.Get("orderBy"))
		topParam, err := parseOptional(qp.Get("top"), func(v string) (int64, error) {
			p, parseErr := strconv.ParseInt(v, 10, 64)
			if parseErr != nil {
				return 0, parseErr
			}
			return p, nil
		})
		if err != nil {
			return nil, err
		}
		skipParam, err := parseOptional(qp.Get("skip"), func(v string) (int64, error) {
			p, parseErr := strconv.ParseInt(v, 10, 64)
			if parseErr != nil {
				return 0, parseErr
			}
			return p, nil
		})
		if err != nil {
			return nil, err
		}
		countParam, err := parseOptional(qp.Get("count"), strconv.ParseBool)
		if err != nil {
			return nil, err
		}
		searchParam := getOptional(qp.Get("search"))
		var options *armbilling.InvoicesClientListByBillingProfileOptions
		if periodStartDateParam != nil || periodEndDateParam != nil || filterParam != nil || orderByParam != nil || topParam != nil || skipParam != nil || countParam != nil || searchParam != nil {
			options = &armbilling.InvoicesClientListByBillingProfileOptions{
				PeriodStartDate: periodStartDateParam,
				PeriodEndDate:   periodEndDateParam,
				Filter:          filterParam,
				OrderBy:         orderByParam,
				Top:             topParam,
				Skip:            skipParam,
				Count:           countParam,
				Search:          searchParam,
			}
		}
		resp := i.srv.NewListByBillingProfilePager(billingAccountNameParam, billingProfileNameParam, options)
		newListByBillingProfilePager = &resp
		i.newListByBillingProfilePager.add(req, newListByBillingProfilePager)
		server.PagerResponderInjectNextLinks(newListByBillingProfilePager, req, func(page *armbilling.InvoicesClientListByBillingProfileResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListByBillingProfilePager, req)
	if err != nil {
		return nil, err
	}
	if !slices.Contains([]int{http.StatusOK}, resp.StatusCode) {
		i.newListByBillingProfilePager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListByBillingProfilePager) {
		i.newListByBillingProfilePager.remove(req)
	}
	return resp, nil
}

func (i *InvoicesServerTransport) dispatchNewListByBillingSubscriptionPager(req *http.Request) (*http.Response, error) {
	if i.srv.NewListByBillingSubscriptionPager == nil {
		return nil, &nonRetriableError{errors.New("fake for method NewListByBillingSubscriptionPager not implemented")}
	}
	newListByBillingSubscriptionPager := i.newListByBillingSubscriptionPager.get(req)
	if newListByBillingSubscriptionPager == nil {
		const regexStr = `/providers/Microsoft\.Billing/billingAccounts/default/billingSubscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/invoices`
		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()
		periodStartDateParam, err := parseOptional(qp.Get("periodStartDate"), func(v string) (time.Time, error) { return time.Parse(time.DateOnly, v) })
		if err != nil {
			return nil, err
		}
		periodEndDateParam, err := parseOptional(qp.Get("periodEndDate"), func(v string) (time.Time, error) { return time.Parse(time.DateOnly, v) })
		if err != nil {
			return nil, err
		}
		filterParam := getOptional(qp.Get("filter"))
		orderByParam := getOptional(qp.Get("orderBy"))
		topParam, err := parseOptional(qp.Get("top"), func(v string) (int64, error) {
			p, parseErr := strconv.ParseInt(v, 10, 64)
			if parseErr != nil {
				return 0, parseErr
			}
			return p, nil
		})
		if err != nil {
			return nil, err
		}
		skipParam, err := parseOptional(qp.Get("skip"), func(v string) (int64, error) {
			p, parseErr := strconv.ParseInt(v, 10, 64)
			if parseErr != nil {
				return 0, parseErr
			}
			return p, nil
		})
		if err != nil {
			return nil, err
		}
		countParam, err := parseOptional(qp.Get("count"), strconv.ParseBool)
		if err != nil {
			return nil, err
		}
		searchParam := getOptional(qp.Get("search"))
		var options *armbilling.InvoicesClientListByBillingSubscriptionOptions
		if periodStartDateParam != nil || periodEndDateParam != nil || filterParam != nil || orderByParam != nil || topParam != nil || skipParam != nil || countParam != nil || searchParam != nil {
			options = &armbilling.InvoicesClientListByBillingSubscriptionOptions{
				PeriodStartDate: periodStartDateParam,
				PeriodEndDate:   periodEndDateParam,
				Filter:          filterParam,
				OrderBy:         orderByParam,
				Top:             topParam,
				Skip:            skipParam,
				Count:           countParam,
				Search:          searchParam,
			}
		}
		resp := i.srv.NewListByBillingSubscriptionPager(options)
		newListByBillingSubscriptionPager = &resp
		i.newListByBillingSubscriptionPager.add(req, newListByBillingSubscriptionPager)
		server.PagerResponderInjectNextLinks(newListByBillingSubscriptionPager, req, func(page *armbilling.InvoicesClientListByBillingSubscriptionResponse, createLink func() string) {
			page.NextLink = to.Ptr(createLink())
		})
	}
	resp, err := server.PagerResponderNext(newListByBillingSubscriptionPager, req)
	if err != nil {
		return nil, err
	}
	if !slices.Contains([]int{http.StatusOK}, resp.StatusCode) {
		i.newListByBillingSubscriptionPager.remove(req)
		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
	}
	if !server.PagerResponderMore(newListByBillingSubscriptionPager) {
		i.newListByBillingSubscriptionPager.remove(req)
	}
	return resp, nil
}

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