
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace QuestionSwapDoc.SwapQuestionModel
{
    /// <summary>
    /// 试题
    /// </summary>
    public class QueItem
    {
        /// <summary>
        /// 关于此题的标记信息
        /// </summary>
        public string Data { get; set; }
        /// <summary>
        /// 题型
        /// </summary>
        public string TiXin { get; set; }
        /// <summary>
        /// 难易程度(1容易 2较易 3中等 4较难 5困难)
        /// </summary>
        public int? NanYi { get; set; }

        /// <summary>
        /// 题所有（题所有=题干+选项+答案+解析）
        /// </summary>
        public QueItemRange TiAllRange { get; set; } = new QueItemRange();
        /// <summary>
        /// 题（题=题干+选项）
        /// </summary>
        public QueItemRange TiRange { get; set; } = new QueItemRange();
        /// <summary>
        /// 题的简要文本（用来在数据库中快速搜索题）
        /// </summary>
        public string TiStr { get; set; }
        /// <summary>
        /// 题干（选择题才有）
        /// </summary>
        public QueItemRange TiGanRange { get; set; } = new QueItemRange();
        /// <summary>
        /// 选项（选择题才有）
        /// </summary>
        public List<QueItemRange> XuanXianRanges { get; set; } = new List<QueItemRange>();
        /// <summary>
        /// 答案
        /// （单选题、多选题为字符串，如"A,B,C"）
        /// （判断题为bool值，如"True"）
        /// </summary>
        public QueItemRange DaAnRange { get; set; } = new QueItemRange();
        /// <summary>
        /// 解析
        /// </summary>
        public QueItemRange JieXiRange { get; set; } = new QueItemRange();


        /// <summary>
        /// 指定选项是否为正确答案
        /// </summary>
        /// <param name="XuanXianRange">选项</param>
        /// <returns></returns>
        public bool IsXuanXianDaAn(QueItemRange XuanXianRange)
        {
            var index = XuanXianRanges.IndexOf(XuanXianRange);
            if (index == -1)
                return false;

            return IsXuanXianDaAn(index);
        }
        /// <summary>
        /// 指定选项是否为正确答案
        /// </summary>
        /// <param name="index">选项的索引</param>
        /// <returns></returns>
        public bool IsXuanXianDaAn(int index)
        {
            if (index > SwapQuestion.XuanXianQianZui.Length)
                return false;

            var qianZui = SwapQuestion.XuanXianQianZui[index].Substring(0, 1);
            return DaAnRange.HtmlText.Contains(qianZui);
        }


        /// <summary>
        /// 转为难易程度int类型(1容易 2较易 3中等 4较难 5困难)
        /// </summary>
        /// <param name="txt">中文或者（1-5的汉字）</param>
        /// <returns></returns>
        public static int? ToNanYiInt(string txt)
        {
            switch (txt)
            {
                case "1":
                case "容易":
                    return 1;
                case "2":
                case "较易":
                    return 2;
                case "3":
                case "中等":
                    return 3;
                case "4":
                case "较难":
                    return 4;
                case "5":
                case "困难":
                    return 5;
                default:
                    return null;
            }
        }

    }
}
