using IRaCIS.Core.Domain.Share;
namespace IRaCIS.Core.Domain.Models;

[Comment("受试者访视")]
[Table("SubjectVisit")]
public class SubjectVisit : BaseFullDeleteAuditEntity
{
    #region 导航属性

    [JsonIgnore]
    public List<TaskStudy> TaskStudyList { get; set; }

    [JsonIgnore]
    public List<TrialQCQuestionAnswer> TrialQCQuestionAnswerList { get; set; }

    [JsonIgnore]
    public TrialSite TrialSite { get; set; }

    [JsonIgnore]
    public List<ClinicalForm> ClinicalFormList { get; set; }

    [JsonIgnore]
    [ForeignKey("OutPlanPreviousVisitId")]
    public SubjectVisit OutPlanPreviousVisit { get; set; }
    [ForeignKey("ForwardUserId")]
    public UserRole ForwardUser { get; set; }

    /// <summary>
    /// 初审
    /// </summary>
    [JsonIgnore]
    [ForeignKey("PreliminaryAuditUserId")]
    public UserRole PreliminaryAuditUser { get; set; }

    /// <summary>
    /// 复审
    /// </summary>
    [JsonIgnore]
    [ForeignKey("ReviewAuditUserId")]
    public UserRole ReviewAuditUser { get; set; }

    [JsonIgnore]
    [ForeignKey("CurrentActionUserId")]
    public UserRole CurrentActionUser { get; set; }
    [JsonIgnore]
    [ForeignKey("SubmitUserId")]
    public UserRole SubmitUser { get; set; }
    [JsonIgnore]
    [ForeignKey("TrialId")]
    public Trial Trial { get; set; }
    [JsonIgnore]
    public List<ReadModule> ReadModuleList { get; set; }
    [JsonIgnore]
    [ForeignKey("SubjectId")]
    public Subject Subject { get; set; }
    [JsonIgnore]
    public List<PreviousHistory> PreviousHistoryList { get; set; }
    [JsonIgnore]
    public List<PreviousOther> PreviousOtherList { get; set; }
    [JsonIgnore]
    public List<PreviousSurgery> PreviousSurgeryList { get; set; }
    [JsonIgnore]
    public List<PreviousPDF> PreviousPDFList { get; set; }
    [JsonIgnore]
    public List<ReadingClinicalData> ReadingClinicalDataList { get; set; }
    [JsonIgnore]
    public List<CheckChallengeDialog> CheckChallengeDialogList { get; set; } = new List<CheckChallengeDialog>();
    [JsonIgnore]
    public List<DicomStudy> StudyList { get; set; } = new List<DicomStudy>();
    [JsonIgnore]
    public List<NoneDicomStudy> NoneDicomStudyList { get; set; } = new List<NoneDicomStudy>();

    [JsonIgnore]
    public List<QCChallenge> QCChallengeList { get; set; } = new List<QCChallenge>();
    [JsonIgnore]
    public List<QCChallengeDialog> QCChallengeDialogList { get; set; } = new List<QCChallengeDialog>();
    [JsonIgnore]
    public List<VisitTask> VisitTaskList { get; set; } = new List<VisitTask>();

    [JsonIgnore]
    public List<SubjectCriteriaEvaluationVisitFilter> SubjectCriteriaEvaluationVisitFilterList { get; set; }

    [JsonIgnore]
    public List<SubjectVisitImageBackRecord> SubjectVisitImageBackRecordList { get; set; }
    #endregion

    public Guid TrialSiteId { get; set; }
    public Guid TrialId { get; set; }
    public Guid SubjectId { get; set; }

    [Comment("访视计划Id，计划外没有")]
    public Guid? VisitStageId { get; set; }
    public int VisitDay { get; set; }
    public string VisitName { get; set; } = string.Empty;
    public int VisitWindowLeft { get; set; }
    public int VisitWindowRight { get; set; }

    [DecimalPrecision(18, 1)]
    public decimal VisitNum { get; set; }
    public string BlindName { get; set; } = string.Empty;

