package com.yinlihupo.enlish.service.service.exam;

import com.yinlihupo.enlish.service.domain.dataobject.ExamWordsDO;
import com.yinlihupo.enlish.service.domain.dataobject.ExamWordsJudgeResultDO;
import com.yinlihupo.enlish.service.domain.dataobject.VocabularyBankDO;
import com.yinlihupo.enlish.service.domain.mapper.ExamWordsDOMapper;
import com.yinlihupo.enlish.service.domain.mapper.VocabularyBankDOMapper;
import com.yinlihupo.enlish.service.model.bo.CoordinatesXY;
import com.yinlihupo.enlish.service.model.bo.StudentExamId;
import com.yinlihupo.enlish.service.service.ExamWordsJudgeService;
import com.yinlihupo.enlish.service.service.StudentService;
import com.yinlihupo.enlish.service.utils.DifyClient;
import com.yinlihupo.enlish.service.utils.PngUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
@Slf4j
public class ExamWordsJudgeServiceTest {


    @Resource
    private ExamWordsJudgeService examWordsJudgeService;
    @Resource
    private StudentService studentService;
    @Resource
    private DifyClient difyClient;
    @Resource
    private ExamWordsDOMapper examWordsDOMapper;
    @Resource
    private VocabularyBankDOMapper vocabularyBankDOMapper;

    @Test
    public void judgeExamWords() {
//        String ansSheetPath = "C:\\project\\java\\enlish_edu\\enlish\\enlish-service\\src\\main\\resources\\templates\\3.png";
//        List<CoordinatesXY> coordinatesXIES = PngUtil.analysisXY(ansSheetPath);
//        // 从图片中获取学生 id 和考试 id
//        String tessdataPath = "C:\\project\\tess";
//        StudentExamId studentExamId = PngUtil.analyzeExamWordsIdAndStudentId(ansSheetPath, tessdataPath, coordinatesXIES);
//        Integer examWordsId = 41;
//
//        ExamWordsDO examWordsDO = examWordsDOMapper.selectById(examWordsId);
//
//        List<Integer> wordIds = examWordsDO.getWordIds();
//        List<Integer> unmemorizedWordIds = PngUtil.analyzePngForUnmemorizedWordIds(ansSheetPath, wordIds, coordinatesXIES);
//        List<Integer> memorizedWordIds = wordIds.stream().filter(wordId -> !unmemorizedWordIds.contains(wordId)).toList();
//        List<VocabularyBankDO> vocabularyBankDOS = vocabularyBankDOMapper.selectVocabularyBankDOListByIds(unmemorizedWordIds);
//        for (VocabularyBankDO vocabularyBankDO : vocabularyBankDOS) {
//            log.info("未掌握的单词：{}", vocabularyBankDO);
//        }
    }

    @Test
    public void judege() {
        examWordsJudgeService.judgeExamWords(5);
    }

    @Test
    public void selectExamWordsJudgeResult() {
//        List<ExamWordsJudgeResultDO> examWordsJudgeResult = examWordsJudgeService.getExamWordsJudgeResult(1, 10);
//        log.info("examWordsJudgeResult:{}", examWordsJudgeResult);
    }

//    @Test
//    public void selectExamWordsJudgeResult2() {
//        String s = studentService.analyzeStudentStudy(1);
//        try {
//            DifyClient.DifyResponse difyResponse = difyClient.sendStudentAnalyze(s);
//            String answer = difyResponse.getAnswer();
//            log.info("answer:{}", answer);
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//        log.info("s:{}", s);
//    }
}
