// 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 armmonitor.ClientFactory type.
type ServerFactory struct {
	// ActionGroupsServer contains the fakes for client ActionGroupsClient
	ActionGroupsServer ActionGroupsServer

	// ActivityLogAlertsServer contains the fakes for client ActivityLogAlertsClient
	ActivityLogAlertsServer ActivityLogAlertsServer

	// ActivityLogsServer contains the fakes for client ActivityLogsClient
	ActivityLogsServer ActivityLogsServer

	// AlertRuleIncidentsServer contains the fakes for client AlertRuleIncidentsClient
	AlertRuleIncidentsServer AlertRuleIncidentsServer

	// AutoscaleSettingsServer contains the fakes for client AutoscaleSettingsClient
	AutoscaleSettingsServer AutoscaleSettingsServer

	// BaselinesServer contains the fakes for client BaselinesClient
	BaselinesServer BaselinesServer

	// CombineServer contains the fakes for client CombineClient
	CombineServer CombineServer

	// DataCollectionEndpointsServer contains the fakes for client DataCollectionEndpointsClient
	DataCollectionEndpointsServer DataCollectionEndpointsServer

	// DataCollectionRuleAssociationsServer contains the fakes for client DataCollectionRuleAssociationsClient
	DataCollectionRuleAssociationsServer DataCollectionRuleAssociationsServer

	// DataCollectionRulesServer contains the fakes for client DataCollectionRulesClient
	DataCollectionRulesServer DataCollectionRulesServer

	// DiagnosticSettingsCategoryServer contains the fakes for client DiagnosticSettingsCategoryClient
	DiagnosticSettingsCategoryServer DiagnosticSettingsCategoryServer

	// DiagnosticSettingsServer contains the fakes for client DiagnosticSettingsClient
	DiagnosticSettingsServer DiagnosticSettingsServer

	// EventCategoriesServer contains the fakes for client EventCategoriesClient
	EventCategoriesServer EventCategoriesServer

	// LogProfilesServer contains the fakes for client LogProfilesClient
	LogProfilesServer LogProfilesServer

	// MetricAlertsServer contains the fakes for client MetricAlertsClient
	MetricAlertsServer MetricAlertsServer

	// MetricAlertsStatusServer contains the fakes for client MetricAlertsStatusClient
	MetricAlertsStatusServer MetricAlertsStatusServer

	// MetricDefinitionsServer contains the fakes for client MetricDefinitionsClient
	MetricDefinitionsServer MetricDefinitionsServer

	// MetricNamespacesServer contains the fakes for client MetricNamespacesClient
	MetricNamespacesServer MetricNamespacesServer

	// MetricsServer contains the fakes for client MetricsClient
	MetricsServer MetricsServer

	// PredictiveMetricServer contains the fakes for client PredictiveMetricClient
	PredictiveMetricServer PredictiveMetricServer

	// PrivateEndpointConnectionsServer contains the fakes for client PrivateEndpointConnectionsClient
	PrivateEndpointConnectionsServer PrivateEndpointConnectionsServer

	// PrivateLinkResourcesServer contains the fakes for client PrivateLinkResourcesClient
	PrivateLinkResourcesServer PrivateLinkResourcesServer

	// PrivateLinkScopeOperationStatusServer contains the fakes for client PrivateLinkScopeOperationStatusClient
	PrivateLinkScopeOperationStatusServer PrivateLinkScopeOperationStatusServer

	// PrivateLinkScopedResourcesServer contains the fakes for client PrivateLinkScopedResourcesClient
	PrivateLinkScopedResourcesServer PrivateLinkScopedResourcesServer

	// PrivateLinkScopesServer contains the fakes for client PrivateLinkScopesClient
	PrivateLinkScopesServer PrivateLinkScopesServer

	// ScheduledQueryRuleServer contains the fakes for client ScheduledQueryRuleClient
	ScheduledQueryRuleServer ScheduledQueryRuleServer

	// ScheduledQueryRulesServer contains the fakes for client ScheduledQueryRulesClient
	ScheduledQueryRulesServer ScheduledQueryRulesServer

	// ServiceDiagnosticSettingsServer contains the fakes for client ServiceDiagnosticSettingsClient
	ServiceDiagnosticSettingsServer ServiceDiagnosticSettingsServer

	// TenantActionGroupsServer contains the fakes for client TenantActionGroupsClient
	TenantActionGroupsServer TenantActionGroupsServer

	// TenantActivityLogsServer contains the fakes for client TenantActivityLogsClient
	TenantActivityLogsServer TenantActivityLogsServer

	// VMInsightsServer contains the fakes for client VMInsightsClient
	VMInsightsServer VMInsightsServer
}

// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation.
// The returned ServerFactoryTransport instance is connected to an instance of armmonitor.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 armmonitor.ClientFactory to instances of ServerFactory.
// Don't use this type directly, use NewServerFactoryTransport instead.
type ServerFactoryTransport struct {
	srv                                     *ServerFactory
	trMu                                    sync.Mutex
	trActionGroupsServer                    *ActionGroupsServerTransport
	trActivityLogAlertsServer               *ActivityLogAlertsServerTransport
	trActivityLogsServer                    *ActivityLogsServerTransport
	trAlertRuleIncidentsServer              *AlertRuleIncidentsServerTransport
	trAutoscaleSettingsServer               *AutoscaleSettingsServerTransport
	trBaselinesServer                       *BaselinesServerTransport
	trCombineServer                         *CombineServerTransport
	trDataCollectionEndpointsServer         *DataCollectionEndpointsServerTransport
	trDataCollectionRuleAssociationsServer  *DataCollectionRuleAssociationsServerTransport
	trDataCollectionRulesServer             *DataCollectionRulesServerTransport
	trDiagnosticSettingsCategoryServer      *DiagnosticSettingsCategoryServerTransport
	trDiagnosticSettingsServer              *DiagnosticSettingsServerTransport
	trEventCategoriesServer                 *EventCategoriesServerTransport
	trLogProfilesServer                     *LogProfilesServerTransport
	trMetricAlertsServer                    *MetricAlertsServerTransport
	trMetricAlertsStatusServer              *MetricAlertsStatusServerTransport
	trMetricDefinitionsServer               *MetricDefinitionsServerTransport
	trMetricNamespacesServer                *MetricNamespacesServerTransport
	trMetricsServer                         *MetricsServerTransport
	trPredictiveMetricServer                *PredictiveMetricServerTransport
	trPrivateEndpointConnectionsServer      *PrivateEndpointConnectionsServerTransport
	trPrivateLinkResourcesServer            *PrivateLinkResourcesServerTransport
	trPrivateLinkScopeOperationStatusServer *PrivateLinkScopeOperationStatusServerTransport
	trPrivateLinkScopedResourcesServer      *PrivateLinkScopedResourcesServerTransport
	trPrivateLinkScopesServer               *PrivateLinkScopesServerTransport
	trScheduledQueryRuleServer              *ScheduledQueryRuleServerTransport
	trScheduledQueryRulesServer             *ScheduledQueryRulesServerTransport
	trServiceDiagnosticSettingsServer       *ServiceDiagnosticSettingsServerTransport
	trTenantActionGroupsServer              *TenantActionGroupsServerTransport
	trTenantActivityLogsServer              *TenantActivityLogsServerTransport
	trVMInsightsServer                      *VMInsightsServerTransport
}

