// 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 (
	"errors"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
	"net/http"
	"strings"
	"sync"
)

// ServerFactory is a fake server for instances of the armdiscovery.ClientFactory type.
type ServerFactory struct {
	// BookshelfPrivateEndpointConnectionsServer contains the fakes for client BookshelfPrivateEndpointConnectionsClient
	BookshelfPrivateEndpointConnectionsServer BookshelfPrivateEndpointConnectionsServer

	// BookshelfPrivateLinkResourcesServer contains the fakes for client BookshelfPrivateLinkResourcesClient
	BookshelfPrivateLinkResourcesServer BookshelfPrivateLinkResourcesServer

	// BookshelvesServer contains the fakes for client BookshelvesClient
	BookshelvesServer BookshelvesServer

	// ChatModelDeploymentsServer contains the fakes for client ChatModelDeploymentsClient
	ChatModelDeploymentsServer ChatModelDeploymentsServer

	// NodePoolsServer contains the fakes for client NodePoolsClient
	NodePoolsServer NodePoolsServer

	// OperationsServer contains the fakes for client OperationsClient
	OperationsServer OperationsServer

	// ProjectsServer contains the fakes for client ProjectsClient
	ProjectsServer ProjectsServer

	// StorageAssetsServer contains the fakes for client StorageAssetsClient
	StorageAssetsServer StorageAssetsServer

	// StorageContainersServer contains the fakes for client StorageContainersClient
	StorageContainersServer StorageContainersServer

	// SupercomputersServer contains the fakes for client SupercomputersClient
	SupercomputersServer SupercomputersServer

	// ToolsServer contains the fakes for client ToolsClient
	ToolsServer ToolsServer

	// WorkspacePrivateEndpointConnectionsServer contains the fakes for client WorkspacePrivateEndpointConnectionsClient
	WorkspacePrivateEndpointConnectionsServer WorkspacePrivateEndpointConnectionsServer

	// WorkspacePrivateLinkResourcesServer contains the fakes for client WorkspacePrivateLinkResourcesClient
	WorkspacePrivateLinkResourcesServer WorkspacePrivateLinkResourcesServer

	// WorkspacesServer contains the fakes for client WorkspacesClient
	WorkspacesServer WorkspacesServer
}

// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation.
// The returned ServerFactoryTransport instance is connected to an instance of armdiscovery.ClientFactory via the
// azcore.ClientOptions.Transporter field in the client's constructor parameters.
func NewServerFactoryTransport(srv *ServerFactory) *ServerFactoryTransport {
	return &ServerFactoryTransport{
		srv: srv,
	}
}

// ServerFactoryTransport connects instances of armdiscovery.ClientFactory to instances of ServerFactory.
// Don't use this type directly, use NewServerFactoryTransport instead.
type ServerFactoryTransport struct {
	srv                                         *ServerFactory
	trMu                                        sync.Mutex
	trBookshelfPrivateEndpointConnectionsServer *BookshelfPrivateEndpointConnectionsServerTransport
	trBookshelfPrivateLinkResourcesServer       *BookshelfPrivateLinkResourcesServerTransport
	trBookshelvesServer                         *BookshelvesServerTransport
	trChatModelDeploymentsServer                *ChatModelDeploymentsServerTransport
	trNodePoolsServer                           *NodePoolsServerTransport
	trOperationsServer                          *OperationsServerTransport
	trProjectsServer                            *ProjectsServerTransport
	trStorageAssetsServer                       *StorageAssetsServerTransport
	trStorageContainersServer                   *StorageContainersServerTransport
	trSupercomputersServer                      *SupercomputersServerTransport
	trToolsServer                               *ToolsServerTransport
	trWorkspacePrivateEndpointConnectionsServer *WorkspacePrivateEndpointConnectionsServerTransport
	trWorkspacePrivateLinkResourcesServer       *WorkspacePrivateLinkResourcesServerTransport
	trWorkspacesServer                          *WorkspacesServerTransport
}

