package cn.sh.stc.sict.theme.hphy.vo;

import cn.hutool.core.collection.CollUtil;
import cn.sh.stc.sict.theme.hphy.model.HphyGuideQuestionOption;
import cn.sh.stc.sict.theme.hphy.model.HphyQuestion;
import cn.sh.stc.sict.theme.hphy.model.HphyQuestionOption;
import lombok.Data;
import lombok.NoArgsConstructor;

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

@Data
@NoArgsConstructor
public class QuestionVO {
    private Long prevQuestionId;

    private Long guideId;
    private HphyQuestion question;
    private Map<Integer, List<HphyQuestionOption>> optionList;
    private List<QuestionVO> childList;
    private List<HphyGuideQuestionOption> answerList;
    private Long progress;

    public QuestionVO(HphyQuestion question, List<QuestionVO> childList, List<HphyQuestionOption> list) {
        this.question = question;
        if (CollUtil.isNotEmpty(childList)) {
            this.childList = childList;
        }
        if (CollUtil.isNotEmpty(list)) {
            this.optionList = list.stream().collect(Collectors.groupingBy(HphyQuestionOption::getGroupId));
        }
    }
}
