package com.qmth.themis.business.entity;

import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.themis.business.base.BaseEntity;
import com.qmth.themis.business.enums.AudioDefaultEnum;
import com.qmth.themis.business.enums.AudioTypeEnum;
import com.qmth.themis.business.enums.MonitorVideoSourceEnum;
import com.qmth.themis.business.util.UidUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Objects;

/**
 * <p>
 * 场次音频表
 * </p>
 *
 * @author wangliang
 * @since 2022-08-30
 */
@ApiModel(value = "TEAudio对象", description = "场次音频表")
public class TEAudio extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "机构id")
    private Long orgId;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "考试场次id")
    @NotNull(message = "考试场次id不能为空")
    private Long activityId;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "附件id")
    @NotNull(message = "附件id不能为空")
    private Long attachmentId;

    @ApiModelProperty(value = "语音内容")
    private String content;

    @ApiModelProperty(value = "类别，BEFORE：开考前语音，AFTER：考试结束前语音")
    @NotNull(message = "类别不能为空")
    private AudioTypeEnum type;

    @ApiModelProperty(value = "是否启用，0：停用，1：启用")
    @TableField(value = "enable", updateStrategy = FieldStrategy.IGNORED)
    private Boolean enable = true;

    @ApiModelProperty(value = "是否默认，SYS：系统内置，CUSTOM：自定义")
    private AudioDefaultEnum audioDefault = AudioDefaultEnum.SYS;

    @ApiModelProperty(value = "更新人")
    @TableField(exist = false)
    private String updateName;

    @ApiModelProperty(value = "附件路径")
    @TableField(exist = false)
    private String attachmentPath;

    @ApiModelProperty(value = "设置时长(单位：秒)")
    private Integer playTime;

    @ApiModelProperty(value = "附件路径")
    @TableField(exist = false)
    private String attachmentName;

    public TEAudio() {

    }

    public TEAudio(Long orgId, Long activityId, Long attachmentId, String content, AudioTypeEnum type, AudioDefaultEnum audioDefault, Long userId, Integer playTime, TEExam teExam, TEExamActivity teExamActivity) {
        setId(UidUtil.nextId());
        this.orgId = orgId;
        this.activityId = activityId;
        this.attachmentId = attachmentId;
        this.content = content;
        this.type = type;
        this.audioDefault = audioDefault;
        this.playTime = playTime;
        setCreateId(userId);
        if (Objects.nonNull(teExam.getForceFinish()) && teExam.getForceFinish().intValue() == 1
                && Objects.nonNull(teExam.getEnable()) && teExam.getEnable() == 1
                && Objects.nonNull(teExamActivity.getEnable()) && teExamActivity.getEnable() == 1
                && Objects.nonNull(teExam.getMonitorRecord())
                && (teExam.getMonitorRecord().contains(MonitorVideoSourceEnum.MOBILE_FIRST.name())
                || teExam.getMonitorRecord().contains(MonitorVideoSourceEnum.MOBILE_SECOND.name()))) {
            this.enable = true;
        } else {
            this.enable = false;
        }
    }

    public void insertInfo(Long userId) {
        setId(UidUtil.nextId());
        setCreateId(userId);
        setCreateTime(System.currentTimeMillis());
    }

    public void updateInfo(Long userId) {
        setUpdateId(userId);
        setUpdateTime(System.currentTimeMillis());
    }

    public String getAttachmentName() {
        return attachmentName;
    }

    public void setAttachmentName(String attachmentName) {
        this.attachmentName = attachmentName;
    }

    public Integer getPlayTime() {
        return playTime;
    }

    public void setPlayTime(Integer playTime) {
        this.playTime = playTime;
    }

    public String getUpdateName() {
        return updateName;
    }

    public void setUpdateName(String updateName) {
        this.updateName = updateName;
    }

    public String getAttachmentPath() {
        return attachmentPath;
    }

    public void setAttachmentPath(String attachmentPath) {
        this.attachmentPath = attachmentPath;
    }

    public Long getOrgId() {
        return orgId;
    }

    public void setOrgId(Long orgId) {
        this.orgId = orgId;
    }

    public Long getActivityId() {
        return activityId;
    }

    public void setActivityId(Long activityId) {
        this.activityId = activityId;
    }

    public Long getAttachmentId() {
        return attachmentId;
    }

    public void setAttachmentId(Long attachmentId) {
        this.attachmentId = attachmentId;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public AudioTypeEnum getType() {
        return type;
    }

    public void setType(AudioTypeEnum type) {
        this.type = type;
    }

    public Boolean getEnable() {
        return enable;
    }

    public void setEnable(Boolean enable) {
        this.enable = enable;
    }

    public AudioDefaultEnum getAudioDefault() {
        return audioDefault;
    }

    public void setAudioDefault(AudioDefaultEnum audioDefault) {
        this.audioDefault = audioDefault;
    }
}
