package controller

import (
	"fmt"

	"be.ems/src/framework/resp"
	"be.ems/src/modules/ne_data/model"
	neDataService "be.ems/src/modules/ne_data/service"

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

// 实例化控制层 AlarmLogController 结构体
var NewAlarmLog = &AlarmLogController{
	alarmLogService:   neDataService.NewAlarmLog,
	alarmEventService: neDataService.NewAlarmEvent,
}

// 告警数据
//
// PATH /alarm/log
type AlarmLogController struct {
	alarmLogService   *neDataService.AlarmLog   // 告警日志信息服务
	alarmEventService *neDataService.AlarmEvent // 告警事件信息服务
}

// 告警日志列表
//
// GET /list
//
//	@Tags			ne_data/alarm_log
//	@Accept			json
//	@Produce		json
//	@Param			neType			query		string	false	"NE Type"	Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
//	@Param			neId			query		string	false	"NE ID The actual record is the network element RmUid"
//	@Param			alarmLogType	query		string	false	"AlarmLog type Communication AlarmLogs=1, Equipment AlarmLogs=2, Processing faults=3, Environmental AlarmLogs=4, Quality of service AlarmLogs=5"	Enums(1,2,3,4,5)
//	@Param			alarmStatus		query		string	false	"Alarm status 0:clear, 1:active"																													Enums(0,1)
//	@Param			origSeverity	query		string	false	"Alarm Type 1: Critical, 2: Major, 3: Minor, 4: Warning"																							Enums(1,2,3,4)
//	@Param			sortField		query		string	false	"Sort fields, fill in result fields"																												default(event_time)
//	@Param			sortOrder		query		string	false	"Sort by ascending or descending order, asc desc"																									default(asc)
//	@Param			pageNum			query		number	true	"pageNum"																																			default(1)
//	@Param			pageSize		query		number	true	"pageSize"																																			default(10)
//	@Success		200				{object}	object	"Response Results"
//	@Security		TokenAuth
//	@Summary		AlarmLog List
//	@Description	AlarmLog List
//	@Router			/neData/alarm/log/list [get]
func (s AlarmLogController) List(c *gin.Context) {
	var query model.AlarmLogQuery
	if err := c.ShouldBindQuery(&query); err != nil {
		errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
		c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
		return
	}
	// 查询数据
	rows, total := s.alarmLogService.FindByPage(query)
	c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}

// 告警事件日志列表
//
// GET /event
//
//	@Tags			ne_data/alarm_log
//	@Accept			json
//	@Produce		json
//	@Param			neType			query		string	false	"NE Type"	Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
//	@Param			neId			query		string	false	"NE ID The actual record is the network element RmUid"
//	@Param			alarmLogType	query		string	false	"AlarmLog type Communication AlarmLogs=1, Equipment AlarmLogs=2, Processing faults=3, Environmental AlarmLogs=4, Quality of service AlarmLogs=5"	Enums(1,2,3,4,5)
//	@Param			alarmStatus		query		string	false	"Alarm status 0:clear, 1:active"																													Enums(0,1)
//	@Param			origSeverity	query		string	false	"Alarm Type 1: Critical, 2: Major, 3: Minor, 4: Warning"																							Enums(1,2,3,4)
//	@Param			sortField		query		string	false	"Sort fields, fill in result fields"																												default(event_time)
//	@Param			sortOrder		query		string	false	"Sort by ascending or descending order, asc desc"																									default(asc)
//	@Param			pageNum			query		number	true	"pageNum"																																			default(1)
//	@Param			pageSize		query		number	true	"pageSize"																																			default(10)
//	@Success		200				{object}	object	"Response Results"
//	@Security		TokenAuth
//	@Summary		Alarm Event Log List
//	@Description	Alarm Event Log List
//	@Router			/neData/alarm/log/event [get]
func (s AlarmLogController) Event(c *gin.Context) {
	var query model.AlarmEventQuery
	if err := c.ShouldBindQuery(&query); err != nil {
		errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
		c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
		return
	}
	// 查询数据
	rows, total := s.alarmEventService.FindByPage(query)
	c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
