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

import cn.reghao.jutil.jdk.web.db.BaseObject;
import cn.reghao.tnb.common.auth.UserContext;
import cn.reghao.tnb.content.app.exam.model.dto.PaperAddDto;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;

/**
 * 试卷
 *
 * @author reghao
 * @date 2024-08-24 23:29:46
 */
@NoArgsConstructor
@Getter
public class Paper extends BaseObject<Integer> {
    private Integer subjectId;
    private String name;
    private Integer markType;
    private Integer scope;
    private Integer duration;
    private Integer totalScore;
    private LocalDateTime startTime;
    private String passcode;
    private Boolean hasSubjective;
    private LocalDateTime createAt;
    private Long createBy;
    private transient List<PaperQuestion> paperQuestionList;

    public Paper(PaperAddDto paperAddDto) {
        this.subjectId = 1;
        this.name = paperAddDto.getExamName();
        this.markType = 1;
        this.scope = 1;
        this.duration = paperAddDto.getExamDuration();
        this.totalScore = paperAddDto.getTotalScore();
        this.startTime = LocalDateTime.ofInstant(paperAddDto.getStartTime().toInstant(), ZoneId.systemDefault());
        this.passcode = paperAddDto.getExamPassword();
        this.hasSubjective = false;
        this.createAt = LocalDateTime.now();
        this.createBy = UserContext.getUserId();
    }
}
