package service

import (
	"server/modules/yx/entity"
	"server/modules/yx/mapper"
)

type YxHistoryScoreControlLineService struct {
	mapper *mapper.YxHistoryScoreControlLineMapper
}

func NewYxHistoryScoreControlLineService() *YxHistoryScoreControlLineService {
	return &YxHistoryScoreControlLineService{
		mapper: mapper.NewYxHistoryScoreControlLineMapper(),
	}
}

// MapsBatchByProfessionalCategoryOfYear 获取指定年份、专业类别、文理科的省控线，并以批次为 Key 返回 Map
func (s *YxHistoryScoreControlLineService) MapsBatchByProfessionalCategoryOfYear(year, professionalCategory, category string) (map[string]entity.YxHistoryScoreControlLine, error) {
	list, err := s.mapper.SelectByYearAndCategory(year, professionalCategory, category)
	if err != nil {
		return nil, err
	}

	result := make(map[string]entity.YxHistoryScoreControlLine)
	for _, item := range list {
		// 复制对象逻辑，处理"本科A段"映射为"提前批"
		if item.Batch == "本科A段" {
			newItem := item
			newItem.Batch = "提前批"
			result[newItem.Batch] = newItem
		}
		result[item.Batch] = item
	}
	return result, nil
}
