package networkdata

import (
	"be.ems/src/framework/logger"
	"be.ems/src/framework/middleware"
	"be.ems/src/framework/middleware/collectlogs"
	"be.ems/src/framework/middleware/repeat"
	"be.ems/src/modules/network_data/controller"

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

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

	neDataGroup := router.Group("/neData")

	// 性能统计信息
	kpiGroup := neDataGroup.Group("/kpi")
	{
		kpiGroup.GET("/title",
			middleware.PreAuthorize(nil),
			controller.NewPerfKPI.Title,
		)
		kpiGroup.GET("/data",
			middleware.PreAuthorize(nil),
			controller.NewPerfKPI.GoldKPI,
		)
	}

	// 告警数据信息
	alarmGroup := neDataGroup.Group("/alarm")
	{
		alarmGroup.GET("/list",
			middleware.PreAuthorize(nil),
			controller.NewAlarm.List,
		)
		alarmGroup.DELETE("/:alarmIds",
			middleware.PreAuthorize(nil),
			controller.NewAlarm.Remove,
		)
	}

	// 网元IMS
	imsGroup := neDataGroup.Group("/ims")
	{
		imsGroup.GET("/cdr/list",
			middleware.PreAuthorize(nil),
			controller.NewIMS.CDRList,
		)
		imsGroup.DELETE("/cdr/:cdrIds",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.imsCDR", collectlogs.BUSINESS_TYPE_DELETE)),
			controller.NewIMS.CDRRemove,
		)
		imsGroup.POST("/cdr/export",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.imsCDR", collectlogs.BUSINESS_TYPE_EXPORT)),
			controller.NewIMS.CDRExport,
		)
		imsGroup.GET("/session/num",
			middleware.PreAuthorize(nil),
			controller.NewIMS.UeSessionNum,
		)
		imsGroup.GET("/session/list",
			middleware.PreAuthorize(nil),
			controller.NewIMS.UeSessionList,
		)
	}

	// 网元SMSC
	smscGroup := neDataGroup.Group("/smsc")
	{
		smscGroup.GET("/cdr/list",
			middleware.PreAuthorize(nil),
			controller.NewSMSC.CDRList,
		)
		smscGroup.DELETE("/cdr/:cdrIds",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.smscCDR", collectlogs.BUSINESS_TYPE_DELETE)),
			controller.NewSMSC.CDRRemove,
		)
		smscGroup.POST("/cdr/export",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.smscCDR", collectlogs.BUSINESS_TYPE_EXPORT)),
			controller.NewSMSC.CDRExport,
		)
	}

	// 网元SMF
	smfGroup := neDataGroup.Group("/smf")
	{
		smfGroup.GET("/cdr/list",
			middleware.PreAuthorize(nil),
			controller.NewSMF.CDRList,
		)
		smfGroup.DELETE("/cdr/:cdrIds",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.smfCDR", collectlogs.BUSINESS_TYPE_DELETE)),
			controller.NewSMF.CDRRemove,
		)
		smfGroup.POST("/cdr/export",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.smfCDR", collectlogs.BUSINESS_TYPE_EXPORT)),
			controller.NewSMF.CDRExport,
		)
		smfGroup.GET("/sub/num",
			middleware.PreAuthorize(nil),
			controller.NewSMF.SubUserNum,
		)
		smfGroup.GET("/sub/list",
			middleware.PreAuthorize(nil),
			controller.NewSMF.SubUserList,
		)
	}

	// 网元AMF
	amfGroup := neDataGroup.Group("/amf")
	{
		amfGroup.GET("/ue/list",
			middleware.PreAuthorize(nil),
			controller.NewAMF.UEList,
		)
		amfGroup.DELETE("/ue/:ueIds",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.amfUE", collectlogs.BUSINESS_TYPE_DELETE)),
			controller.NewAMF.UERemove,
		)
		amfGroup.POST("/ue/export",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.amfUE", collectlogs.BUSINESS_TYPE_EXPORT)),
			controller.NewAMF.UEExport,
		)
		amfGroup.GET("/nb/list",
			middleware.PreAuthorize(nil),
			controller.NewAMF.NbInfoList,
		)
		amfGroup.GET("/nb/list-cfg",
			middleware.PreAuthorize(nil),
			controller.NewAMF.NbStateList,
		)
	}

	// 网元UPF
	upfGroup := neDataGroup.Group("/upf")
	{
		upfGroup.GET("/totalFlow",
			middleware.PreAuthorize(nil),
			controller.NewUPF.TotalFlow,
		)
	}

	// 网元UDM 鉴权用户信息
	udmAuthGroup := neDataGroup.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 := neDataGroup.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,
		)
	}

	// 网元MME
	mmeGroup := neDataGroup.Group("/mme")
	{
		mmeGroup.GET("/ue/list",
			middleware.PreAuthorize(nil),
			controller.NewMME.UEList,
		)
		mmeGroup.DELETE("/ue/:ueIds",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.mmeUE", collectlogs.BUSINESS_TYPE_DELETE)),
			controller.NewMME.UERemove,
		)
		mmeGroup.POST("/ue/export",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.mmeUE", collectlogs.BUSINESS_TYPE_EXPORT)),
			controller.NewMME.UEExport,
		)
		mmeGroup.GET("/nb/list",
			middleware.PreAuthorize(nil),
			controller.NewMME.NbInfoList,
		)
		mmeGroup.GET("/nb/list-cfg",
			middleware.PreAuthorize(nil),
			controller.NewMME.NbStateList,
		)
	}

	// 网元SGWC
	sgwcGroup := neDataGroup.Group("/sgwc")
	{
		sgwcGroup.GET("/cdr/list",
			middleware.PreAuthorize(nil),
			controller.NewSGWC.CDRList,
		)
		sgwcGroup.DELETE("/cdr/:cdrIds",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sgwcCDR", collectlogs.BUSINESS_TYPE_DELETE)),
			controller.NewSGWC.CDRRemove,
		)
		sgwcGroup.POST("/cdr/export",
			middleware.PreAuthorize(nil),
			collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sgwcCDR", collectlogs.BUSINESS_TYPE_EXPORT)),
			controller.NewSGWC.CDRExport,
		)
	}
}
