package controller

import (
	"fmt"

	"github.com/gin-gonic/gin"

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

// 实例化控制层 NEStateController 结构体
var NewNEState = &NEStateController{
	neInfoService:  neService.NewNeInfo,
	neStateService: neDataService.NewNEState,
}

// 网元状态记录
//
// PATH /ne-state
type NEStateController struct {
	neInfoService  *neService.NeInfo      // 网元信息服务
	neStateService *neDataService.NEState // 网元状态服务
}

// 网元状态记录-内存/CPU/磁盘列表
//
// GET /list
//
//	@Tags			ne_data
//	@Accept			json
//	@Produce		json
//	@Param			neType		query		string	true	"NE Type"								Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(AMF)
//	@Param			neId		query		string	true	"NE ID"									default(001)
//	@Param			pageNum		query		number	true	"pageNum"								default(1)
//	@Param			pageSize	query		number	true	"pageSize"								default(10)
//	@Param			startTime	query		number	false	"Start time (timestamped milliseconds)"	default(1729162507596)
//	@Param			endTime		query		number	false	"End time (timestamped milliseconds)"	default(1729164187611)
//	@Param			sortField	query		string	false	"Sort fields, fill in result fields"	Enums(id,create_time)	default(id)
//	@Param			sortOrder	query		string	false	"Sort by ascending or descending order"	Enums(asc,desc)			default(asc)
//	@Success		200			{object}	object	"Response Results"
//	@Security		TokenAuth
//	@Summary		NE Status Record - Memory/CPU/Disk List
//	@Description	NE Status Record - Memory/CPU/Disk List
//	@Router			/ne-state/list [get]
func (s NEStateController) List(c *gin.Context) {
	var query model.NEStateQuery
	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.neStateService.FindByPage(query)
	c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
