package com.zd.exam.domain;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import com.zd.common.core.valid.ValidGroup;
import com.zd.exam.enums.FileType;
import com.zd.exam.util.CourcseUtils;
import org.hibernate.validator.constraints.Length;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.zd.common.core.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import com.zd.common.core.web.domain.BaseEntity;

import java.util.List;

/**
 * 课件资源对象 el_resources
 *
 * @author liubo
 * @date 2021-12-07
 */
@ApiModel("课件资源")
public class ElResources extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * ID
     */
    @ApiModelProperty(value = "${comment}")
    private Long id;
    /**
     * 分类id
     */
    @Excel(name = "分类id")
    @NotNull(groups = ValidGroup.Crud.Create.class, message = "分类id不能为空")
    @ApiModelProperty(value = "分类id")
    private Long cateId;

    @ApiModelProperty(value = "分类标题")
    private String cateTitle;

    /**
     * 标题
     */
    @Excel(name = "标题")
    @NotBlank(groups = ValidGroup.Crud.Create.class, message = "标题不能为空")
    @Length(message = "标题长度不能超过128")
    @ApiModelProperty(value = "标题")
    private String title;
    /**
     * 文件类型 1 文件，2 视频，3 图片，4 音频
     */
    @ApiModelProperty(value = "文件类型 1 文件，2 视频，3 图片，4 音频，5 富文本")
    private Integer type;
    /**
     * 文件后缀
     */
    @Excel(name = "文件后缀")
    @ApiModelProperty(value = "文件后缀")
    private String postfix;
    /**
     * 文件大小
     */
    @Excel(name = "文件大小")
    @ApiModelProperty(value = "文件大小")
    private Long size;

    private String sizeStr;
    /**
     * 文件时长
     */
    @Excel(name = "文件时长")
    @ApiModelProperty(value = "文件时长")
    private Long duration;

    private String durationStr;
    /**
     * 文件路径
     */
    @Excel(name = "文件路径")
    @ApiModelProperty(value = "文件路径")
    private String path;

    @ApiModelProperty(value = "富文本内容")
    private String content;

    private String beginTime;

    private String endTime;

    private List<Long> cateIds;

    private String fileName;

    private Long fileSize;

    public void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setCateId(Long cateId) {
        this.cateId = cateId;
    }

    public Long getCateId() {
        return cateId;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public void setPostfix(String postfix) {
        this.postfix = postfix;
         this.setType(FileType.getTypeByFile(postfix));
    }

    public String getPostfix() {
        return postfix;
    }

    public void setSize(Long size) {
        this.size = size;
    }

    public Long getSize() {
        return size;
    }

    public void setDuration(Long duration) {
        this.duration = duration;
        if(duration != null){
            this.setDurationStr(duration);
        }
    }

    public Long getDuration() {
        return duration;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getPath() {
        return path;
    }

    public Integer getType() {
        return type;
    }

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

    public String getCateTitle() {
        return cateTitle;
    }

    public void setCateTitle(String cateTitle) {
        this.cateTitle = cateTitle;
    }

    public String getSizeStr() {
        if(size != null){
            return CourcseUtils.getSizeStr(size);
        }else {
            return sizeStr;
        }
    }

    public void setSizeStr(String sizeStr) {
        this.sizeStr = sizeStr;
    }

    public String getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(String beginTime) {
        this.beginTime = beginTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public String getContent() {
        return content;
    }

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

    public String getDurationStr() {
        return durationStr;
    }

    public void setDurationStr(Long duration) {
        this.durationStr = CourcseUtils.getTimeString(Math.toIntExact(duration));;
    }

    public List<Long> getCateIds() {
        return cateIds;
    }

    public void setCateIds(List<Long> cateIds) {
        this.cateIds = cateIds;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public Long getFileSize() {
        return fileSize;
    }

    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }
}
