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

namespace IRaCIS.Core.Domain.Models;

[Comment("项目阅片问题")]
[Table("ReadingQuestionTrial")]
public class ReadingQuestionTrial : BaseAddAuditEntity
{
    #region 导航属性
    [Comment("分页标准")]
    [ForeignKey("ReadingCriterionPageId")]
    [JsonIgnore]
    public ReadingCriterionPage ReadingCriterionPage { get; set; }
    [JsonIgnore]
    [ForeignKey("ParentId")]
    public ReadingQuestionTrial ParentReadingQuestionTrial { get; set; }
    [JsonIgnore]
    [ForeignKey("RelevanceId")]
    public ReadingQuestionTrial RelevanceReadingQuestionTrial { get; set; }
    [JsonIgnore]
    [ForeignKey("ReadingQuestionCriterionTrialId")]
    public ReadingQuestionCriterionTrial ReadingQuestionCriterionTrial { get; set; }

    [JsonIgnore]
    public List<ReadingTableQuestionTrial> ReadingTableQuestionTrialList { get; set; }
    [JsonIgnore]
    [ForeignKey("GroupId")]
    public ReadingQuestionTrial GroupInfo { 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>();
            }

        }
    }

    [NotMapped]
    public List<string> HighlightAnswerList
    {
        get
        {

            try
            {
                var result = JsonConvert.DeserializeObject<List<string>>(this.HighlightAnswer);
                return result == null ? new List<string>() : result;
            }
            catch (Exception)
            {

                return new List<string>();
            }

        }
    }
    #endregion
    public bool IsAdditional { get; set; }
    [Comment("项目标准Id")]
    public Guid ReadingQuestionCriterionTrialId { get; set; }

    [Comment("项目Id")]
    public Guid TrialId { get; set; }

    [Comment("类型")]
    public string Type { get; set; } = string.Empty;

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

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

    [Comment("是否是必须")]
    public IsRequired IsRequired { get; set; }

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

    [Comment("父问题ID")]
    public Guid? ParentId { get; set; }
    [Comment("类型值")]
    public string TypeValue { get; set; } = string.Empty;

    public bool IsEnable { get; set; }

    [Comment("是否是裁判问题")]
    public bool IsJudgeQuestion { get; set; }

    [Comment("病灶类型")]
    public LesionType? LesionType { get; set; }

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

    [Comment("全局阅片显示类型")]
    public GlobalReadingShowType GlobalReadingShowType { get; set; } = GlobalReadingShowType.NotShow;
    [Comment("转化显示类型")]
    public ConvertShowType ConvertShowType { get; set; } = ConvertShowType.All;

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

    [Comment("分组")]
    public string GroupName { get; set; } = string.Empty;
    [Comment("系统问题ID")]
    public Guid? ReadingQuestionSystemId { get; set; }

    [Comment("系统标准的ParentId")]
    public Guid? SystemParentId { get; set; }

    [Comment("答案分组")]
    public string AnswerGroup { get; set; } = string.Empty;

    [Comment("答案组合")]
    public string AnswerCombination { get; set; } = string.Empty;

    [Comment("裁判类型")]
    public JudgeTypeEnum JudgeType { get; set; } = JudgeTypeEnum.AnswerDisaffinity;

    [Comment("裁判百分比或绝对值的相差值")]
    public decimal? JudgeDifferenceValue { get; set; }

    [Comment("裁判百分比或绝对值的相差值匹配规则")]
    public JudgeDifferenceType JudgeDifferenceType { get; set; }
    [Comment("标准分页Id")]
    public Guid? ReadingCriterionPageId { get; set; }

    [Comment("关联ID")]
    public Guid? RelevanceId { get; set; }

    [Comment("关联Value")]
    public string RelevanceValue { get; set; } = string.Empty;

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

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

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

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

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

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

    [Comment("是否显示在Dicom阅片中")]
    public bool IsShowInDicom { get; set; } = false;
    [Comment("序号标记")]
    public string OrderMark { get; set; } = string.Empty;

    [Comment("字典code")]
    public string DictionaryCode { get; set; } = string.Empty;

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

    [Comment("数值类型")]
    public ValueOfType? ValueType { get; set; }

    [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("限制显示")]
    public LimitShow LimitShow { get; set; } = LimitShow.AllShow;

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

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

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

    [Comment("问题英文分组")]
    public string GroupEnName { get; set; } = string.Empty;

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

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

    [Comment("是否复制病灶")]
    public bool IsCopyLesions { get; set; } = false;

    [Comment("分组ID")]
    public Guid? GroupId { get; set; }
    [Comment("分组分类")]
    public GroupClassify? GroupClassify { get; set; }
    [Comment("问题分类")]
    public QuestionClassify? QuestionClassify { get; set; }
    [Comment("高亮问题的答案")]
    public string HighlightAnswer { 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>();
            }

        }
    }
}
public class CalculateInfo
{
    public bool IsTable { get; set; }

    public Guid? QuestionId { get; set; }

    public Guid? TableQuestionId { get; set; }

}