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.util.CourcseUtils;
import org.apache.commons.collections4.CollectionUtils;
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.ArrayList;
import java.util.List;

/**
 * 学习资源章节对象 el_course_chapter
 *
 * @author liubo
 * @date 2021-12-07
 */
@ApiModel("学习资源章节")
public class ElCourseChapter extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * ID
     */
    private Long id;
    /**
     * 课程ID
     */
    @Excel(name = "课程ID")
    @NotNull( message = "课程ID不能为空")
    @ApiModelProperty(value = "课程ID")
    private Long courseId;
    /**
     * 标题
     */
    @Excel(name = "标题")
    @NotBlank( message = "标题不能为空")
    @Length(message = "标题长度不能超过256")
    @ApiModelProperty(value = "标题")
    private String title;
    /**
     * 父级ID
     */
    @Excel(name = "父级ID")
    @ApiModelProperty(value = "父级ID")
    private Long parentId;
    /**
     * $column.columnComment
     */
    private Long position;
    /**
     * 关联资源ID
     */
    @Excel(name = "关联资源ID")
    @ApiModelProperty(value = "关联资源ID")
    private Long resourcesId;
    /**
     * 资源地址或上传的地址
     */
    @Excel(name = "资源地址或上传的地址")
    @ApiModelProperty(value = "资源地址或上传的地址")
    private String chapterData;
    /**
     * 简介
     */
    @Excel(name = "简介")
    @Length(message = "简介长度不能超过1024")
    @ApiModelProperty(value = "简介")
    private String description;
    /**
     * 是否免费试读章节，0为收费，1为免费
     */
    @Excel(name = "是否免费试读章节，0为收费，1为免费")
    @ApiModelProperty(value = "是否免费试读章节，0为收费，1为免费")
    private Integer free;
    /**
     * 0 为目录 其他类型同课件类型
     */
    @Excel(name = "0 为目录 其他类型同课件类型")
    @ApiModelProperty(value = "0 为目录 其他类型同课件类型")
    private Integer type;
    /**
     * 文件后缀
     */
    @Excel(name = "文件后缀")
    @ApiModelProperty(value = "文件后缀")
    private String postfix;
    /**
     * 允许下载资源
     */
    @Excel(name = "允许下载资源")
    @ApiModelProperty(value = "允许下载资源")
    private Integer allowdownload;
    /**
     * 课件时长
     */
    @Excel(name = "课件时长")
    @ApiModelProperty(value = "课件时长")
    private Long duration;

    private String durationStr;

    /**
     * 学习状态 0 未完成，1 已完成
     * V2.6 增加 0 学习中，2 未学习，1 已完成
     */
    private Integer learnStatus;
    /**
     * 是否考核（0 否，1 是）
     */
    private Integer isAssess;
    /**
     * 考核状态 0 未完成，1 已完成
     */
    private Integer assessStatus;
    /**
     * 考核次数
     */
    private Integer hasAssess;
    /**
     * 考核名称
     */
    private String assessName;

    private boolean hasChildren = false;

    private List<ElCourseChapter> children = new ArrayList<>();

    /**
     * 章节考题集合
     */
    private List<ElCourseChapterQu> chapterQuList;

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

    public Long getId() {
        return id;
    }

    public void setCourseId(Long courseId) {
        this.courseId = courseId;
    }

    public Long getCourseId() {
        return courseId;
    }

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

    public String getTitle() {
        return title;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setPosition(Long position) {
        this.position = position;
    }

    public Long getPosition() {
        return position;
    }

    public void setResourcesId(Long resourcesId) {
        this.resourcesId = resourcesId;
    }

    public Long getResourcesId() {
        return resourcesId;
    }

    public void setChapterData(String chapterData) {
        this.chapterData = chapterData;
    }

    public String getChapterData() {
        return chapterData;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    public void setFree(Integer free) {
        this.free = free;
    }

    public Integer getFree() {
        return free;
    }

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

    public Integer getType() {
        return type;
    }

    public void setAllowdownload(Integer allowdownload) {
        this.allowdownload = allowdownload;
    }

    public Integer getAllowdownload() {
        return allowdownload;
    }

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

    public Long getDuration() {
        return duration;
    }

    public List<ElCourseChapter> getChildren() {
        return children;
    }

    public void setChildren(List<ElCourseChapter> children) {
        this.children = children;
        if(CollectionUtils.isNotEmpty(children)){
            this.setHasChildren(true);
        }
    }

    public boolean isHasChildren() {
        return hasChildren;
    }

    public void setHasChildren(boolean hasChildren) {
        this.hasChildren = hasChildren;
    }

    public String getPostfix() {
        return postfix;
    }

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

    public Integer getLearnStatus() {
        return learnStatus;
    }

    public void setLearnStatus(Integer learnStatus) {
        this.learnStatus = learnStatus;
    }

    public String getDurationStr() {
        return durationStr;
    }

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

    public Integer getIsAssess() {
        return isAssess;
    }

    public void setIsAssess(Integer isAssess) {
        this.isAssess = isAssess;
    }

    public List<ElCourseChapterQu> getChapterQuList() {
        return chapterQuList;
    }

    public void setChapterQuList(List<ElCourseChapterQu> chapterQuList) {
        this.chapterQuList = chapterQuList;
    }

    public String getAssessName() {
        return assessName;
    }

    public void setAssessName(String assessName) {
        this.assessName = assessName;
    }

    public Integer getAssessStatus() {
        return assessStatus;
    }

    public void setAssessStatus(Integer assessStatus) {
        this.assessStatus = assessStatus;
    }

    public Integer getHasAssess() {
        return hasAssess;
    }

    public void setHasAssess(Integer hasAssess) {
        this.hasAssess = hasAssess;
    }
}