// Do implements the policy.Transporter interface for ServerFactoryTransport.
func (s *ServerFactoryTransport) 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")}
	}

	client := method[:strings.Index(method, ".")]
	var resp *http.Response
	var err error

	switch client {
	case "BookshelfPrivateEndpointConnectionsClient":
		initServer(&s.trMu, &s.trBookshelfPrivateEndpointConnectionsServer, func() *BookshelfPrivateEndpointConnectionsServerTransport {
			return NewBookshelfPrivateEndpointConnectionsServerTransport(&s.srv.BookshelfPrivateEndpointConnectionsServer)
		})
		resp, err = s.trBookshelfPrivateEndpointConnectionsServer.Do(req)
	case "BookshelfPrivateLinkResourcesClient":
		initServer(&s.trMu, &s.trBookshelfPrivateLinkResourcesServer, func() *BookshelfPrivateLinkResourcesServerTransport {
			return NewBookshelfPrivateLinkResourcesServerTransport(&s.srv.BookshelfPrivateLinkResourcesServer)
		})
		resp, err = s.trBookshelfPrivateLinkResourcesServer.Do(req)
	case "BookshelvesClient":
		initServer(&s.trMu, &s.trBookshelvesServer, func() *BookshelvesServerTransport { return NewBookshelvesServerTransport(&s.srv.BookshelvesServer) })
		resp, err = s.trBookshelvesServer.Do(req)
	case "ChatModelDeploymentsClient":
		initServer(&s.trMu, &s.trChatModelDeploymentsServer, func() *ChatModelDeploymentsServerTransport {
			return NewChatModelDeploymentsServerTransport(&s.srv.ChatModelDeploymentsServer)
		})
		resp, err = s.trChatModelDeploymentsServer.Do(req)
	case "NodePoolsClient":
		initServer(&s.trMu, &s.trNodePoolsServer, func() *NodePoolsServerTransport { return NewNodePoolsServerTransport(&s.srv.NodePoolsServer) })
		resp, err = s.trNodePoolsServer.Do(req)
	case "OperationsClient":
		initServer(&s.trMu, &s.trOperationsServer, func() *OperationsServerTransport { return NewOperationsServerTransport(&s.srv.OperationsServer) })
		resp, err = s.trOperationsServer.Do(req)
	case "ProjectsClient":
		initServer(&s.trMu, &s.trProjectsServer, func() *ProjectsServerTransport { return NewProjectsServerTransport(&s.srv.ProjectsServer) })
		resp, err = s.trProjectsServer.Do(req)
	case "StorageAssetsClient":
		initServer(&s.trMu, &s.trStorageAssetsServer, func() *StorageAssetsServerTransport {
			return NewStorageAssetsServerTransport(&s.srv.StorageAssetsServer)
		})
		resp, err = s.trStorageAssetsServer.Do(req)
	case "StorageContainersClient":
		initServer(&s.trMu, &s.trStorageContainersServer, func() *StorageContainersServerTransport {
			return NewStorageContainersServerTransport(&s.srv.StorageContainersServer)
		})
		resp, err = s.trStorageContainersServer.Do(req)
	case "SupercomputersClient":
		initServer(&s.trMu, &s.trSupercomputersServer, func() *SupercomputersServerTransport {
			return NewSupercomputersServerTransport(&s.srv.SupercomputersServer)
		})
		resp, err = s.trSupercomputersServer.Do(req)
	case "ToolsClient":
		initServer(&s.trMu, &s.trToolsServer, func() *ToolsServerTransport { return NewToolsServerTransport(&s.srv.ToolsServer) })
		resp, err = s.trToolsServer.Do(req)
	case "WorkspacePrivateEndpointConnectionsClient":
		initServer(&s.trMu, &s.trWorkspacePrivateEndpointConnectionsServer, func() *WorkspacePrivateEndpointConnectionsServerTransport {
			return NewWorkspacePrivateEndpointConnectionsServerTransport(&s.srv.WorkspacePrivateEndpointConnectionsServer)
		})
		resp, err = s.trWorkspacePrivateEndpointConnectionsServer.Do(req)
	case "WorkspacePrivateLinkResourcesClient":
		initServer(&s.trMu, &s.trWorkspacePrivateLinkResourcesServer, func() *WorkspacePrivateLinkResourcesServerTransport {
			return NewWorkspacePrivateLinkResourcesServerTransport(&s.srv.WorkspacePrivateLinkResourcesServer)
		})
		resp, err = s.trWorkspacePrivateLinkResourcesServer.Do(req)
	case "WorkspacesClient":
		initServer(&s.trMu, &s.trWorkspacesServer, func() *WorkspacesServerTransport { return NewWorkspacesServerTransport(&s.srv.WorkspacesServer) })
		resp, err = s.trWorkspacesServer.Do(req)
	default:
		err = fmt.Errorf("unhandled client %s", client)
	}

	if err != nil {
		return nil, err
	}

	return resp, nil
}
