package com.seer.teach.common.utils;

import com.seer.teach.common.utils.dto.GradeDTO;
import com.seer.teach.common.utils.dto.SubjectDTO;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
public class SubjectUtils {

    private static final Map<Integer, String> SUBJECTS = new HashMap<>();
    private static final List<SubjectDTO> SUBJECT_LIST = new ArrayList<>();
    static {
        SUBJECTS.put(1, "语文");
        SUBJECTS.put(2, "数学");
        SUBJECTS.put(3, "英语");
        SUBJECTS.put(4, "品德与生活");
        SUBJECTS.put(5, "科学");
        SUBJECTS.put(6, "历史");
        SUBJECTS.put(7, "地理");
        SUBJECTS.put(8, "生物学");
        SUBJECTS.put(9, "政治");
        SUBJECTS.put(10, "物理");
        SUBJECTS.put(11, "化学");
        SUBJECTS.put(12, "信息技术");
        SUBJECTS.put(13, "课外拓展");

        SUBJECT_LIST.addAll(SUBJECTS.entrySet().stream().map(item -> new SubjectDTO(item.getKey(), item.getValue()))
                .sorted(Comparator.comparing(SubjectDTO::getId))
                .collect(Collectors.toList()));
    }


    public static List<SubjectDTO> getList() {
        return SUBJECT_LIST;
    }

    public static Integer getSubjectIdBySubjectName(String subjectName) {
        for (Map.Entry<Integer, String> entry : SUBJECTS.entrySet()) {
            if (entry.getValue().equals(subjectName)) {
                return entry.getKey();
            }
        }
        if("道德与法治".equals(subjectName)){
            return 9;
        }
        if("生物".equalsIgnoreCase(subjectName)){
            return 8;
        }
        log.warn("未找到学科名称对应的ID: {}", subjectName);
        return null;
    }

    public static String getSubjectNameBySubjectId(Integer id) {
        return SUBJECTS.get(id);
    }
}
