package com.ruoyi.web.service;

import cn.hutool.core.lang.Dict;
import com.ruoyi.enums.ExamineeStatus;
import com.ruoyi.learn.domain.LearnPaper;
import com.ruoyi.learn.domain.LearnTestStudent;
import com.ruoyi.learn.mapper.LearnPaperMapper;
import com.ruoyi.learn.mapper.LearnTestStudentMapper;
import org.apache.commons.compress.utils.Lists;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentService {
    private final LearnPaperMapper learnPaperMapper;
    private final LearnTestStudentMapper learnTestStudentMapper;

    public StudentService(LearnPaperMapper learnPaperMapper, LearnTestStudentMapper learnTestStudentMapper) {
        this.learnPaperMapper = learnPaperMapper;
        this.learnTestStudentMapper = learnTestStudentMapper;
    }

    public List<Dict> selectStatsForStudent(Long studentId) {
        Integer undone = 0, done = 0;
        for(LearnTestStudent ts : learnTestStudentMapper.selectStatsForStudent(studentId)) {
            if(ExamineeStatus.Init.getVal().equals(ts.getStatus()) || ExamineeStatus.Exam.getVal().equals(ts.getStatus())) {
                undone += ts.getCount();
            } else {
                done += ts.getCount();
            }
        }
        List<Dict> list = Lists.newArrayList();
        list.add(Dict.create().set("全部", undone + done));
        list.add(Dict.create().set("未完成", undone));
        list.add(Dict.create().set("已完成", done));
        return list;
    }

    public List<LearnPaper> selectLearnPaperForStudent(Long studentId, Integer status) {
        return learnPaperMapper.selectLearnPaperForStudent(studentId, status);
    }
}
