package jnpf.cultivate.utils;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import jnpf.model.cultivate.po.exam.FtbCultivateExam;
import jnpf.model.cultivate.po.exam.FtbCultivateExamHistoryPaper;
import jnpf.model.cultivate.po.question.FtbCultivateQuestion;
import jnpf.model.cultivate.req.paper.PaperConfigReq;
import jnpf.model.cultivate.resp.ExamQuestionBakVo;
import jnpf.util.QuestionAnalysisUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class HistoryPaperUtils {

    public static FtbCultivateExam converToExam(FtbCultivateExamHistoryPaper ftbCultivateExamHistoryPaper) {
        FtbCultivateExam exam = BeanUtil.copyProperties(ftbCultivateExamHistoryPaper, FtbCultivateExam.class);
        exam.setId(ftbCultivateExamHistoryPaper.getPrimaryExamId());
        return exam;
    }

    public static Map<String, PaperConfigReq.QuestionNum> analysPaperQuestionCount(List<FtbCultivateQuestion> questionVoList) {
        //2、初始化返回值
        Map<String, PaperConfigReq.QuestionNum> analyMap = QuestionAnalysisUtil.initAnalysQuestionCount();
        if (CollectionUtil.isNotEmpty(questionVoList)) {
            QuestionAnalysisUtil.analysQuestionCount(analyMap, questionVoList);
        }
        return analyMap;
    }

    public static List<ExamQuestionBakVo> convertQuestionList(String str) {
        if (StringUtils.isEmpty(str)) {
            return new ArrayList<>();
        }
        return JSONUtil.toList(str, ExamQuestionBakVo.class);
    }
}
