package com.ssj.service.kmt.dto;


import com.alibaba.fastjson.JSONArray;
import com.ssj.conch.constant.CourseConstant;
import com.ssj.framework.core.util.PropertiesUtil;
import com.ssj.framework.core.util.SystemResourceLocator;
import com.ssj.service.kmt.constant.KnowledgeVersion;
import com.ssj.service.kmt.dto.exercise.QuestionSubjectAttribute;
import org.apache.commons.lang3.StringUtils;

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

public class KnowledgeSubjectDto implements Serializable {

    private static final long serialVersionUID = 1L;

    private String name;

    private int textBookIndex = 0;

    private List<KnowledgeBaseDto> textBookList = new ArrayList<KnowledgeBaseDto>();

    private int bookTypeIndex = 0;

    private List<KnowledgeBaseDto> bookTypeList =  new ArrayList<KnowledgeBaseDto>();

    private List<KnowledgeBaseDto> questionTypes  =  new ArrayList<KnowledgeBaseDto>();
    private List<KnowledgeBaseDto> realExamTypes  =  new ArrayList<KnowledgeBaseDto>();
    private List<KnowledgeBaseDto> difficultyLevels  =  new ArrayList<KnowledgeBaseDto>();
    private List<KnowledgeBaseDto> trainingSkills  =  new ArrayList<KnowledgeBaseDto>();

    public KnowledgeSubjectDto (String subject) {
        this.name = subject;
        this.createBookType();
        KnowledgeVersion knowledgeVersion = SystemResourceLocator.getBean(KnowledgeVersion.class);
        this.textBookList = knowledgeVersion.getVersionListBySubject(subject);


        //题目类型
        if (StringUtils.isNotBlank(CourseConstant.QUESTION_TYPES_STR)){
            for (QuestionSubjectAttribute baseDto : JSONArray.parseArray(CourseConstant.QUESTION_TYPES_STR, QuestionSubjectAttribute.class)){
                if (this.name.equals(baseDto.getSubject())){
                    questionTypes = baseDto.getList();
                }
            }
        }

        //难易度
        if (StringUtils.isNotBlank(CourseConstant.DIFFICULTY_LEVELS_STR)){
            this.difficultyLevels = JSONArray.parseArray(CourseConstant.DIFFICULTY_LEVELS_STR, KnowledgeBaseDto.class);
        }

        //真例题类型
        if (StringUtils.isNotBlank(CourseConstant.REAL_EXAM_TYPE_STR)){
            this.realExamTypes = JSONArray.parseArray(CourseConstant.REAL_EXAM_TYPE_STR, KnowledgeBaseDto.class);
        }

        //能力
        if (StringUtils.isNotBlank(CourseConstant.TRAINING_SKILL_STR)){
            for (QuestionSubjectAttribute baseDto : JSONArray.parseArray(CourseConstant.TRAINING_SKILL_STR, QuestionSubjectAttribute.class)){
                if (this.name.equals(baseDto.getSubject())){
                    this.trainingSkills = baseDto.getList();
                }
            }
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getTextBookIndex() {
        return textBookIndex;
    }

    public void setTextBookIndex(int textBookIndex) {
        this.textBookIndex = textBookIndex;
    }

    public List<KnowledgeBaseDto> getTextBookList() {
        return textBookList;
    }

    public void setTextBookList(List<KnowledgeBaseDto> textBookList) {
        this.textBookList = textBookList;
    }

    public int getBookTypeIndex() {
        return bookTypeIndex;
    }

    public void setBookTypeIndex(int bookTypeIndex) {
        this.bookTypeIndex = bookTypeIndex;
    }

    public List<KnowledgeBaseDto> getBookTypeList() {
        return bookTypeList;
    }

    public void setBookTypeList(List<KnowledgeBaseDto> bookTypeList) {
        this.bookTypeList = bookTypeList;
    }

    public void createBookType () {
        KnowledgeBaseDto temp = new KnowledgeBaseDto(1, "同步");
        this.bookTypeList.add(temp);
        if ("语文".equals(this.name) || "英语".equals(this.name)){
            temp = new KnowledgeBaseDto(2, "专题");
            this.bookTypeList.add(temp);
        }
    }

    public List<KnowledgeBaseDto> getQuestionTypes() {
        return questionTypes;
    }

    public void setQuestionTypes(List<KnowledgeBaseDto> questionTypes) {
        this.questionTypes = questionTypes;
    }

    public List<KnowledgeBaseDto> getRealExamTypes() {
        return realExamTypes;
    }

    public void setRealExamTypes(List<KnowledgeBaseDto> realExamTypes) {
        this.realExamTypes = realExamTypes;
    }

    public List<KnowledgeBaseDto> getDifficultyLevels() {
        return difficultyLevels;
    }

    public void setDifficultyLevels(List<KnowledgeBaseDto> difficultyLevels) {
        this.difficultyLevels = difficultyLevels;
    }

    public List<KnowledgeBaseDto> getTrainingSkills() {
        return trainingSkills;
    }

    public void setTrainingSkills(List<KnowledgeBaseDto> trainingSkills) {
        this.trainingSkills = trainingSkills;
    }
}