// 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 "ActionGroupsClient":
		initServer(&s.trMu, &s.trActionGroupsServer, func() *ActionGroupsServerTransport { return NewActionGroupsServerTransport(&s.srv.ActionGroupsServer) })
		resp, err = s.trActionGroupsServer.Do(req)
	case "ActivityLogAlertsClient":
		initServer(&s.trMu, &s.trActivityLogAlertsServer, func() *ActivityLogAlertsServerTransport {
			return NewActivityLogAlertsServerTransport(&s.srv.ActivityLogAlertsServer)
		})
		resp, err = s.trActivityLogAlertsServer.Do(req)
	case "ActivityLogsClient":
		initServer(&s.trMu, &s.trActivityLogsServer, func() *ActivityLogsServerTransport { return NewActivityLogsServerTransport(&s.srv.ActivityLogsServer) })
		resp, err = s.trActivityLogsServer.Do(req)
	case "AlertRuleIncidentsClient":
		initServer(&s.trMu, &s.trAlertRuleIncidentsServer, func() *AlertRuleIncidentsServerTransport {
			return NewAlertRuleIncidentsServerTransport(&s.srv.AlertRuleIncidentsServer)
		})
		resp, err = s.trAlertRuleIncidentsServer.Do(req)
	case "AutoscaleSettingsClient":
		initServer(&s.trMu, &s.trAutoscaleSettingsServer, func() *AutoscaleSettingsServerTransport {
			return NewAutoscaleSettingsServerTransport(&s.srv.AutoscaleSettingsServer)
		})
		resp, err = s.trAutoscaleSettingsServer.Do(req)
	case "BaselinesClient":
		initServer(&s.trMu, &s.trBaselinesServer, func() *BaselinesServerTransport { return NewBaselinesServerTransport(&s.srv.BaselinesServer) })
		resp, err = s.trBaselinesServer.Do(req)
	case "CombineClient":
		initServer(&s.trMu, &s.trCombineServer, func() *CombineServerTransport { return NewCombineServerTransport(&s.srv.CombineServer) })
		resp, err = s.trCombineServer.Do(req)
	case "DataCollectionEndpointsClient":
		initServer(&s.trMu, &s.trDataCollectionEndpointsServer, func() *DataCollectionEndpointsServerTransport {
			return NewDataCollectionEndpointsServerTransport(&s.srv.DataCollectionEndpointsServer)
		})
		resp, err = s.trDataCollectionEndpointsServer.Do(req)
	case "DataCollectionRuleAssociationsClient":
		initServer(&s.trMu, &s.trDataCollectionRuleAssociationsServer, func() *DataCollectionRuleAssociationsServerTransport {
			return NewDataCollectionRuleAssociationsServerTransport(&s.srv.DataCollectionRuleAssociationsServer)
		})
		resp, err = s.trDataCollectionRuleAssociationsServer.Do(req)
	case "DataCollectionRulesClient":
		initServer(&s.trMu, &s.trDataCollectionRulesServer, func() *DataCollectionRulesServerTransport {
			return NewDataCollectionRulesServerTransport(&s.srv.DataCollectionRulesServer)
		})
		resp, err = s.trDataCollectionRulesServer.Do(req)
	case "DiagnosticSettingsCategoryClient":
		initServer(&s.trMu, &s.trDiagnosticSettingsCategoryServer, func() *DiagnosticSettingsCategoryServerTransport {
			return NewDiagnosticSettingsCategoryServerTransport(&s.srv.DiagnosticSettingsCategoryServer)
		})
		resp, err = s.trDiagnosticSettingsCategoryServer.Do(req)
	case "DiagnosticSettingsClient":
		initServer(&s.trMu, &s.trDiagnosticSettingsServer, func() *DiagnosticSettingsServerTransport {
			return NewDiagnosticSettingsServerTransport(&s.srv.DiagnosticSettingsServer)
		})
		resp, err = s.trDiagnosticSettingsServer.Do(req)
	case "EventCategoriesClient":
		initServer(&s.trMu, &s.trEventCategoriesServer, func() *EventCategoriesServerTransport {
			return NewEventCategoriesServerTransport(&s.srv.EventCategoriesServer)
		})
		resp, err = s.trEventCategoriesServer.Do(req)
	case "LogProfilesClient":
		initServer(&s.trMu, &s.trLogProfilesServer, func() *LogProfilesServerTransport { return NewLogProfilesServerTransport(&s.srv.LogProfilesServer) })
		resp, err = s.trLogProfilesServer.Do(req)
	case "MetricAlertsClient":
		initServer(&s.trMu, &s.trMetricAlertsServer, func() *MetricAlertsServerTransport { return NewMetricAlertsServerTransport(&s.srv.MetricAlertsServer) })
		resp, err = s.trMetricAlertsServer.Do(req)
	case "MetricAlertsStatusClient":
		initServer(&s.trMu, &s.trMetricAlertsStatusServer, func() *MetricAlertsStatusServerTransport {
			return NewMetricAlertsStatusServerTransport(&s.srv.MetricAlertsStatusServer)
		})
		resp, err = s.trMetricAlertsStatusServer.Do(req)
	case "MetricDefinitionsClient":
		initServer(&s.trMu, &s.trMetricDefinitionsServer, func() *MetricDefinitionsServerTransport {
			return NewMetricDefinitionsServerTransport(&s.srv.MetricDefinitionsServer)
		})
		resp, err = s.trMetricDefinitionsServer.Do(req)
	case "MetricNamespacesClient":
		initServer(&s.trMu, &s.trMetricNamespacesServer, func() *MetricNamespacesServerTransport {
			return NewMetricNamespacesServerTransport(&s.srv.MetricNamespacesServer)
		})
		resp, err = s.trMetricNamespacesServer.Do(req)
	case "MetricsClient":
		initServer(&s.trMu, &s.trMetricsServer, func() *MetricsServerTransport { return NewMetricsServerTransport(&s.srv.MetricsServer) })
		resp, err = s.trMetricsServer.Do(req)
	case "PredictiveMetricClient":
		initServer(&s.trMu, &s.trPredictiveMetricServer, func() *PredictiveMetricServerTransport {
			return NewPredictiveMetricServerTransport(&s.srv.PredictiveMetricServer)
		})
		resp, err = s.trPredictiveMetricServer.Do(req)
	case "PrivateEndpointConnectionsClient":
		initServer(&s.trMu, &s.trPrivateEndpointConnectionsServer, func() *PrivateEndpointConnectionsServerTransport {
			return NewPrivateEndpointConnectionsServerTransport(&s.srv.PrivateEndpointConnectionsServer)
		})
		resp, err = s.trPrivateEndpointConnectionsServer.Do(req)
	case "PrivateLinkResourcesClient":
		initServer(&s.trMu, &s.trPrivateLinkResourcesServer, func() *PrivateLinkResourcesServerTransport {
			return NewPrivateLinkResourcesServerTransport(&s.srv.PrivateLinkResourcesServer)
		})
		resp, err = s.trPrivateLinkResourcesServer.Do(req)
	case "PrivateLinkScopeOperationStatusClient":
		initServer(&s.trMu, &s.trPrivateLinkScopeOperationStatusServer, func() *PrivateLinkScopeOperationStatusServerTransport {
			return NewPrivateLinkScopeOperationStatusServerTransport(&s.srv.PrivateLinkScopeOperationStatusServer)
		})
		resp, err = s.trPrivateLinkScopeOperationStatusServer.Do(req)
	case "PrivateLinkScopedResourcesClient":
		initServer(&s.trMu, &s.trPrivateLinkScopedResourcesServer, func() *PrivateLinkScopedResourcesServerTransport {
			return NewPrivateLinkScopedResourcesServerTransport(&s.srv.PrivateLinkScopedResourcesServer)
		})
		resp, err = s.trPrivateLinkScopedResourcesServer.Do(req)
	case "PrivateLinkScopesClient":
		initServer(&s.trMu, &s.trPrivateLinkScopesServer, func() *PrivateLinkScopesServerTransport {
			return NewPrivateLinkScopesServerTransport(&s.srv.PrivateLinkScopesServer)
		})
		resp, err = s.trPrivateLinkScopesServer.Do(req)
	case "ScheduledQueryRuleClient":
		initServer(&s.trMu, &s.trScheduledQueryRuleServer, func() *ScheduledQueryRuleServerTransport {
			return NewScheduledQueryRuleServerTransport(&s.srv.ScheduledQueryRuleServer)
		})
		resp, err = s.trScheduledQueryRuleServer.Do(req)
	case "ScheduledQueryRulesClient":
		initServer(&s.trMu, &s.trScheduledQueryRulesServer, func() *ScheduledQueryRulesServerTransport {
			return NewScheduledQueryRulesServerTransport(&s.srv.ScheduledQueryRulesServer)
		})
		resp, err = s.trScheduledQueryRulesServer.Do(req)
	case "ServiceDiagnosticSettingsClient":
		initServer(&s.trMu, &s.trServiceDiagnosticSettingsServer, func() *ServiceDiagnosticSettingsServerTransport {
			return NewServiceDiagnosticSettingsServerTransport(&s.srv.ServiceDiagnosticSettingsServer)
		})
		resp, err = s.trServiceDiagnosticSettingsServer.Do(req)
	case "TenantActionGroupsClient":
		initServer(&s.trMu, &s.trTenantActionGroupsServer, func() *TenantActionGroupsServerTransport {
			return NewTenantActionGroupsServerTransport(&s.srv.TenantActionGroupsServer)
		})
		resp, err = s.trTenantActionGroupsServer.Do(req)
	case "TenantActivityLogsClient":
		initServer(&s.trMu, &s.trTenantActivityLogsServer, func() *TenantActivityLogsServerTransport {
			return NewTenantActivityLogsServerTransport(&s.srv.TenantActivityLogsServer)
		})
		resp, err = s.trTenantActivityLogsServer.Do(req)
	case "VMInsightsClient":
		initServer(&s.trMu, &s.trVMInsightsServer, func() *VMInsightsServerTransport { return NewVMInsightsServerTransport(&s.srv.VMInsightsServer) })
		resp, err = s.trVMInsightsServer.Do(req)
	default:
		err = fmt.Errorf("unhandled client %s", client)
	}

	if err != nil {
		return nil, err
	}

	return resp, nil
}
