package report

import (
	logger "eta/eta_mini_ht_api/common/component/log"
	etaDao "eta/eta_mini_ht_api/models/eta"
)

func GetClassifyIdsByPermissionIds(permissionIds []int) (classifyIds []int, err error) {
	return etaDao.GetClassifyIdsByPermissionIds(permissionIds)
}

func GetPermissionNamesByPermissionIds(permissionIds []int) (permissionNames []string, err error) {
	return etaDao.GetPermissionNamesByPermissionIds(permissionIds)
}
func GetPermissionList() (dtoList []PermissionDTO, err error) {
	list, err := etaDao.GetChartPermissionList()
	if err != nil {
		logger.Error("获取研报列表失败")
		return
	}
	dtoList = make([]PermissionDTO, 0)
	for _, node := range list {
		dto := convertPermissionDTO(node)
		dtoList = append(dtoList, dto)
	}
	return
}
func GetFirstPermissionsByIds(ids []int) (permissionDTOS []PermissionDTO, err error) {
	list, err := etaDao.GetFirstPermissionsByIds(ids)
	if err != nil {
		logger.Error("查询品种信息失败:%v", err)
	}
	for _, node := range list {
		permissionDTOS = append(permissionDTOS, convertPermissionDTO(node))
	}
	return
}

// 获取二级品种id
func GetPermissionIdByName(name string) (permissionId int, err error) {
	return etaDao.GetPermissionIdByName(name)
}

// 获取一级品种(海通的板块)
func GetReportPermissionsById(id int, source string) (permissionIds []PermissionDTO) {
	switch source {
	case SourceETA:
		//展示一级品种
		return getETAReportFirstPermissions(id)
	case SourceHT:
		return []PermissionDTO{}
	}
	return
}

func GetReportSecondPermissionsById(id int, source string) (permissionIds []PermissionDTO) {
	switch source {
	case SourceETA:
		//展示一级品种
		return getETAReportSecondPermissions(id)
	case SourceHT:
		return []PermissionDTO{}
	}
	return
}
func convertPermissionDTO(node etaDao.ChartPermission) PermissionDTO {
	return PermissionDTO{
		ID:       node.ChartPermissionID,
		Name:     node.PermissionName,
		ParentID: node.ParentID,
	}
}
