package rpc_apis

import (
	"gd_management_gateway/rpc_apis/gd_admin"
	"gd_management_gateway/rpc_apis/gd_crontab"
	"gd_management_gateway/rpc_apis/gd_management"
	"gd_management_gateway/rpc_apis/gd_service"
	"gd_management_gateway/rpc_apis/gd_statistics"

	"gd_management_gateway/common.in/config"
)

//var Vehicle *gd_vehicle.GdVehicleXClient
//var Service *gd_service.GdServiceXClient
var Management *gd_management.GdManagementXClient
var Admin *gd_admin.GdAdminXClient
var Statistics *gd_statistics.GdStatisticsXClient
var Service *gd_service.GdServiceXClient
var Crontab *gd_crontab.GdCrontabXClient

func Init(etcdAddrs []string, conf *config.Configure) {
	Management = &gd_management.GdManagementXClient{}
	Management.Init(etcdAddrs, conf.Rpc.BasePath, conf.Rpc.Management.Name)

	Admin = &gd_admin.GdAdminXClient{}
	Admin.Init(etcdAddrs, conf.Rpc.BasePath, conf.Rpc.Admin.Name)

	Statistics = &gd_statistics.GdStatisticsXClient{}
	Statistics.Init(etcdAddrs, conf.Rpc.BasePath, conf.Rpc.Statistics.Name)

	Service = &gd_service.GdServiceXClient{}
	Service.Init(etcdAddrs, conf.Rpc.BasePath, conf.Rpc.Service.Name)

	Crontab = &gd_crontab.GdCrontabXClient{}
	Crontab.Init(etcdAddrs, conf.Rpc.BasePath, conf.Rpc.Crontab.Name)
}

func InitForK8s(conf *config.Configure) {
	Service = &gd_service.GdServiceXClient{}
	Service.InitForK8s(conf.Rpc.Service.Name, conf.Rpc.Service.ServiceName, conf.Rpc.Service.ServicePort.String())

	Management = &gd_management.GdManagementXClient{}
	Management.InitForK8s(conf.Rpc.Management.Name, conf.Rpc.Management.ServiceName, conf.Rpc.Management.ServicePort.String())

	Statistics = &gd_statistics.GdStatisticsXClient{}
	Statistics.InitForK8s(conf.Rpc.Statistics.Name, conf.Rpc.Statistics.ServiceName, conf.Rpc.Statistics.ServicePort.String())

	Admin = &gd_admin.GdAdminXClient{}
	Admin.InitForK8s(conf.Rpc.Admin.Name, conf.Rpc.Admin.ServiceName, conf.Rpc.Admin.ServicePort.String())

	Crontab = &gd_crontab.GdCrontabXClient{}
	Crontab.InitForK8s(conf.Rpc.Crontab.Name, conf.Rpc.Crontab.ServiceName, conf.Rpc.Crontab.ServicePort.String())

}
