package com.ssj.service.conch.parents.v2.dto;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.ssj.framework.core.util.Constant;
import com.ssj.service.kmt.dto.exercise.ExerciseQuestionAnswerSpace;
import com.ssj.service.kmt.dto.exercise.ExerciseQuestionAnswerValue;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

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

/**
 * @author yrf
 * @time 2019/12/18 21:03
 */
public class TrainRecommendQuestionDTO implements Serializable {

    private static final long serialVersionUID = 1023056215317123924L;

    private String id;
    private String question;

    @JSONField(serialize = false)
    private String questionJsonStr;

    private List<ExerciseQuestionAnswerValue> questionJson;

    private String analysis;

    @JSONField(serialize = false)
    private String analysisJsonStr;

    private List<ExerciseQuestionAnswerSpace> analysisJson;

    private String optionAnswer;

    @JSONField(serialize = false)
    private String optionAnswerStr;

    private List<ExerciseQuestionAnswerSpace> optionAnswerJson;

    @JSONField(serialize = false)
    private String answerJsonStr;

    private List<ExerciseQuestionAnswerSpace> answerJson;

    private Integer difficulty;

    @JSONField(serialize = false)
    private Integer optionTypeInt;

    @JSONField(serialize = false)
    private String courseName;

    @JSONField(serialize = false)
    private Integer num;

    @JSONField(serialize = false)
    private Integer questionClassType;

    @JSONField(serialize = false)
    private Boolean contentEmpty = false;

    private String optionType;
    private List<TrainRecommendQuestionDTO> childList;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getQuestion() {
        return question;
    }

    public void setQuestion(String question) {
        this.question = question;
    }

    public String getQuestionJsonStr() {
        return questionJsonStr;
    }

    public void setQuestionJsonStr(String questionJsonStr) {
        this.questionJsonStr = questionJsonStr;
    }

    public List<ExerciseQuestionAnswerValue> getQuestionJson() {
        if (CollectionUtils.isEmpty(questionJson) &&
                StringUtils.isNotBlank(questionJsonStr) &&
                !"[]".equals(questionJsonStr)) {
            this.questionJson = JSON.parseArray(questionJsonStr, ExerciseQuestionAnswerValue.class);
        }
        return questionJson;
    }

    public void setQuestionJson(List<ExerciseQuestionAnswerValue> questionJson) {
        this.questionJson = questionJson;
    }

    public String getAnalysis() {
        return analysis;
    }

    public void setAnalysis(String analysis) {
        this.analysis = analysis;
    }

    public String getAnalysisJsonStr() {
        return analysisJsonStr;
    }

    public void setAnalysisJsonStr(String analysisJsonStr) {
        this.analysisJsonStr = analysisJsonStr;
    }

    public List<ExerciseQuestionAnswerSpace> getAnalysisJson() {
        if (CollectionUtils.isEmpty(analysisJson) &&
                StringUtils.isNotBlank(analysisJsonStr) &&
                !"[]".equals(analysisJsonStr)) {
            this.analysisJson = JSON.parseArray(analysisJsonStr, ExerciseQuestionAnswerSpace.class);
        }
        return analysisJson;
    }

    public void setAnalysisJson(List<ExerciseQuestionAnswerSpace> analysisJson) {
        this.analysisJson = analysisJson;
    }

    public String getOptionAnswer() {
        return optionAnswer;
    }

    public void setOptionAnswer(String optionAnswer) {
        this.optionAnswer = optionAnswer;
    }

    public String getAnswerJsonStr() {
        return answerJsonStr;
    }

    public void setAnswerJsonStr(String answerJsonStr) {
        this.answerJsonStr = answerJsonStr;
    }

    public List<ExerciseQuestionAnswerSpace> getAnswerJson() {
        if (CollectionUtils.isEmpty(answerJson) &&
                StringUtils.isNotBlank(answerJsonStr) &&
                !"[]".equals(answerJsonStr)) {
            this.answerJson = JSON.parseArray(answerJsonStr, ExerciseQuestionAnswerSpace.class);
        }
        return answerJson;
    }

    public void setAnswerJson(List<ExerciseQuestionAnswerSpace> answerJson) {
        this.answerJson = answerJson;
    }

    public Integer getDifficulty() {
        return difficulty;
    }

    public void setDifficulty(Integer difficulty) {
        this.difficulty = difficulty;
    }

    public Integer getOptionTypeInt() {
        return optionTypeInt;
    }

    public void setOptionTypeInt(Integer optionTypeInt) {
        this.optionTypeInt = optionTypeInt;
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    public Integer getQuestionClassType() {
        return questionClassType;
    }

    public void setQuestionClassType(Integer questionClassType) {
        this.questionClassType = questionClassType;
    }

    public Boolean getContentEmpty() {
        return contentEmpty;
    }

    public void setContentEmpty(Boolean contentEmpty) {
        this.contentEmpty = contentEmpty;
    }

    public String getOptionType() {
        if (optionTypeInt != null) {
            return Constant.QUESTION_TYPE_MAP.get(optionTypeInt);
        }
        return optionType;
    }

    public void setOptionType(String optionType) {
        this.optionType = optionType;
    }

    public List<TrainRecommendQuestionDTO> getChildList() {
        return childList;
    }

    public void setChildList(List<TrainRecommendQuestionDTO> childList) {
        this.childList = childList;
    }

    @Override
    public String toString() {
        return "TrainRecommendQuestionDTO{" +
                "id='" + id + '\'' +
                ", question='" + question + '\'' +
                ", questionJsonStr='" + questionJsonStr + '\'' +
                ", analysis='" + analysis + '\'' +
                ", analysisJsonStr='" + analysisJsonStr + '\'' +
                ", optionAnswer='" + optionAnswer + '\'' +
                ", optionAnswerStr='" + optionAnswerStr + '\'' +
                ", answerJsonStr='" + answerJsonStr + '\'' +
                ", difficulty=" + difficulty +
                ", optionTypeInt=" + optionTypeInt +
                ", courseName='" + courseName + '\'' +
                ", num=" + num +
                ", questionClassType=" + questionClassType +
                ", contentEmpty=" + contentEmpty +
                ", optionType='" + optionType + '\'' +
                ", childList=" + childList +
                '}';
    }
}
