using Edu.Model.ViewModel.Question;
using System;
using System.Collections.Generic;
using System.Text;

namespace Edu.Module.Question
{
    /// <summary>
    /// 解析问题
    /// </summary>
    public class AnalysisQuestionTypeModule
    {
        /// <summary>
        /// 问题解析
        /// </summary>
        /// <param name="key"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public object ParsingQuestion(string key, string data)
        {
            var obj = new object();
            switch (key)
            {
                //单选题
                case "single":
                    obj = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(data);
                    break;
                //多选题
                case "multiple":
                    obj = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(data);
                    break;
                //填空题
                case "fill-in":
                    if (!string.IsNullOrEmpty(data))
                    {
                        obj = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(data);
                    }
                    else
                    {
                        obj = null;
                    }
                    break;
                //判断题
                case "judge":
                    obj = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(data);
                    break;
                //简答题
                case "short-answer":
                    obj = data;
                    break;
                //名词解释
                case "noun-explanation":
                    obj = data;
                    break;
                //论述题
                case "essay-question":
                    obj = data;
                    break;
                //计算题
                case "calculation":
                    obj = data;
                    break;
                //分录题
                case "entry-problem":
                    obj = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(data);
                    break;
                //资料题
                case "data-question":
                    obj = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(data);
                    break;
                //连线题
                case "matching":
                    obj = Common.Plugin.JsonHelper.DeserializeObject<List<List<matchingItem>>>(data);
                    break;
                //排序题
                case "sorting-problem":
                    obj = Common.Plugin.JsonHelper.DeserializeObject<List<List<matchingItem>>>(data);
                    break;
                //完型填空
                case "cloze":
                    obj = Common.Plugin.JsonHelper.DeserializeObject<List<List<optionItem>>>(data);
                    break;
                //阅读理解
                case "reading-comprehensio":
                    var readingList = Common.Plugin.JsonHelper.DeserializeObject<List<readingComprehensioItem>>(data);
                    if (readingList != null && readingList.Count > 0)
                    {
                        foreach (var item in readingList)
                        {
                            switch (item.QuestionKey)
                            {
                                //单选题
                                case "single":
                                    item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
                                    break;
                                //多选题
                                case "multiple":
                                    item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
                                    break;
                                //填空题
                                case "fill-in":
                                    item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(item.SubAnwser.ToString());
                                    break;
                                //判断题
                                case "judge":
                                    item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
                                    break;
                                //简答题
                                case "short-answer":
                                    item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(item.SubAnwser.ToString());
                                    break;
                                //单选题(数字)
                                case "single-number":
                                    item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
                                    break;
                            }
                        }
                    }
                    obj = readingList;
                    break;
                //口语题
                case "spoken":
                    obj = data;
                    break;
                //听力题
                case "listening":
                    var listenList = Common.Plugin.JsonHelper.DeserializeObject<List<readingComprehensioItem>>(data);
                    if (listenList != null && listenList.Count > 0)
                    {
                        foreach (var item in listenList)
                        {
                            switch (item.QuestionKey)
                            {
                                //单选题
                                case "single":
                                    item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
                                    break;
                                //多选题
                                case "multiple":
                                    item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
                                    break;
                                //填空题
                                case "fill-in":
                                    item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(item.SubAnwser.ToString());
                                    break;
                                //判断题
                                case "judge":
                                    item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
                                    break;
                                //简答题
                                case "short-answer":
                                    item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(item.SubAnwser.ToString());
                                    break;
                            }
                        }
                    }
                    obj = listenList;
                    break;
                //共用选择题
                case "sharing-choose":
                    if (!string.IsNullOrEmpty(data))
                    {
                        obj = Common.Plugin.JsonHelper.DeserializeObject<List<List<matchingItem>>>(data);
                    }
                    else
                    {
                        obj = null;
                    }
                    break;
                //其它题
                case "other":
                    obj = data;
                    break;
                //单选题(数字)
                case "single-number":
                    try
                    {
                        if (!string.IsNullOrEmpty(data))
                        {
                            obj = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(data);
                        }
                    }
                    catch (Exception ex)
                    {
                        string str = ex.Message;
                    }
                    break;
            }
            return obj;
        }
    }
}
