package org.xyzh.common.vo;

import java.math.BigDecimal;
import java.util.Date;

import org.xyzh.common.dto.study.TbLearningTask;
import org.xyzh.common.dto.study.TbTaskItem;
import org.xyzh.common.dto.study.TbTaskUser;

public class TaskItemVO extends TbLearningTask {
    
    private Integer itemType;
    private String courseID;
    private String courseName;
    private String resourceID;
    private String resourceName;
    private String userID;
    private String username;
    private Boolean required;
    private Integer orderNum;
    private Integer status;
    private BigDecimal progress;
    private Date completeTime;

    

    public TaskItemVO() {
    }

    public Integer getItemType() {
        return itemType;
    }

    public void setItemType(Integer itemType) {
        this.itemType = itemType;
    }

    public TaskItemVO(TbTaskItem taskItem) {
      this.itemType = taskItem.getItemType();
      this.setTaskID(taskItem.getTaskID());
      this.orderNum = taskItem.getOrderNum();
      this.required = taskItem.getRequired();
      this.setID(taskItem.getID());
      this.setCreateTime(taskItem.getCreateTime());
      this.setCreator(taskItem.getCreator());
      
      // 根据类型设置对应的ID
      if (taskItem.getItemType() != null) {
        if (taskItem.getItemType() == 2) {  // 课程
          this.courseID = taskItem.getItemID();
        } else if (taskItem.getItemType() == 1) {  // 资源
          this.resourceID = taskItem.getItemID();
        }
      }
    }
    public TaskItemVO(TbTaskUser taskUser) {
      this.userID = taskUser.getUserID();
      this.setTaskID(taskUser.getTaskID());
      this.status = taskUser.getStatus();
      this.progress = taskUser.getProgress();
      this.completeTime = taskUser.getCompleteTime();
    }

    public String getCourseID() {
      return courseID;
    }
    public void setCourseID(String courseID) {
      this.courseID = courseID;
    }
    public String getCourseName() {
      return courseName;
    }
    public void setCourseName(String courseName) {
      this.courseName = courseName;
    }
    public String getResourceID() {
      return resourceID;
    }
    public void setResourceID(String resourceID) {
      this.resourceID = resourceID;
    }
    public String getResourceName() {
      return resourceName;
    }
    public void setResourceName(String resourceName) {
      this.resourceName = resourceName;
    }
    public String getUserID() {
      return userID;
    }
    public void setUserID(String userID) {
      this.userID = userID;
    }
    public String getUsername() {
      return username;
    }
    public void setUsername(String userName) {
      this.username = userName;
    }

    public Boolean getRequired() {
      return required;
    }
    public void setRequired(Boolean required) {
      this.required = required;
    }
    public Integer getOrderNum() {
      return orderNum;
    }
    public void setOrderNum(Integer orderNum) {
      this.orderNum = orderNum;
    }
    
    public TbTaskItem toTaskItem() {
      TbTaskItem taskItem = new TbTaskItem();
      taskItem.setID(getID());
      taskItem.setTaskID(getTaskID());
      taskItem.setItemType(itemType);
      taskItem.setRequired(required);
      taskItem.setOrderNum(orderNum);
      taskItem.setCreateTime(getCreateTime());
      taskItem.setCreator(getCreator());
      
      // 根据类型设置对应的itemID
      if (courseID != null && !courseID.isEmpty()) {
        taskItem.setItemID(courseID);
        if (itemType == null) {
          taskItem.setItemType(2);  // 课程
        }
      } else if (resourceID != null && !resourceID.isEmpty()) {
        taskItem.setItemID(resourceID);
        if (itemType == null) {
          taskItem.setItemType(1);  // 资源
        }
      }
      
      return taskItem;
    }
    public TbTaskUser toTaskUser() {
      TbTaskUser taskUser = new TbTaskUser();
      taskUser.setUserID(userID);
      taskUser.setTaskID(getTaskID());
      taskUser.setCreateTime(getCreateTime());
      taskUser.setCreator(getCreator());
      return taskUser;
    }
    public Integer getStatus() {
      return status;
    }
    public void setStatus(Integer status) {
      this.status = status;
    }
    public BigDecimal getProgress() {
      return progress;
    }
    public void setProgress(BigDecimal progress) {
      this.progress = progress;
    }
    public Date getCompleteTime() {
      return completeTime;
    }
    public void setCompleteTime(Date completeTime) {
      this.completeTime = completeTime;
    }

    
}
