package cn.com.qmth.stmms.admin.utils;

import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;

import cn.com.qmth.stmms.admin.vo.StudentGrade;
import cn.com.qmth.stmms.common.enums.SchoolLevel;

public class StudentGradeUtils {

    public static List<StudentGrade> getGradeSelectList(SchoolLevel schoolLevel) {
        List<StudentGrade> list = new LinkedList<StudentGrade>();
        if (SchoolLevel.PRIMARY == schoolLevel) {
            list.addAll(buildList(SchoolLevel.PRIMARY, 6));
        } else if (SchoolLevel.JUNIOR == schoolLevel) {
            list.addAll(buildList(SchoolLevel.JUNIOR, 3));
        } else if (SchoolLevel.SENIOR == schoolLevel) {
            list.addAll(buildList(SchoolLevel.SENIOR, 3));
        } else if (SchoolLevel.MIDDLE == schoolLevel) {
            list.addAll(buildList(SchoolLevel.JUNIOR, 3));
            list.addAll(buildList(SchoolLevel.SENIOR, 3));
        } else if (SchoolLevel.COLLEGE == schoolLevel) {
            list.addAll(buildList(SchoolLevel.COLLEGE, 4));
        }
        return list;
    }

    private static List<StudentGrade> buildList(SchoolLevel level, int count) {
        List<StudentGrade> list = new LinkedList<StudentGrade>();
        int year = Calendar.getInstance().get(Calendar.YEAR);
        int month = Calendar.getInstance().get(Calendar.MONTH);
        for (int i = 1; i <= count; i++) {
            StudentGrade grade = new StudentGrade();
            grade.setName(level.getName() + i + "年级");
            grade.setSchoolLevel(level.getValue());
            grade.setGraduateYear(month >= 9 ? year + i : year + i - 1);
            list.add(grade);
        }
        return list;
    }
}
