package com.seer.teach.teacher.convert;

import com.seer.teach.common.dto.mq.im.QuestionCorrectParseHtmlDTO;
import com.seer.teach.teacher.common.resp.*;
import com.seer.teach.teacher.common.dto.QuestionResultDTO;
import com.seer.teach.teacher.common.dto.QuestionSetDTO;
import com.seer.teach.teacher.common.dto.ReportQuestionDTO;
import com.seer.teach.teacher.common.llm.req.QuestionCorrectLlmReq;
import com.seer.teach.teacher.module.entity.*;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author Captain
 * @since 2025-07-23 19:59
 */
@Mapper
public interface QuestionConvert {

    QuestionConvert INSTANCE = Mappers.getMapper(QuestionConvert.class);


    @Mapping(source = "result", target = "result")
    @Mapping(source = "html", target = "html")
    QuestionCorrectParseHtmlDTO toQuestionCorrectParseHtmlResp(Integer result, String html);

    QuestionsCorrectDTO toQuestionsCorrectResp(Integer id, Integer type, Integer score, String useTime, LocalDate time, String correctRate, List<QuestionCorrectParseHtmlDTO> parseHtml);

    @Mapping(source = "taskId", target = "taskId")
    @Mapping(source = "questionId", target = "questionId")
    @Mapping(source = "studentAnswer", target = "studentAnswer")
    @Mapping(ignore = true, target = "result")
    EvaluationQuestionsEntity toEvaluationQuestionEntity(Integer questionId, Integer taskId, String studentAnswer);

    ReportQuestionDTO toReportQuestionDTO(Integer subjectId, Integer type, BigDecimal correctRate, Integer questionCount, LocalDateTime createTime, LocalDateTime updateTime, Integer studyDuration);

    WrongQuestionListResp toWrongQuestionListResp(Integer id, String type, String subject, Integer questionCount, String correctRate, LocalDateTime createTime);

    @Mapping(target = "planId", source = "planId")
    @Mapping(target = "questionId", source = "questionId")
    @Mapping(target = "studentAnswer", source = "studentAnswer")
    @Mapping(target = "result", ignore = true)
    PlanQuestionsEntity toPlanQuestionEntity(Integer planId, Integer questionId, String studentAnswer);

    QuestionCorrectLlmReq toQuestionCorrectLlmReq(Integer id, Integer type, String studentAnswer, String question, String answer);

    @Mapping(target = "questionId", source = "questionId")
    @Mapping(target = "result", source = "result")
    QuestionResultDTO toQuestionResultDTO(Integer questionId, Integer result);

    @Mapping(target = "knowId", source = "knowId")
    @Mapping(target = "useTime", source = "useTime")
    @Mapping(target = "averageDifficulty", source = "averageDifficulty")
    @Mapping(target = "questions", source = "questionDTOs")
    QuestionSetDTO toQuestionSetDTO(Integer knowId, Integer useTime, BigDecimal averageDifficulty, List<QuestionResultDTO> questionDTOs);

    @Mapping(source = "question.id", target = "id")
    @Mapping(source = "question.type", target = "type")
    @Mapping(source = "question.title", target = "question")
    @Mapping(target = "options", ignore = true)
    QuestionResp toQuestionResp(BankQuestionsEntity question);

    @Mapping(source = "taskId", target = "id")
    @Mapping(source = "code", target = "type")
    @Mapping(source = "results", target = "questions")
    DoExerciseResp toDoExerciseResp(Integer taskId, Integer code, List<QuestionResp> results);


    @Mapping(source = "question.id", target = "id")
    @Mapping(source = "question.html", target = "html")
    WrongQuestionPageListResp toWrongQuestionPageListResp(BankQuestionsEntity  question);
}