package main

import (
	"fmt"

	jsonrpclite "git.ius.plus/justin.xing/JsonRpcLiteGo"
)

var (
	dingTalkService             *DingTalkService             = new(DingTalkService)
	loginService                *LoginService                = new(LoginService)
	adminService                *AdminService                = new(AdminService)
	departmentService           *DepartmentService           = new(DepartmentService)
	employeeService             *EmployeeService             = new(EmployeeService)
	workingDayService           *WorkingDayService           = new(WorkingDayService)
	workingDayStatisticsService *WorkingDayStatisticsService = new(WorkingDayStatisticsService)
	statisticsTableService      *StatisticsTableService      = new(StatisticsTableService)
	viewCodeService             *ViewCodeService             = new(ViewCodeService)
	emailService                *EmailService                = new(EmailService)
	holidayService              *HolidayService              = new(HolidayService)
	domainService               *DomainService               = new(DomainService)
	messageTemplateService      *MessageTemplateService      = new(MessageTemplateService)
	progressService             *ProgressService             = new(ProgressService)
)

func main() {
	//Initialize database manager.
	databaseManager.Initialize()
	//Start session manager
	sessionManager.Start()
	//Create and start rpc server.
	jsonrpclite.SetRpcLogger(Logger)

	dingTalkService.initialize()
	progressService.initialize()

	router := jsonrpclite.NewRpcRouter()
	router.RegisterService("DingTalkService", dingTalkService)
	router.RegisterService("LoginService", loginService)
	router.RegisterService("AdminService", adminService)
	router.RegisterService("DepartmentService", departmentService)
	router.RegisterService("EmployeeService", employeeService)
	router.RegisterService("WorkingDayService", workingDayService)
	router.RegisterService("WorkingDayStatisticsService", workingDayStatisticsService)
	router.RegisterService("StatisticsTableService", statisticsTableService)
	router.RegisterService("ViewCodeService", viewCodeService)
	router.RegisterService("EmailService", emailService)
	router.RegisterService("HolidayService", holidayService)
	router.RegisterService("DomainService", domainService)
	router.RegisterService("MessageTemplateService", messageTemplateService)
	router.RegisterService("ProgressService", progressService)

	engine := jsonrpclite.NewRpcHttpServerEngine(8080)
	//engine := jsonrpclite.NewRpcHttpServerEngine(12087)
	server := jsonrpclite.NewRpcServer(engine)
	server.Start(router)
	fmt.Println("Server started.")
	fmt.Scanln()
}
