// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.

package rpc

import (
	"LAPP_ACURA_MOM_BACKEND/container"
	"reflect"
)

type RouteManager struct {
	componentContainer   container.ComponentContainer
	serviceRouteManagers []*ServiceRouteManager
}

func NewRouteManager(componentContainer container.ComponentContainer) *RouteManager {
	return &RouteManager{componentContainer, make([]*ServiceRouteManager, 0, 100)}
}

func (manager *RouteManager) RegisterService(factory interface{}) *ServiceRouteManager {
	return manager.RegisterRoute(reflect.ValueOf(factory).Type().Out(0))
}

func (manager *RouteManager) RegisterRoute(serviceType reflect.Type) *ServiceRouteManager {
	serviceRouteManager := NewServiceRouteManager(manager.componentContainer, serviceType)
	manager.serviceRouteManagers = append(manager.serviceRouteManagers, serviceRouteManager)
	return serviceRouteManager
}

func (manager *RouteManager) ServiceRouteManagers() []*ServiceRouteManager {
	return manager.serviceRouteManagers
}
