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

namespace IRaCIS.Core.Domain.Models;

[Comment("项目阅片问题")]
[Table("ReadingTableQuestionTrial")]
public class ReadingTableQuestionTrial : BaseAddAuditEntity
{
    #region 导航属性
    [JsonIgnore]
    [ForeignKey("DependParentId")]
    public ReadingTableQuestionTrial DependParentQuestion { get; set; }

    [JsonIgnore]
    [ForeignKey("ReadingQuestionId")]
    public ReadingQuestionTrial ReadingQuestionTrial { 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>();
            }
        }

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

                return new List<CalculateInfo>();
            }

        }
    }
    #endregion

    public Guid TrialId { get; set; }

    [Comment("项目问题的Id ReadingQuestionTrial的id")]
    public Guid ReadingQuestionId { get; set; }
    public string Type { get; set; } = string.Empty;
    public Guid? ParentId { get; set; }

    public string ParentTriggerValue { get; set; } = string.Empty;
    public string QuestionName { get; set; } = string.Empty;
    public IsRequired IsRequired { get; set; }

    public int ShowOrder { get; set; }

    public string TypeValue { get; set; } = string.Empty;
    public bool IsEnable { get; set; }
    [Comment("注释")]
    public string Remark { get; set; } = string.Empty;
    public Guid? RelevanceId { get; set; }

    public string RelevanceValue { get; set; } = string.Empty;

    public ShowQuestion ShowQuestion { get; set; }
    public int? MaxRowCount { get; set; }

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

    public string DataTableName { get; set; } = string.Empty;

    public string DataTableColumn { get; set; } = string.Empty;

    public TableQuestionType? TableQuestionType { get; set; }

    public Guid? DependParentId { get; set; }

    public IsDepend IsDepend { get; set; }
    public Guid TrialCriterionId { 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 string ClassifyAlgorithms { get; set; } = string.Empty;

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

    [Comment("自定义单位")]
    public string CustomUnit { get; set; } = string.Empty;

    [Comment("自定义计算标记")]
    public CustomCalculateMark? CustomCalculateMark { get; set; }

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

    [Comment("自定义计算标记")]
    [MaxLength]
    public string CalculateQuestions { get; set; } = "[]";

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

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

    [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? SystemTableQuestionId { get; set; }

    [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 ExportIdentification? ExportIdentification { get; set; }

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

    [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>();
            }

        }
    }
}