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

namespace IRaCIS.Core.Domain.Models;
public class OSSImageInfo
{
    public string FileName { get; set; } = string.Empty;

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

[Comment("项目阅片 - 医学审核")]
[Table("TaskMedicalReview")]
public class TaskMedicalReview : BaseFullAuditEntity
{
    #region 导航属性

    [JsonIgnore]
    public User LatestReplyUser { get; set; }

    [JsonIgnore]
    public User MedicalManagerUser { get; set; }

    [JsonIgnore]
    [ForeignKey("VisitTaskId")]
    public VisitTask VisitTask { get; set; }

    [JsonIgnore]
    public List<ReadingMedicalReviewDialog> ReadingMedicalReviewDialogList { get; set; }

    [JsonIgnore]
    public Trial Trial { get; set; }
    [Comment("文件")]
    [NotMapped]
    public List<OSSImageInfo> FileList
    {
        get
        {
            try
            {
                var result = JsonConvert.DeserializeObject<List<OSSImageInfo>>(this.ImagePath);
                return result == null ? new List<OSSImageInfo>() : result;
            }
            catch (Exception)
            {

                return new List<OSSImageInfo>();
            }

        }
    }

    [NotMapped]
    public List<Guid> PDRelationTaskIdList => PDRelationTaskIdListStr.Split('|', StringSplitOptions.RemoveEmptyEntries).Select(t => Guid.Parse(t)).ToList();

    #endregion

    public Guid? LatestReplyUserId { get; set; }
    [Comment("分配时间")]
    public DateTime? AllocateTime { get; set; }

    [Comment("审核状态")]
    
    public MedicalReviewAuditState AuditState { get; set; }

    [Comment("审核通过时间")]
    public DateTime? AuditSignTime { get; set; }

    [Comment("阅片人是否认同")]
    public MedicalReviewDoctorUserIdea DoctorUserIdeaEnum { get; set; }

    /// <summary>
    /// mim
    /// </summary>
    public Guid? MedicalManagerUserId { get; set; }
    public Guid VisitTaskId { get; set; }
    public Guid TrialId { get; set; }

    /// <summary>
    /// 审核结论  false 为通过 true 为不通过
    /// </summary>
    [Comment("是否有问题")]
    public bool IsHaveQuestion { get; set; } = false;

    [Comment("质询问题")]
    public string Questioning { get; set; } = string.Empty;

    [Comment("图片路径")]
    [StringLength(1000)]
    public string ImagePath { get; set; } = string.Empty;

    [Comment("审核建议")]
    public AuditAdvice AuditAdviceEnum { get; set; }

    [Comment("是否关闭对话")]
    public bool IsClosedDialog { get; set; }

    [Comment("保存问题的时间")]
    public DateTime? SaveQuestionTime { get; set; }
    [Comment("不同意重阅原因")]
    public string DisagreeReason { get; set; } = string.Empty;
    [Comment("是否申请重阅")]
    public bool IsApplyHeavyReading { get; set; } = false;
    [Comment("保存结论时间")]
    public DateTime? SaveConclusionTime { get; set; }
    [Comment("文件名称")]
    public string FileName { get; set; } = string.Empty;

    [Comment("是否发送消息")]
    public bool IsSendMessage { get; set; } = false;
    [Comment("医学审核对话关闭原因")]
    public MedicalDialogClose MedicalDialogCloseEnum { get; set; }

    [Comment("对话关闭原因")]
    public string DialogCloseReason { get; set; } = string.Empty;

    [Comment("无效的 为True无效")]
    public bool IsInvalid { get; set; }

    public bool IsAutoGenerate { get; set; }

    [StringLength(1000)]
    public string PDRelationTaskIdListStr { get; set; } = string.Empty;
}