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

import cn.reghao.tnb.content.app.exam.model.po.PaperAnswer;
import cn.reghao.tnb.content.app.exam.model.po.Question;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.io.Serializable;

/**
 * @author reghao
 * @date 2025-08-09 14:00:42
 */
@NoArgsConstructor
@Setter
@Getter
public class QuestionAnswer implements Serializable {
    private static final long serialVersionUID = 1L;

    @NotNull
    private Long questionId;
    @NotNull
    private Integer questionType;
    @NotNull
    private Integer pos;
    @Size(min = 1, max = 20)
    private Object[] submitAnswer = {};
    @Size(min = 1, max = 20)
    private Object[] correctAnswer = {};
    @NotNull
    private Integer submitScore;
    @NotNull
    private Integer correctScore;

    private Long pid = 0L;

    public QuestionAnswer(QuestionInfo questionInfo) {
        this.questionId = questionInfo.getQuestionId();
        this.questionType = questionInfo.getQuestionType();
        this.pos = questionInfo.getPos();
        this.submitScore = 0;
        this.correctScore = questionInfo.getScore();
    }

    public QuestionAnswer(PaperAnswer paperAnswer, int correctScore) {
        this.questionId = paperAnswer.getQuestionId();
        this.questionType = paperAnswer.getQuestionType();
        this.pos = paperAnswer.getPos();
        this.submitScore = paperAnswer.getScore();
        this.correctScore = correctScore;
    }

    public QuestionAnswer(Question question, int correctScore) {
        this.questionId = question.getQuestionId();
        this.questionType = question.getType();
        this.pos = 1;
        this.submitScore = 0;
        this.correctScore = correctScore;
    }
}
