// 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 armresiliencemanagement.ClientFactory type.
type ServerFactory struct {
	// DrillResourcesServer contains the fakes for client DrillResourcesClient
	DrillResourcesServer DrillResourcesServer

	// DrillRunResourcesServer contains the fakes for client DrillRunResourcesClient
	DrillRunResourcesServer DrillRunResourcesServer

	// DrillRunsServer contains the fakes for client DrillRunsClient
	DrillRunsServer DrillRunsServer

	// DrillsServer contains the fakes for client DrillsClient
	DrillsServer DrillsServer

	// EnrollmentsServer contains the fakes for client EnrollmentsClient
	EnrollmentsServer EnrollmentsServer

	// GoalAssignmentsServer contains the fakes for client GoalAssignmentsClient
	GoalAssignmentsServer GoalAssignmentsServer

	// GoalResourcesServer contains the fakes for client GoalResourcesClient
	GoalResourcesServer GoalResourcesServer

	// GoalTemplatesServer contains the fakes for client GoalTemplatesClient
	GoalTemplatesServer GoalTemplatesServer

	// OperationStatusServer contains the fakes for client OperationStatusClient
	OperationStatusServer OperationStatusServer

	// OperationsServer contains the fakes for client OperationsClient
	OperationsServer OperationsServer

	// RecoveryJobResourcesServer contains the fakes for client RecoveryJobResourcesClient
	RecoveryJobResourcesServer RecoveryJobResourcesServer

	// RecoveryJobsServer contains the fakes for client RecoveryJobsClient
	RecoveryJobsServer RecoveryJobsServer

	// RecoveryPlanActionsServer contains the fakes for client RecoveryPlanActionsClient
	RecoveryPlanActionsServer RecoveryPlanActionsServer

	// RecoveryPlansServer contains the fakes for client RecoveryPlansClient
	RecoveryPlansServer RecoveryPlansServer

	// RecoveryResourcesServer contains the fakes for client RecoveryResourcesClient
	RecoveryResourcesServer RecoveryResourcesServer

	// UnifiedResilienceItemsServer contains the fakes for client UnifiedResilienceItemsClient
	UnifiedResilienceItemsServer UnifiedResilienceItemsServer

	// UsagePlansServer contains the fakes for client UsagePlansClient
	UsagePlansServer UsagePlansServer
}

// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation.
// The returned ServerFactoryTransport instance is connected to an instance of armresiliencemanagement.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 armresiliencemanagement.ClientFactory to instances of ServerFactory.
// Don't use this type directly, use NewServerFactoryTransport instead.
type ServerFactoryTransport struct {
	srv                            *ServerFactory
	trMu                           sync.Mutex
	trDrillResourcesServer         *DrillResourcesServerTransport
	trDrillRunResourcesServer      *DrillRunResourcesServerTransport
	trDrillRunsServer              *DrillRunsServerTransport
	trDrillsServer                 *DrillsServerTransport
	trEnrollmentsServer            *EnrollmentsServerTransport
	trGoalAssignmentsServer        *GoalAssignmentsServerTransport
	trGoalResourcesServer          *GoalResourcesServerTransport
	trGoalTemplatesServer          *GoalTemplatesServerTransport
	trOperationStatusServer        *OperationStatusServerTransport
	trOperationsServer             *OperationsServerTransport
	trRecoveryJobResourcesServer   *RecoveryJobResourcesServerTransport
	trRecoveryJobsServer           *RecoveryJobsServerTransport
	trRecoveryPlanActionsServer    *RecoveryPlanActionsServerTransport
	trRecoveryPlansServer          *RecoveryPlansServerTransport
	trRecoveryResourcesServer      *RecoveryResourcesServerTransport
	trUnifiedResilienceItemsServer *UnifiedResilienceItemsServerTransport
	trUsagePlansServer             *UsagePlansServerTransport
}

