package com.yinlihupo.enlish.service.service.plan;

import com.yinlihupo.enlish.service.domain.dataobject.StudentLessonPlansDO;
import com.yinlihupo.enlish.service.domain.mapper.StudentLessonPlansDOMapper;
import com.yinlihupo.enlish.service.domain.mapper.VocabularyBankDOMapper;
import com.yinlihupo.enlish.service.domain.mapper.WordMasteryLogDOMapper;
import com.yinlihupo.enlish.service.service.StudentLessonPlansService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class StudentLessonPlansServiceImpl implements StudentLessonPlansService {

    @Resource
    private StudentLessonPlansDOMapper studentLessonPlansDOMapper;
    @Resource
    private WordMasteryLogDOMapper wordMasteryLogDOMapper;
    @Resource
    private VocabularyBankDOMapper vocabularyBankDOMapper;


    @Override
    public List<StudentLessonPlansDO> findStudentLessonPlansDOList(Integer page, Integer size, String name) {
        log.info("查询学生学案");
        if (name.isEmpty()) {
            return studentLessonPlansDOMapper.selectStudentLessonPlanList((page - 1) * size, size, null);
        }
        return studentLessonPlansDOMapper.selectStudentLessonPlanList((page - 1) * size, size, name);
    }

    @Override
    public Integer findStudentLessonPlanTotal() {
        return studentLessonPlansDOMapper.selectStudentPlanTotal();
    }

    @Override
    public int finishStudentLessonPlan(Integer studentId, Integer planId) {
        int wordStrengthCount = wordMasteryLogDOMapper.selectStudentStrengthCount(studentId);
        Integer wordTotal = vocabularyBankDOMapper.selectWordTotal();

        return studentLessonPlansDOMapper.finfishStudentPlan(studentId, planId, wordStrengthCount, (double) wordStrengthCount / wordTotal);
    }

    @Override
    public List<StudentLessonPlansDO> findStudentLessonPlansByStudentId(Integer studentId) {
        return studentLessonPlansDOMapper.selectStudentLessonPlanListByStudentId(studentId);
    }
}
