package com.ssj.service.kmt.request;

import com.ssj.bean.common.framework.core.domain.BaseRequest;
import com.ssj.service.kmt.dto.KnowHowDetailsDTO;
import com.ssj.service.kmt.dto.KnowledgeBaseDto;
import io.swagger.annotations.ApiModelProperty;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;

import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;

public class QuestionUpdateRequest extends BaseRequest {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(name = "questionId", value = "题目id", required = false)
    private String  questionId;

    @ApiModelProperty(name = "questionText", value = "题目", required = true)
    private String questionText;

    @ApiModelProperty(name = "smallQuestionIndex", value = "小题号", required = true)
    private String smallQuestionIndex;

    @ApiModelProperty(name = "questionImage", value = "题目原图", required = true)
    private String questionImage;

    @ApiModelProperty(name = "answerJson", value = "答案", required = true)
    private String answerJson;

    @ApiModelProperty(name = "questionAnalysis", value = "题目解析", required = false)
    private String questionAnalysis;

    @ApiModelProperty(name = "analysisJson", value = "解析json字符串", required = false)
    private String analysisJson;

    @ApiModelProperty(name = "questionTypes", value = "题目类型", required = false)
    private List<KnowledgeBaseDto> questionTypes;

    @ApiModelProperty(name = "difficultyLevels", value = "难度级别", required = false)
    private List<KnowledgeBaseDto> difficultyLevels;

    @ApiModelProperty(name = "realExamTypes", value = "真题、例题类型", required = false)
    private List<KnowledgeBaseDto> realExamTypes;

    @ApiModelProperty(name = "trainingSkills", value = "训练能力", required = false)
    private List<KnowledgeBaseDto> trainingSkills;

    @ApiModelProperty(name = "knowledges", value = "关联的知识点", required = false)
    private List<KnowHowDetailsDTO> knowledges;

    @ApiModelProperty(name = "subject", value = "科目", required = false)
    private String subject;

    @ApiModelProperty(name = "yearName", value = "年份", required = false)
    private String yearName;

    private int beginYear;

    private int endYear;

    public String getQuestionId() {
        return questionId;
    }

    public void setQuestionId(String questionId) {
        this.questionId = questionId;
    }

    public String getSmallQuestionIndex() {
        return smallQuestionIndex;
    }

    public void setSmallQuestionIndex(String smallQuestionIndex) {
        this.smallQuestionIndex = smallQuestionIndex;
    }

    public String getQuestionText() {
        return questionText;
    }

    public void setQuestionText(String questionText) {
        this.questionText = questionText;
    }

    public String getQuestionImage() {
        return questionImage;
    }

    public void setQuestionImage(String questionImage) {
        this.questionImage = questionImage;
    }

    public String getAnswerJson() {
        return answerJson;
    }

    public void setAnswerJson(String answerJson) {
        this.answerJson = answerJson;
    }

    public String getQuestionAnalysis() {
        return questionAnalysis;
    }

    public void setQuestionAnalysis(String questionAnalysis) {
        this.questionAnalysis = questionAnalysis;
    }

    public String getAnalysisJson() {
        return analysisJson;
    }

    public void setAnalysisJson(String analysisJson) {
        this.analysisJson = analysisJson;
    }

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

    public void setQuestionTypes(List<KnowledgeBaseDto> questionTypes) {
        this.questionTypes = questionTypes.stream().collect(collectingAndThen(
                toCollection(() -> new TreeSet<>(Comparator.comparing(KnowledgeBaseDto::getType))), ArrayList::new));
    }

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

    public void setDifficultyLevels(List<KnowledgeBaseDto> difficultyLevels) {
        this.difficultyLevels = difficultyLevels.stream().collect(collectingAndThen(
                toCollection(() -> new TreeSet<>(Comparator.comparing(KnowledgeBaseDto::getType))), ArrayList::new));
    }

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

    public void setRealExamTypes(List<KnowledgeBaseDto> realExamTypes) {
        this.realExamTypes = realExamTypes.stream().collect(collectingAndThen(
                toCollection(() -> new TreeSet<>(Comparator.comparing(KnowledgeBaseDto::getType))), ArrayList::new));
    }

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

    public void setTrainingSkills(List<KnowledgeBaseDto> trainingSkills) {
        this.trainingSkills = trainingSkills.stream().collect(collectingAndThen(
                toCollection(() -> new TreeSet<>(Comparator.comparing(KnowledgeBaseDto::getType))), ArrayList::new));
    }

    public List<KnowHowDetailsDTO> getKnowledges() {
        return knowledges;
    }

    public void setKnowledges(List<KnowHowDetailsDTO> knowledges) {
        this.knowledges = knowledges.stream().collect(collectingAndThen(
                toCollection(() -> new TreeSet<>(Comparator.comparing(KnowHowDetailsDTO::getId))), ArrayList::new));
    }

    public String getSubject() {
        return subject;
    }

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

    public void setYearName(String yearName) {
        this.yearName = yearName;
        if (yearName != null && yearName !=""){
            String[] yearArray = yearName.split("-");
            if (yearArray.length == 2){
                this.beginYear = Integer.parseInt(yearArray[0]);
                this.endYear = Integer.parseInt(yearArray[1]);

            }
        }
    }

    public int getBeginYear() {
        return beginYear;
    }


    public int getEndYear() {
        return endYear;
    }
}