// 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 "DrillResourcesClient":
		initServer(&s.trMu, &s.trDrillResourcesServer, func() *DrillResourcesServerTransport {
			return NewDrillResourcesServerTransport(&s.srv.DrillResourcesServer)
		})
		resp, err = s.trDrillResourcesServer.Do(req)
	case "DrillRunResourcesClient":
		initServer(&s.trMu, &s.trDrillRunResourcesServer, func() *DrillRunResourcesServerTransport {
			return NewDrillRunResourcesServerTransport(&s.srv.DrillRunResourcesServer)
		})
		resp, err = s.trDrillRunResourcesServer.Do(req)
	case "DrillRunsClient":
		initServer(&s.trMu, &s.trDrillRunsServer, func() *DrillRunsServerTransport { return NewDrillRunsServerTransport(&s.srv.DrillRunsServer) })
		resp, err = s.trDrillRunsServer.Do(req)
	case "DrillsClient":
		initServer(&s.trMu, &s.trDrillsServer, func() *DrillsServerTransport { return NewDrillsServerTransport(&s.srv.DrillsServer) })
		resp, err = s.trDrillsServer.Do(req)
	case "EnrollmentsClient":
		initServer(&s.trMu, &s.trEnrollmentsServer, func() *EnrollmentsServerTransport { return NewEnrollmentsServerTransport(&s.srv.EnrollmentsServer) })
		resp, err = s.trEnrollmentsServer.Do(req)
	case "GoalAssignmentsClient":
		initServer(&s.trMu, &s.trGoalAssignmentsServer, func() *GoalAssignmentsServerTransport {
			return NewGoalAssignmentsServerTransport(&s.srv.GoalAssignmentsServer)
		})
		resp, err = s.trGoalAssignmentsServer.Do(req)
	case "GoalResourcesClient":
		initServer(&s.trMu, &s.trGoalResourcesServer, func() *GoalResourcesServerTransport {
			return NewGoalResourcesServerTransport(&s.srv.GoalResourcesServer)
		})
		resp, err = s.trGoalResourcesServer.Do(req)
	case "GoalTemplatesClient":
		initServer(&s.trMu, &s.trGoalTemplatesServer, func() *GoalTemplatesServerTransport {
			return NewGoalTemplatesServerTransport(&s.srv.GoalTemplatesServer)
		})
		resp, err = s.trGoalTemplatesServer.Do(req)
	case "OperationStatusClient":
		initServer(&s.trMu, &s.trOperationStatusServer, func() *OperationStatusServerTransport {
			return NewOperationStatusServerTransport(&s.srv.OperationStatusServer)
		})
		resp, err = s.trOperationStatusServer.Do(req)
	case "OperationsClient":
		initServer(&s.trMu, &s.trOperationsServer, func() *OperationsServerTransport { return NewOperationsServerTransport(&s.srv.OperationsServer) })
		resp, err = s.trOperationsServer.Do(req)
	case "RecoveryJobResourcesClient":
		initServer(&s.trMu, &s.trRecoveryJobResourcesServer, func() *RecoveryJobResourcesServerTransport {
			return NewRecoveryJobResourcesServerTransport(&s.srv.RecoveryJobResourcesServer)
		})
		resp, err = s.trRecoveryJobResourcesServer.Do(req)
	case "RecoveryJobsClient":
		initServer(&s.trMu, &s.trRecoveryJobsServer, func() *RecoveryJobsServerTransport { return NewRecoveryJobsServerTransport(&s.srv.RecoveryJobsServer) })
		resp, err = s.trRecoveryJobsServer.Do(req)
	case "RecoveryPlanActionsClient":
		initServer(&s.trMu, &s.trRecoveryPlanActionsServer, func() *RecoveryPlanActionsServerTransport {
			return NewRecoveryPlanActionsServerTransport(&s.srv.RecoveryPlanActionsServer)
		})
		resp, err = s.trRecoveryPlanActionsServer.Do(req)
	case "RecoveryPlansClient":
		initServer(&s.trMu, &s.trRecoveryPlansServer, func() *RecoveryPlansServerTransport {
			return NewRecoveryPlansServerTransport(&s.srv.RecoveryPlansServer)
		})
		resp, err = s.trRecoveryPlansServer.Do(req)
	case "RecoveryResourcesClient":
		initServer(&s.trMu, &s.trRecoveryResourcesServer, func() *RecoveryResourcesServerTransport {
			return NewRecoveryResourcesServerTransport(&s.srv.RecoveryResourcesServer)
		})
		resp, err = s.trRecoveryResourcesServer.Do(req)
	case "UnifiedResilienceItemsClient":
		initServer(&s.trMu, &s.trUnifiedResilienceItemsServer, func() *UnifiedResilienceItemsServerTransport {
			return NewUnifiedResilienceItemsServerTransport(&s.srv.UnifiedResilienceItemsServer)
		})
		resp, err = s.trUnifiedResilienceItemsServer.Do(req)
	case "UsagePlansClient":
		initServer(&s.trMu, &s.trUsagePlansServer, func() *UsagePlansServerTransport { return NewUsagePlansServerTransport(&s.srv.UsagePlansServer) })
		resp, err = s.trUsagePlansServer.Do(req)
	default:
		err = fmt.Errorf("unhandled client %s", client)
	}

	if err != nil {
		return nil, err
	}

	return resp, nil
}
