using IRaCIS.Core.Domain.Share;
using System.Linq;

namespace IRaCIS.Core.Domain.Models;

[Comment("系统表格问题")]
[Table("ReadingTableQuestionSystem")]
public class ReadingTableQuestionSystem : BaseAddAuditEntity
{
    #region 导航属性
    [ForeignKey("DependParentId")]
    [JsonIgnore]
    public ReadingTableQuestionSystem DependParentQuestion { get; set; }


    [JsonIgnore]
    [ForeignKey("ReadingQuestionId")]
    public ReadingQuestionSystem ReadingQuestionSystem { get; set; }

    [NotMapped]
    public List<string> ParentTriggerValueList
    {
        get
        {
            try
            {
                return this.ParentTriggerValue.Split(',').ToList();
            }
            catch (Exception)
            {

                return new List<string>();
            }
        }

    }
    [NotMapped]
    public List<string> RelevanceValueList
    {
        get
        {
            try
            {
                return this.RelevanceValue.Split(',').ToList();
            }
            catch (Exception)
            {

                return new List<string>();
            }
        }

    }
    #endregion

    [Comment("系统表的问题Id    ReadingQuestionSystem的Id")]
    public Guid ReadingQuestionId { get; set; }

    public string Type { get; set; } = string.Empty;
    public Guid? ParentId { get; set; }

    [Comment("父问题触发值")]
    public string ParentTriggerValue { get; set; } = string.Empty;

    [Comment("问题名称")]
    public string QuestionName { get; set; } = string.Empty;

    [Comment("默认值")]
    public string DefaultValue { get; set; } = string.Empty;
    public IsRequired IsRequired { get; set; }

    [Comment("排序号")]
    public int ShowOrder { get; set; }

    [Comment("值")]
    public string TypeValue { get; set; } = string.Empty;

    [Comment("是否启用")]
    public bool IsEnable { get; set; }

    [Comment("备注")]
    public string Remark { get; set; } = string.Empty;

    [Comment("显示父问题")]
    public Guid? RelevanceId { get; set; }

    [Comment("显示父问题的值")]
    public string RelevanceValue { get; set; } = string.Empty;

    [Comment("是否显示")]
    public ShowQuestion ShowQuestion { get; set; }

    [Comment("最大问题数")]
    public int? MaxRowCount { get; set; }

    [Comment("图片数量")]
    public int? ImageCount { get; set; }

    [Comment("数据表名称")]
    public string DataTableName { get; set; } = string.Empty;

    [Comment("数据列")]
    public string DataTableColumn { get; set; } = string.Empty;
    [Comment("关联父问题")]
    public Guid? DependParentId { get; set; }

    [Comment("是否关联")]
    public IsDepend IsDepend { get; set; }

    [Comment("表格问题类型")]
    public TableQuestionType? TableQuestionType { get; set; }

    [Comment("系统标准Id")]
    public Guid SystemCriterionId { get; set; }

    [Comment("问题标识")]
    public QuestionMark? QuestionMark { get; set; }

    [Comment("字典code")]
    public string DictionaryCode { get; set; } = string.Empty;
    [Comment("数值类型")]
    public ValueOfType? ValueType { get; set; }

    [Comment("单位")]
    public ValueUnit? Unit { get; set; }

    [Comment("问题英文名称")]
    public string QuestionEnName { get; set; } = string.Empty;

    [Comment("数据来源")]
    public DataSources DataSource { get; set; } = DataSources.ManualEntry;

    /// <summary>
    /// 显示图表类型
    /// </summary>
    public ShowChartType ShowChartTypeEnum { get; set; } = ShowChartType.NotShow;

    /// <summary>
    /// 选项类型
    /// </summary>
    public OptionType OptionTypeEnum { get; set; } = OptionType.Defalut;

    [Comment("限制编辑")]
    public LimitEdit LimitEdit { get; set; } = LimitEdit.None;

    [Comment("最大答案长度")]
    public int? MaxAnswerLength { get; set; }

    [Comment("文件类型")]
    public string? FileType { get; set; } = string.Empty;

    [Comment("问题分类")]
    public QuestionClassify? QuestionClassify { get; set; }

    [Comment("复制病灶的时候 是否复制这个问题")]
    public bool IsCopy { get; set; } = false;

    [Comment("分类问题表格Id")]
    public Guid? ClassifyTableQuestionId { get; set; }

    [Comment("分类类型")]
    public ClassifyType? ClassifyType { get; set; }

    /// <summary>
    /// 分类编辑类型  是否可编辑
    /// </summary>
    public ClassifyEditType? ClassifyEditType { get; set; }

    /// <summary>
    /// 分类显示类型  是否显示
    /// </summary>
    public ClassifyShowType? ClassifyShowType { get; set; }

    [Comment("分类算法")]
    public string ClassifyAlgorithms { get; set; } = string.Empty;

    [Comment("导出结果")]
    public string ExportResultStr { get; set; } = "[]";


    /// <summary>
    /// 是否预设
    /// </summary>
    public bool IsPreinstall { get; set; } = false;

    [NotMapped]
    public List<ExportResult> ExportResult
    {
        get
        {
            try
            {
                var result = JsonConvert.DeserializeObject<List<ExportResult>>(this.ExportResultStr);
                return result == null ? new List<ExportResult>() : result;
            }
            catch (Exception)
            {

                return new List<ExportResult>();
            }

        }
    }


}
