package controller

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

// 实例化控制层 NeInfoController 结构体
var NewNeInfo = &NeInfoController{
	neInfoService: neService.NewNeInfoImpl,
}

// 网元信息请求
//
// PATH /
type NeInfoController struct {
	// 网元信息服务
	neInfoService neService.INeInfo
}

// 网元neType和neID查询
//
// GET /info
func (s *NeInfoController) NeTypeAndID(c *gin.Context) {
	language := ctx.AcceptLanguage(c)
	neType := c.Query("neType")
	neId := c.Query("neId")
	if neType == "" || neId == "" {
		c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
		return
	}

	neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(neType, neId)
	if neInfo.NeId != neId || neInfo.IP == "" {
		c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
		return
	}
	c.JSON(200, result.OkData(neInfo))
}
