package apirestcxy

import (
	"nms_nbi/src/framework/logger"
	"nms_nbi/src/framework/middleware"
	"nms_nbi/src/modules/api_rest_cxy/controller"
	"nms_nbi/src/modules/api_rest_cxy/utils/kafka"
	"nms_nbi/src/modules/api_rest_cxy/utils/oss"

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

// 模块路由注册 - 中国星网网络创新研究院有限公司企业标准
func Setup(router *gin.Engine) {
	logger.Infof("开始加载 ====> NMS-CXY 北向模块路由")

	apiRest := router.Group("nms-cxy/api/rest")

	// 启动时需要的初始参数
	InitLoad()

	// 安全管理
	securityManagementGroup := apiRest.Group("/securityManagement")
	{
		// 鉴权登录接口
		securityManagementGroup.POST("/:apiVersion/oauth/token",
			controller.NewSecurity.OauthTokenLogin,
		)
		// 握手消息接口
		securityManagementGroup.POST("/:apiVersion/oauth/handshake",
			middleware.PreAuthorize(nil),
			controller.NewSecurity.Handshake,
		)
		// 退出消息接口
		securityManagementGroup.DELETE("/:apiVersion/oauth/token",
			middleware.PreAuthorize(nil),
			controller.NewSecurity.OauthTokenLogout,
		)
	}

	// 系统管理
	systemManagementGroup := apiRest.Group("/systemManagement")
	{
		// 软件版本查询接口
		systemManagementGroup.GET("/:apiVersion/softwareVersion",
			middleware.PreAuthorize(nil),
			controller.NewSystem.SoftwareVersionInfo,
		)

		// 软件下载请求接口
		systemManagementGroup.POST("/:apiVersion/softwareDownload",
			middleware.PreAuthorize(nil),
			controller.NewSystem.SoftwareDownloadCheck,
		)
		// 软件下载状态查询接口
		systemManagementGroup.GET("/:apiVersion/softwareDownload",
			middleware.PreAuthorize(nil),
			controller.NewSystem.SoftwareDownloadState,
		)

		// 软件更新请求接口
		systemManagementGroup.POST("/:apiVersion/softwareUpdate",
			middleware.PreAuthorize(nil),
			controller.NewSystem.SoftwareUpdateVersion,
		)
		// 软件更新状态查询接口
		systemManagementGroup.GET("/:apiVersion/softwareUpdate",
			middleware.PreAuthorize(nil),
			controller.NewSystem.SoftwareUpdateState,
		)

		// 网元重启请求接口
		systemManagementGroup.POST("/:apiVersion/reboot",
			middleware.PreAuthorize(nil),
			controller.NewSystem.RebootApp,
		)
		// 网元重启状态查询接口
		systemManagementGroup.GET("/:apiVersion/reboot",
			middleware.PreAuthorize(nil),
			controller.NewSystem.RebootState,
		)

		// 恢复出厂配置请求接口
		systemManagementGroup.POST("/:apiVersion/reinitiate",
			middleware.PreAuthorize(nil),
			controller.NewSystem.ReinitiateApp,
		)
		// 恢复出厂配置状态查询接口
		systemManagementGroup.GET("/:apiVersion/reinitiate",
			middleware.PreAuthorize(nil),
			controller.NewSystem.ReinitiateState,
		)

		// 配置修改接口
		systemManagementGroup.POST("/:apiVersion/config",
			middleware.PreAuthorize(nil),
			controller.NewSystem.ConfigApp,
		)
		// 配置查询接口
		systemManagementGroup.GET("/:apiVersion/config",
			middleware.PreAuthorize(nil),
			controller.NewSystem.ConfigInfo,
		)

		// 告警文件同步请求接口
		systemManagementGroup.POST("/:apiVersion/alarm",
			middleware.PreAuthorize(nil),
			controller.NewSystem.AlarmSysnc,
		)

		// 日志数据同步请求接口
		systemManagementGroup.POST("/:apiVersion/log",
			middleware.PreAuthorize(nil),
			controller.NewSystem.LogSysnc,
		)

		// 业务诊断请求接口
		systemManagementGroup.POST("/:apiVersion/diagnose",
			middleware.PreAuthorize(nil),
			controller.NewSystem.Diagnose,
		)

		// 业务连续性功能控制接口
		systemManagementGroup.POST("/:apiVersion/servicecontinuity",
			middleware.PreAuthorize(nil),
			controller.NewSystem.ServiceContinuity,
		)
	}

	// 测试管理
	testManagementGroup := apiRest.Group("/testManagement")
	{
		// kafka发送消息
		testManagementGroup.POST("/kafka/send",
			middleware.PreAuthorize(nil),
			controller.NewTest.KafkaSend,
		)
		// kafka读取并消费消息
		testManagementGroup.POST("/kafka/readMark",
			middleware.PreAuthorize(nil),
			controller.NewTest.KafkaReadMark,
		)
		// 告警列表
		testManagementGroup.POST("/alarm/list",
			middleware.PreAuthorize(nil),
			controller.NewTest.AlarmList,
		)
		// OSS文件上传
		testManagementGroup.POST("/oss/upload",
			middleware.PreAuthorize(nil),
			controller.NewTest.OssUpload,
		)
		// OSS文件上传测试上报
		testManagementGroup.POST("/oss/testUp",
			middleware.PreAuthorize(nil),
			controller.NewTest.OssTestUp,
		)
	}
}

// InitLoad 初始参数
func InitLoad() {
	// 初始化连接Kafka
	kafka.InitConfig()
	// 初始化连接OSS
	oss.InitConfig()
}
