package networkelement

import (
	"ems.agt/src/framework/logger"
	"ems.agt/src/framework/middleware"
	"ems.agt/src/framework/middleware/collectlogs"
	"ems.agt/src/framework/middleware/repeat"
	"ems.agt/src/modules/network_element/controller"

	"github.com/gin-gonic/gin"
)

// 模块路由注册
func Setup(router *gin.Engine) {
	logger.Infof("开始加载 ====> network_element 模块路由")

	neGroup := router.Group("/ne")
	{
		neGroup.GET("/info",
			middleware.PreAuthorize(nil),
			controller.NewNeInfo.NeTypeAndID,
		)
	}

	// UDM鉴权用户信息
	udmAuthGroup := neGroup.Group("/udm/auth")
	{
		udmAuthGroup.PUT("/resetData/:neId",
			repeat.RepeatSubmit(5),
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_CLEAN)),
			controller.NewUDMAuth.ResetData,
		)
		udmAuthGroup.GET("/list",
			middleware.PreAuthorize(nil),
			controller.NewUDMAuth.List,
		)
		udmAuthGroup.GET("/:neId/:imsi",
			middleware.PreAuthorize(nil),
			controller.NewUDMAuth.Info,
		)
		udmAuthGroup.POST("/:neId",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_INSERT)),
			controller.NewUDMAuth.Add,
		)
		udmAuthGroup.POST("/:neId/:num",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_INSERT)),
			controller.NewUDMAuth.Adds,
		)
		udmAuthGroup.PUT("/:neId",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_UPDATE)),
			controller.NewUDMAuth.Edit,
		)
		udmAuthGroup.DELETE("/:neId/:imsi",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_DELETE)),
			controller.NewUDMAuth.Remove,
		)
		udmAuthGroup.DELETE("/:neId/:imsi/:num",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_DELETE)),
			controller.NewUDMAuth.Removes,
		)
		udmAuthGroup.POST("/export",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_EXPORT)),
			controller.NewUDMAuth.Export,
		)
		udmAuthGroup.POST("/import",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_IMPORT)),
			controller.NewUDMAuth.Import,
		)
	}

	// UDM签约用户信息
	udmSubGroup := neGroup.Group("/udm/sub")
	{
		udmSubGroup.PUT("/resetData/:neId",
			repeat.RepeatSubmit(5),
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_CLEAN)),
			controller.NewUDMSub.ResetData,
		)
		udmSubGroup.GET("/list",
			middleware.PreAuthorize(nil),
			controller.NewUDMSub.List,
		)
		udmSubGroup.GET("/:neId/:imsi",
			middleware.PreAuthorize(nil),
			controller.NewUDMSub.Info,
		)
		udmSubGroup.POST("/:neId",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_INSERT)),
			controller.NewUDMSub.Add,
		)
		udmSubGroup.POST("/:neId/:num",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_INSERT)),
			controller.NewUDMSub.Adds,
		)
		udmSubGroup.PUT("/:neId",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_UPDATE)),
			controller.NewUDMSub.Edit,
		)
		udmSubGroup.DELETE("/:neId/:imsi",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_DELETE)),
			controller.NewUDMSub.Remove,
		)
		udmSubGroup.DELETE("/:neId/:imsi/:num",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_DELETE)),
			controller.NewUDMSub.Removes,
		)
		udmSubGroup.POST("/export",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_EXPORT)),
			controller.NewUDMSub.Export,
		)
		udmSubGroup.POST("/import",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmSub", collectlogs.BUSINESS_TYPE_IMPORT)),
			controller.NewUDMSub.Import,
		)
	}

}
