package routes

import (
	"LAPP_ACURA_MOM_BACKEND/container"
	"LAPP_ACURA_MOM_BACKEND/db"
	"LAPP_ACURA_MOM_BACKEND/grmi"
	"LAPP_ACURA_MOM_BACKEND/messaging"
	"LAPP_ACURA_MOM_BACKEND/rpc"
	_ "LAPP_ACURA_MOM_BACKEND/services/base/specifications"
	_ "LAPP_ACURA_MOM_BACKEND/web/controllers/base"
	_ "LAPP_ACURA_MOM_BACKEND/web/controllers/common"
	homereg "LAPP_ACURA_MOM_BACKEND/web/controllers/home"
	_ "LAPP_ACURA_MOM_BACKEND/web/controllers/jit"
	_ "LAPP_ACURA_MOM_BACKEND/web/controllers/me"
	_ "LAPP_ACURA_MOM_BACKEND/web/controllers/ods"
	_ "LAPP_ACURA_MOM_BACKEND/web/controllers/om"
	_ "LAPP_ACURA_MOM_BACKEND/web/controllers/pln"
	_ "LAPP_ACURA_MOM_BACKEND/web/controllers/pm"
	_ "LAPP_ACURA_MOM_BACKEND/web/controllers/qm"
	_ "LAPP_ACURA_MOM_BACKEND/web/controllers/report"
	"LAPP_ACURA_MOM_BACKEND/web/middleware"
	"LAPP_ACURA_MOM_BACKEND/web/middleware/cors"
	"github.com/kataras/iris/v12"
)

// 所有的路由
func Hub(app *iris.Application) {

	/* 定义路由 */
	main := app.Party("/", cors.Mycors()).AllowMethods(iris.MethodOptions)
	//中间件，验证token和权限路径
	main.Use(middleware.ServeHTTP)

	home := main.Party("/")
	homereg.RegisterBaseRoutes(home)

	// 用户API模块
	//user := main.Party("/user")
	//user.Post("/login", controllers.Login)            //登录
	//user.Get("/plants", controllers.PlantsTable)      //车间列表
	//user.Get("/getuserinfo", controllers.GetUserInfo) // 返回用户信息
	//个人中心
	//user.Get("/profile", controllers.GetSysUserProfile)  //获取当前登录用户
	//user.Get("/getimg", controllers.GetImg)              //重定向获取图片
	//user.Post("/avatar", controllers.InsetSysUserAvatar) //上传图片
	//user.Put("/pwd", controllers.SysUserUpdatePwd)       //更新密码

	//// 权限API模块
	admin := main.Party("/admin")
	{
		messaging.BindRoutes(admin)

		grmi.BindRoutes(admin)
		transactionHandlerFactory := container.NewTransactionHandlerFactory(db.Eloquent.Master())
		container.RegisterRoutes(admin, rpc.DefaultMethodInvokerBuilder.Build, container.GlobalInformations, transactionHandlerFactory)
	}
}
