package controller

import (
	"be.ems/src/framework/i18n"
	"be.ems/src/framework/utils/ctx"
	"be.ems/src/framework/vo/result"
	neDataService "be.ems/src/modules/network_data/service"
	neService "be.ems/src/modules/network_element/service"
	"github.com/gin-gonic/gin"
)

// 实例化控制层 UPFController 结构体
var NewUPFController = &UPFController{
	neInfoService:  neService.NewNeInfoImpl,
	perfKPIService: neDataService.NewPerfKPIImpl,
}

// 网元UPF
//
// PATH /upf
type UPFController struct {
	// 网元信息服务
	neInfoService neService.INeInfo
	// 统计信息服务
	perfKPIService neDataService.IPerfKPI
}

// 总流量数 N3上行 N6下行
// 单位 比特(bit)
//
// GET /totalFlow
func (s *UPFController) TotalFlow(c *gin.Context) {
	language := ctx.AcceptLanguage(c)
	var querys struct {
		NeType string `json:"neType" form:"neType" binding:"required"`
		NeID   string `form:"neId" binding:"required"`
		Day    int    `form:"day" binding:"required"`
	}
	if err := c.ShouldBindQuery(&querys); querys.Day < 0 || err != nil {
		c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
		return
	}

	// 查询网元获取IP
	neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
	if neInfo.NeId != querys.NeID || neInfo.IP == "" {
		c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
		return
	}

	data := s.perfKPIService.SelectUPFTotalFlow(neInfo.NeType, neInfo.RmUID, querys.Day)

	c.JSON(200, result.OkData(data))
}
