package com.ssj.service.kmt.constant;


import com.ssj.service.kmt.dto.KnowledgeBaseDto;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class KnowledgeVersion {

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

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

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

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

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

    public void init() {
        initChineseList();
        initMathList();
        initEnglishList();
        initPhysicsList();
        initChemistryList();
    }

    public void destroy () {

    }

    /**
     * 初始化语文版本
     */
    public void initChineseList () {
        KnowledgeBaseDto temp = new KnowledgeBaseDto(1, "人教版");
        this.chineseList.add(temp);
        temp = new KnowledgeBaseDto(2, "人教(部编)");
        this.chineseList.add(temp);
        temp = new KnowledgeBaseDto(3, "人教(部编旧)");
        this.chineseList.add(temp);
    }

    /**
     * 初始化数学版本
     */
    public void initMathList () {
        KnowledgeBaseDto northTemp = new KnowledgeBaseDto(1, "北师大版");
        this.mathList.add(northTemp);
        KnowledgeBaseDto renTemp = new KnowledgeBaseDto(2, "人教版");
        this.mathList.add(renTemp);
        KnowledgeBaseDto suTTemp = new KnowledgeBaseDto(5, "苏教版");
        this.mathList.add(suTTemp);
        KnowledgeBaseDto siTemp = new KnowledgeBaseDto(6, "思维拓展");
        this.mathList.add(siTemp);
    }

    /**
     * 初始化英语版本
     */
    public void initEnglishList () {
        KnowledgeBaseDto temp = new KnowledgeBaseDto(3, "沪教版（新）");
        this.englishList.add(temp);

        KnowledgeBaseDto longmanEdition = new KnowledgeBaseDto(7, "朗文版");
        this.englishList.add(longmanEdition);

        KnowledgeBaseDto peopleEducationEdition = new KnowledgeBaseDto(8, "人教版(PEP)");
        this.englishList.add(peopleEducationEdition);

        KnowledgeBaseDto teachingVersion = new KnowledgeBaseDto(2, "教科版");
        this.englishList.add(teachingVersion);

        KnowledgeBaseDto oxford = new KnowledgeBaseDto(9, "牛津版");
        this.englishList.add(oxford);

        KnowledgeBaseDto externalResearchEdition = new KnowledgeBaseDto(10, "外研版");
        this.englishList.add(externalResearchEdition);

        temp = new KnowledgeBaseDto(11, "广东人民版");
        this.englishList.add(temp);

        temp = new KnowledgeBaseDto(12, "牛津上海版");
        this.englishList.add(temp);

        temp = new KnowledgeBaseDto(14, "译林版");
        this.englishList.add(temp);
    }

    /**
     * 初始化物理版本
     */
    public void initPhysicsList () {
        KnowledgeBaseDto temp = new KnowledgeBaseDto(2, "人教版");
        this.physicsList.add(temp);
    }

    /**
     * 初始化化学版本
     */
    public void initChemistryList () {
        KnowledgeBaseDto temp = new KnowledgeBaseDto(2, "人教版");
        this.chemistryList.add(temp);
    }


    /**
     * 根据科目返回版本列表
     * @param subject
     * @return
     */
    public List<KnowledgeBaseDto> getVersionListBySubject (String subject) {
        List<KnowledgeBaseDto> result;
        switch (subject){
            case "语文": result = this.chineseList; break;
            case "数学": result = this.mathList; break;
            case "英语": result = this.englishList; break;
            default: result = this.physicsList;
        }
        return result;
    }

    /**
     * 根据科目和版本号获取版本名
     */
    public String getVersionNameBySubjectAndVersionNum(String subject, Integer versionNum) {
        List<KnowledgeBaseDto> knowledgeBaseDtoList = getVersionListBySubject(subject);
        for (KnowledgeBaseDto knowledgeBaseDto : knowledgeBaseDtoList) {
            if (Objects.equals(versionNum, knowledgeBaseDto.getType())) {
                return knowledgeBaseDto.getName();
            }
        }

        return "未知的版本";
    }

    /**
     * 根据科目和版本名获取版本号
     */
    public Integer getVersionNumBySubjectAndVersionName(String subject, String versionName) {
        List<KnowledgeBaseDto> knowledgeBaseDtoList = getVersionListBySubject(subject);
        for (KnowledgeBaseDto knowledgeBaseDto : knowledgeBaseDtoList) {
            if (Objects.equals(versionName, knowledgeBaseDto.getName())) {
                return knowledgeBaseDto.getType();
            }
        }
        return 0;
    }

}
