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

import cn.reghao.jutil.jdk.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;

/**
 * 试卷
 *
 * @author reghao
 * @date 2024-08-24 23:29:46
 */
@NoArgsConstructor
@Getter
public class Paper extends BaseObject<Integer> {
    private Integer subjectId;
    private String name;
    private String description;
    private Integer duration;
    private Integer totalScore;
    private Integer passScore;
    private LocalDateTime startTime;
    private LocalDateTime endTime;
    private String passcode;
    private int status;
    private LocalDateTime createAt;
    private Long createBy;

    public Paper(PaperAddDto paperAddDto) {
        this.subjectId = 1;
        this.name = paperAddDto.getExamName();
        this.description = paperAddDto.getExamDesc();
        this.duration = paperAddDto.getExamDuration();
        this.totalScore = paperAddDto.getTotalScore();
        this.passScore = paperAddDto.getPassScore();
        this.startTime = LocalDateTime.ofInstant(paperAddDto.getStartTime().toInstant(), ZoneId.systemDefault());
        this.endTime = LocalDateTime.ofInstant(paperAddDto.getEndTime().toInstant(), ZoneId.systemDefault());
        this.passcode = paperAddDto.getExamPassword();
        this.status = 1;
        this.createAt = LocalDateTime.now();
        this.createBy = UserContext.getUser();
    }
}
