using Assets.Native.tools.excel.Atrtribute;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Assets.Native.tools.excel.Model {

    [DataContract]
    class ExerciseBaseConfigOutPutModel
    {
        
        [DataMember(Name = "Version", EmitDefaultValue = false)]
        public string Version;

        [DataMember(Name = "BaseConfig", EmitDefaultValue = false)]
        public List<ExerciseBaseConfigModel> PracticeBaseConfigModels = new List<ExerciseBaseConfigModel>();
        public ExerciseBaseConfigOutPutModel(List<ExerciseExcelPageRow> practiceExcelPageRows, string Version)
        { 
            foreach(ExerciseExcelPageRow practiceExcelContent in practiceExcelPageRows)
            {
                ExerciseBaseConfigModel practiceBaseConfigModel = new ExerciseBaseConfigModel(practiceExcelContent);
                PracticeBaseConfigModels.Add(practiceBaseConfigModel);
            }

            this.Version = Version;
            //practiceExcelPageRows.ForEach(practiceExcelContent => PracticeBaseConfigModels.Add(new PracticeBaseConfigModel(practiceExcelContent)));
        }
    }

    [DataContract]
    class ExerciseBaseConfigModel
    {
        Dictionary<string, string> GameDic = new Dictionary<string, string>()
        {
            { "选择题", "Select"},
            { "单选题", "Select"},
            { "多选题", "MultipleSelect"},
            { "脑泡题", "Select2"},
            { "音频题", "Select3"},
            { "拖拽题", "Drag"},
            { "连线题", "Line"},
            { "排序题", "Sort"},
            { "找不同", "Search"},
            { "观察题", "Observe"},

        };

        Dictionary<string, string> GameNameDic = new Dictionary<string, string>()
        {
            { "Select", "单选题"},
            { "MultipleSelect", "多选题"},
            { "Select2", "脑泡题"},
            { "Select3", "音频题"},
            { "Drag", "拖拽题"},
            { "Line", "连线题"},
            { "Sort", "排序题"},
            { "Search", "找不同"},
            { "Observe", "观察题"},
        };

        Dictionary<string, string> GameIDDic = new Dictionary<string, string>()
        {
            { "Select", "1"},
            { "Drag", "2"},
            { "Select2", "3"},
            { "Line", "4"},
            { "MultipleSelect", "5"},
            { "Select3", "6"},
            { "Observe", "7"},
            { "Search", "8"},
            { "Sort", "9"},

        };

        Dictionary<string, string> AbilityDic = new Dictionary<string, string>()
        {
            { "记忆力", "memory"},
            { "观察力", "observe"},
            { "逻辑力", "logic"},
            { "理解力", "comprehension"},
            { "语言力", "language"},
        };

        [DataMember(Name = "QuestionId", EmitDefaultValue = false)]
        public string QuestionId;

        [DataMember(Name = "GameType", EmitDefaultValue = false)]
        public string GameType;

        [DataMember(Name = "GameName", EmitDefaultValue = false)]
        public string GameName;

        [DataMember(Name = "AbilityType", EmitDefaultValue = false)]
        public string AbilityType;

        [DataMember(Name = "AbilityName", EmitDefaultValue = false)]
        public string AbilityName;

        [DataMember(Name = "QuestionText", EmitDefaultValue = false)]
        public string QuestionText;

        [DataMember(Name = "AnswerText", EmitDefaultValue = false)]
        public List<string> AnswerText;

        [DataMember(Name = "AnalysisText", EmitDefaultValue = false)]
        public string AnalysisText;

        [DataMember(Name = "RightCount", EmitDefaultValue = false)]
        public string RightCount;

        public ExerciseBaseConfigModel(ExerciseExcelPageRow data)
        {
            GameType = GameDic[data.GameType];
            AbilityName = data.AbilityType;
            AbilityType = AbilityDic[data.AbilityType];
            if(!string.IsNullOrEmpty(data.QuestionText))
            {
                QuestionText = data.QuestionText;
            }
            if (!string.IsNullOrEmpty(data.AnalysisText))
            {
                AnalysisText = data.AnalysisText;
            }
            if (!string.IsNullOrEmpty(data.RightCount))
            {
                RightCount = data.RightCount;
            }
            if (!string.IsNullOrEmpty(data.AnswerText))
            {
                AnswerText = new List<string>(data.AnswerText.Split("/"));
            }
            if(GameType == "Select") {
                int count = string.IsNullOrEmpty(RightCount) ? 0 : int.Parse(RightCount);
                if(count > 1)
                {
                    GameType = "MultipleSelect";
                }
            } else if(GameType == "Observe")
            {
                AnalysisText = "正确答案是：";
            } else if (GameType == "Sort")
            {
                QuestionText = "按照故事发展，拖动图片进行排序吧。";
            }

            QuestionId = GameIDDic[GameType];
            GameName = GameNameDic[GameType];
        }
    }
}
