package com.ssj.service.kmt.dto;

import com.ssj.framework.weixin.util.DateUtil;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.*;

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

    private String subject;
    /**
     * 日期 yyyy-MM-dd
     */
    private String time;


    private List<KnowledgeBaseDto> versionList;

    private List<Map<String, Object>> grades;

    private List<StudentHomeworkDto> list;

    public SubjectStudentHomeworkDto (String subject, Date date) {
        this.subject = subject;
        this.setTime(date);
        list = new ArrayList<StudentHomeworkDto>();
        this.initGrade();
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getTime() {
        return this.time;
    }

    public void setTime(Date date) {
        this.time = DateUtil.format_yyyyMMdd(date);
    }

    public List<StudentHomeworkDto> getList() {
        return list;
    }

    public void setList(List<StudentHomeworkDto> list) {
        this.list = list;
    }

    public void addStudent (StudentHomeworkDto student) {
        this.list.add(student);
    }

    public void addProblem (String vipId, HomeworkPictureDto picture) {
        if (StringUtils.isNotEmpty(vipId)){
            for (StudentHomeworkDto sp : list){
                if (sp.getVipId().equals(vipId)){
                    sp.getHomeworkPictureList().add(picture);
                    break;
                }
            }
        }
    }

    public boolean containStudent (String vipId) {
        boolean result = false;
        if (StringUtils.isNotEmpty(vipId)){
            for (StudentHomeworkDto sp : list){
                if (sp.getVipId().equals(vipId)){
                    result = true;
                    break;
                }
            }
        }
        return result;
    }

    public List<KnowledgeBaseDto> getVersionList() {
        return versionList;
    }

    public void setVersionList(List<KnowledgeBaseDto> versionList) {
        this.versionList = versionList;
    }

    public List<Map<String, Object>> getGrades() {
        return grades;
    }

    public void setGrades(List<Map<String, Object>> grades) {
        this.grades = grades;
    }
    public void initGrade (){
        String[] grades = {"一年级","二年级","三年级","四年级","五年级","六年级"};
        this.grades = new ArrayList<>();
        for (String grade : grades){
            Map<String, Object> gradeMap = new HashMap<>();
            gradeMap.put("grade", grade);
            this.grades.add(gradeMap);
        }
    }
}
