package cn.reghao.tnb.content.app.exam.model.po;

import cn.reghao.jutil.jdk.web.db.BaseObject;
import cn.reghao.tnb.content.app.exam.model.constant.QuestionLevel;
import cn.reghao.tnb.content.app.exam.model.constant.QuestionType;
import cn.reghao.tnb.content.app.exam.model.dto.QuestionAddDto;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 试题
 *
 * @author reghao
 * @date 2024-08-24 23:28:02
 */
@NoArgsConstructor
@Getter
@Setter
public class Question extends BaseObject<Integer> {
    private Long questionId;
    private Integer subjectId;
    private Integer type;
    private Integer level;
    private String content;
    private String analysis;
    private Long createBy;
    private Long pid;
    private Boolean child;
    private Integer pos;
    private String extra;
    private transient List<QuestionOption> questionOptions;

    public Question(long questionId, String content, int questionType, String extra) {
        this.questionId = questionId;
        this.subjectId = 1;
        this.type = questionType;
        this.level = QuestionLevel.EASY.getCode();
        this.content = content;
        this.analysis = "";
        this.pid = 0L;
        this.child = questionType == QuestionType.QUESTION6.getCode();
        this.pos = 0;
        this.extra = extra;
    }

    public Question(long questionId, QuestionAddDto questionAddDto) {
        this.questionId = questionId;
        this.subjectId = questionAddDto.getSubjectId();
        this.type = questionAddDto.getQuestionType();
        this.level = questionAddDto.getQuestionLevel();
        this.content = questionAddDto.getQuestionContent();
        this.analysis = questionAddDto.getAnalysis();
        this.pid = 0L;
        this.child = Objects.equals(questionAddDto.getQuestionType(), QuestionType.QUESTION6.getCode());
        this.pos = 0;
    }

    public Question(long questionId, QuestionAddDto questionAddDto, boolean child) {
        this.questionId = questionId;
        this.subjectId = questionAddDto.getSubjectId();
        this.type = questionAddDto.getQuestionType();
        this.level = questionAddDto.getQuestionLevel();
        this.content = questionAddDto.getQuestionContent();
        this.analysis = questionAddDto.getAnalysis();
        this.pid = 0L;
        this.child = child;
        this.pos = 0;
    }

    public void setSubjectId(Integer subjectId) {
        this.subjectId = subjectId;
    }

    public void setPid(Long pid) {
        this.pid = pid;
    }

    public void setPos(Integer pos) {
        this.pos = pos;
    }
}
