package com.ssj.service.sys.homework.vo;

import com.alibaba.fastjson.annotation.JSONField;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class HomeworkExerciseBookDto implements Serializable {
    private static final long serialVersionUID = 1L;

    private String bookId;

    private String bookName;

    private int partFlag;

    @JSONField(serialize = false)
    private String courseName;

    @JSONField(serialize = false)
    private int versionType;

    @JSONField(serialize = false)
    private int semester;

    private List<HomeworkExerciseUnitDto> units;

    public HomeworkExerciseBookDto (String bookId, String bookName){
        this.bookId = bookId;
        this.bookName = bookName;
    }

    public String getBookId() {
        return bookId;
    }

    public void setBookId(String bookId) {
        this.bookId = bookId;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    @JSONField(serialize = false)
    public int getPartFlag() {
        return partFlag;
    }

    public void setPartFlag(int partFlag) {
        this.partFlag = partFlag;
    }

    public List<HomeworkExerciseUnitDto> getUnits() {
        return units;
    }

    public void setUnits(List<HomeworkExerciseUnitDto> units) {
        this.units = units;
    }

    public void addUnit(String unitId, String unitName, String periodId, String periodName){
        boolean isExist = false;
        if (this.units == null){
            this.units = new ArrayList<>();
        }
        //新建课时对象
        HomeworkExercisePeriodDto periodDto = new HomeworkExercisePeriodDto(periodId, periodName);
        for (HomeworkExerciseUnitDto unit : this.units){
            if (unit.getUnitId().equals(unitId)){
                isExist = true;
                unit.addPeriod(periodDto);
            }
        }
        //如果单元不存在，需要新增单元
        if (!isExist){
            HomeworkExerciseUnitDto unit = new HomeworkExerciseUnitDto(unitId, unitName);
            unit.addPeriod(periodDto);
            this.units.add(unit);
        }
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public int getVersionType() {
        return versionType;
    }

    public void setVersionType(int versionType) {
        this.versionType = versionType;
    }

    public int getSemester() {
        return semester;
    }

    public void setSemester(int semester) {
        this.semester = semester;
    }
}
