package com.seer.teach.teacher.service.registry.wrongQuestionDetail.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.seer.teach.common.enums.MakeQuestionTypeEnums;
import com.seer.teach.teacher.common.req.WrongQuestionDetailReq;
import com.seer.teach.teacher.module.entity.BankQuestionsEntity;
import com.seer.teach.teacher.module.entity.PlanQuestionsEntity;
import com.seer.teach.teacher.service.BankQuestionsService;
import com.seer.teach.teacher.service.PlanQuestionsService;
import com.seer.teach.teacher.service.registry.wrongQuestionDetail.WrongQuestionDetailHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class PlanWrongQuestionDetailHandlerImpl implements WrongQuestionDetailHandler {

    private final PlanQuestionsService planQuestionsService;

    private final BankQuestionsService bankQuestionsService;

    @Override
    public List<String> handler(Integer userId, WrongQuestionDetailReq params) {
        // 查询该任务下的所有题目
        List<Integer> questionIds = planQuestionsService.list(new LambdaQueryWrapper<PlanQuestionsEntity>()
                        .eq(PlanQuestionsEntity::getPlanId, params.getId())).stream()
                .map(PlanQuestionsEntity::getQuestionId).collect(Collectors.toList());
        List<BankQuestionsEntity> questions = bankQuestionsService.listByIds(questionIds);
        return questions.stream().map(BankQuestionsEntity::getHtml).collect(Collectors.toList());
    }


    /**
     * 获取当前处理器支持的题目生成类型编码。
     *
     * @return 题目生成类型编码（REVIEW 类型）
     */
    @Override
    public Integer getType() {
        return MakeQuestionTypeEnums.PLAN.getCode();
    }
}
