using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using IRaCIS.Core.Domain.Share;
using Microsoft.EntityFrameworkCore.Metadata.Internal;

namespace IRaCIS.Core.Domain.Models
{
    [Table("SubjectVisit")]
    public class SubjectVisit : Entity, IAuditUpdate, IAuditAdd, ISoftDelete
    {
        //一个访视  对应有对应Site的  TrialSiteCode   所以 fluentApi中配置  TrialSite  连表用TrialId  SiteId  双字段
        public TrialSite TrialSite { get; set; }
        public Guid TrialId { get; set; }
        public Guid SubjectId { get; set; }
        public Guid SiteId { get; set; }


        public VisitStage VisitStage { get; set; }
        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; }

        [Column(TypeName = "decimal(18,1)")]
        public decimal VisitNum { get; set; }
        //public string AnonymousVisitName { get; set; } = string.Empty;
        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;


        //0 未执行  1 执行了  2 不可用
        public VisitExecutedEnum VisitExecuted { get; set; } = VisitExecutedEnum.UnExecuted;

        public DateTime? EarliestScanDate { get; set; }

        public DateTime? LatestScanDate { get; set; }

        public Guid CreateUserId { get; set; }
        public DateTime CreateTime { get; set; }
        public Guid UpdateUserId { get; set; }
        public DateTime UpdateTime { get; set; }

        public Guid? Auditor { get; set; }
        

        //public SubjectVisitStateEnum VisitState { get; set; }

        //核查状态
        public CheckStateEnum CheckState { get; set; }

        //提交状态
        public SubmitStateEnum SubmitState { get; set; }
        //审核状态
        public AuditStateEnum AuditState { get; set; }
        public ForwardStateEnum ForwardState { get; set; }
        public Guid? PreliminaryAuditUserId { get; set; }

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

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

        /// <summary>
        /// 通过原因
        /// </summary>
        public string ManualPassReason { get; set; }

        public bool IsUrgent { get; set; }

        public bool IsTake { get; set; }

        public bool IsFinalVisit { get; set; }

        public ChallengeStateEnum ChallengeState { get; set; }

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

        //是否一致性核查回退
        public bool? IsCheckBack { get; set; }

        public CheckChanllengeTypeEnum CheckChallengeState { get; set; }
        public PDStateEnum PDState { get; set; } = PDStateEnum.None;

        //public bool IsOutEnromentVisit { get; set; } = false;

        public DateTime? CheckPassedTime { get; set; }

        public Guid? OutPlanPreviousVisitId { get; set; }

        //public Guid? ClinicalDataSignUserId { get; set; }

        //public DateTime? ClinicalDataSignTime { get; set; }

        [ForeignKey("ClinicalDataSignUserId")]
        public User ClinicalDataSignUser { get; set; }

        [ForeignKey("ForwardUserId")]
        public User ForwardUser { get; set; }


        [ForeignKey("PreliminaryAuditUserId")]
        public User PreliminaryAuditUser { get; set; }

        [ForeignKey("ReviewAuditUserId")]
        public User ReviewAuditUser { get; set; }

        [ForeignKey("CurrentActionUserId")]
        public User CurrentActionUser { get; set; }

        public RequestBackStateEnum RequestBackState { get; set; }


        public bool IsQCConfirmedReupload { get; set; }

        public bool IsLostVisit { get; set; }


        //是否确认了、签名了 临床数据完整性
        public bool? IsConfirmedClinicalData { get; set; }


        public bool IsEnrollmentConfirm { get; set; }

        /// <summary>
        /// 关闭一致性质疑原因
        /// </summary>
        public string CloseTheReason { get; set; }


        public bool IsDeleted { get; set; }
        public DateTime? DeletedTime { get; set; }

        public Guid? DeleteUserId { get; set; }


        //导航属性
        [ForeignKey("TrialId")]
        public Trial Trial { get; set; }

        [ForeignKey("SiteId")]
        public Site Site { get; set; }

        [ForeignKey("SubjectId")]
        public Subject Subject { get; set; }


        //// 一个访视可以被多个参与者 查看
        //public List<TrialUser> TrialUsers { get; set; }

        ////一个访视 对应该Site下的多个CRC管理   必须加这个  不然生成的sql 会报 TrialSiteUserId  不存在该列名

        //public List<TrialSiteUser> TrialSiteUserList { get; set; }

        public List<PreviousHistory> PreviousHistoryList { get; set; }

        public List<PreviousOther> PreviousOtherList { get; set; }

        public List<PreviousSurgery> PreviousSurgeryList { get; set; }

        public List<PreviousPDF> PreviousPDFList { get; set; }

        public List<CheckChallengeDialog> CheckChallengeDialogList { get; set; } = new List<CheckChallengeDialog>();

        public List<DicomStudy> StudyList { get; set; } = new List<DicomStudy>();

        public List<NoneDicomStudy> NoneDicomStudyList { get; set; } = new List<NoneDicomStudy>();


        public List<QCChallenge> QCChallengeList { get; set; } = new List<QCChallenge>();

        public List<QCChallengeDialog> QCChallengeDialogList { get; set; } = new List<QCChallengeDialog>();


    }



}
