package com.ssj.service.conch.teacher.library.dto;

import com.alibaba.fastjson.JSONObject;
import com.ssj.framework.core.util.PropertiesUtil;

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

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

    private String subject;

    /**
     * 	1全部完成 2部分完成 3无作业, 4无纸面作业
     */
    private int finishState;

    private long startTime;

    private long endTime;

    private List<UnFinishedLabelStateDto> unfinishedList;

    private List<LibraryHomeworkPictureDto> homeworkPictureList;

    public String getSubject() {
        return subject;
    }

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

    public int getFinishState() {
        return finishState;
    }

    public void setFinishState(int finishState) {
        this.finishState = finishState;
    }

    public List<UnFinishedLabelStateDto> getUnfinishedList() {
        return unfinishedList;
    }

    public void setUnfinishedList(List<UnFinishedLabelStateDto> unfinishedList) {
        this.unfinishedList = unfinishedList;
    }

    public List<LibraryHomeworkPictureDto> getHomeworkPictureList() {
        return homeworkPictureList;
    }

    public void setHomeworkPictureList(List<LibraryHomeworkPictureDto> homeworkPictureList) {
        this.homeworkPictureList = homeworkPictureList;
    }

    public void addHomeworkPicture(LibraryHomeworkPictureDto hpd){
        if (this.homeworkPictureList == null) {
            this.homeworkPictureList = new ArrayList<>();
        }
        this.homeworkPictureList.add(hpd);
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public long getEndTime() {
        return endTime;
    }

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

    public void initUnfinishOption(String[] seleteds){
        if (this.unfinishedList == null){
            this.unfinishedList = new ArrayList<UnFinishedLabelStateDto>();
        }

        if ("语文".equals(this.subject)){
            this.unfinishedList = JSONObject.parseArray(PropertiesUtil.getValue("CHINESE_PART_FINISH_CONTENT"), UnFinishedLabelStateDto.class);
        } else if ("英语".equals(this.subject)){
            this.unfinishedList = JSONObject.parseArray(PropertiesUtil.getValue("ENGLISH_PART_FINISH_CONTENT"), UnFinishedLabelStateDto.class);
        } else {
            this.unfinishedList = JSONObject.parseArray(PropertiesUtil.getValue("MATH_PART_FINISH_CONTENT"), UnFinishedLabelStateDto.class);
        }

        if (seleteds != null){
            List<String> seletedList = Arrays.asList(seleteds);
            for (UnFinishedLabelStateDto item : this.unfinishedList){
                item.setActive(0);
                if (seletedList.contains(item.getName())){
                    item.setActive(1);
                } else if ("其他".equals(item.getName())){
                    for (String seleted : seleteds){
                        if (seleted.indexOf("其他") != -1){
                            item.setActive(1);
                            item.setContent(seleted.replace("其他（", "").replace("）", ""));
                        }
                    }
                }
            }
        }
    }
}