    public string SVUPDES { get; set; } = string.Empty;
    public DateTime? SVSTDTC { get; set; }
    public DateTime? SVENDTC { get; set; }
    public bool InPlan { get; set; } = true;
    public bool IsBaseLine { get; set; } = false;

    [Comment("0 未执行  1 执行了  2 不可用")]
    public VisitExecutedEnum VisitExecuted { get; set; } = VisitExecutedEnum.UnExecuted;

    public DateTime? EarliestScanDate { get; set; }

    [Comment("最晚拍片日期")]
    public DateTime? LatestScanDate { get; set; }

    public Guid? Auditor { get; set; }

    [Comment("核查状态")]
    public CheckStateEnum CheckState { get; set; }

    [Comment("提交状态")]
    public SubmitStateEnum SubmitState { get; set; }

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

    [Comment("单审通过人")]
    public Guid? PreliminaryAuditUserId { get; set; }

    [Comment("双审通过人")]
    public Guid? ReviewAuditUserId { get; set; }

    [Comment("一致性核查人Id")]
    public Guid? CheckUserId { get; set; }

    public DateTime? ReviewAuditTime { get; set; }
    public DateTime? PreliminaryAuditTime { get; set; }
    public Guid? ForwardUserId { get; set; }
    public DateTime? ForwardTime { get; set; }

    /// <summary>
    /// 当前领取
    /// </summary>
    [Comment("当前质控领取人")]
    public Guid? CurrentActionUserId { get; set; }
    public DateTime? CurrentActionUserExpireTime { get; set; }

    public DateTime? SubmitTime { get; set; }
    public DateTime? CheckTime { get; set; }

    [Comment("通过原因")]
    public string ManualPassReason { get; set; } = string.Empty;

    public bool IsUrgent { get; set; }

    public bool IsTake { get; set; }

    public bool IsFinalVisit { get; set; }

    public ChallengeStateEnum ChallengeState { get; set; }

    [MaxLength]
    public string CheckResult { get; set; } = String.Empty;

    [Comment("是否一致性核查回退")]
    public bool? IsCheckBack { get; set; }

    public DateTime? CheckBackTime { get; set; }

    public CheckChanllengeTypeEnum CheckChallengeState { get; set; }
    public PDStateEnum PDState { get; set; } = PDStateEnum.None;
    public DateTime? CheckPassedTime { get; set; }
    [Comment("计划外上一访视")]
    public Guid? OutPlanPreviousVisitId { get; set; }
    [Comment("一致性核查 回退")]
    public RequestBackStateEnum RequestBackState { get; set; }
    public bool IsQCConfirmedReupload { get; set; }

    public bool IsLostVisit { get; set; }

    [Comment("是否确认了、签名了 临床数据完整性")]
    public bool? IsConfirmedClinicalData { get; set; }

    public bool IsEnrollmentConfirm { get; set; }

    public bool IsVisitTaskGenerated { get; set; }

    public bool IsPMBackOrReReading { get; set; }

    [Comment("关闭一致性质疑原因")]
    public string CloseTheReason { get; set; } = string.Empty;

    public Guid? SubmitUserId { get; set; }
    public ReadingStatusEnum ReadingStatus { get; set; }

    public SecondReviewState SecondReviewState { get; set; }
}

[Comment("受试者访视影像回退记录表")]
[Table("SubjectVisitImageBackRecord")]
public class SubjectVisitImageBackRecord : BaseFullAuditEntity
{
    [JsonIgnore]
    public SubjectVisit SubjectVisit { get; set; }


    public Guid SubjectVisitId { get; set; }

    public DateTime? SubmitTime { get; set; }

    public DateTime? EarliestScanDate { get; set; }

    [Comment("最晚拍片日期")]
    public DateTime? LatestScanDate { get; set; }



    public ImageBackApplyEnum ApplyUserRole { get; set; }

    [Comment("影像上传 回退")]
    public ImageBackStateEnum ImageBackState { get; set; }

    public DateTime? AuditTime { get; set; }

    /// <summary>
    /// 申请原因
    /// </summary>
    public string ApplyReason { get; set; } = string.Empty;

    /// <summary>
    /// 结果备注
    /// </summary>
    public string ResultRemark { get; set; } = string.Empty;

}
