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  双字段
        [JsonIgnore]
        public TrialSite TrialSite { get; set; }
        public Guid TrialId { get; set; }
        public Guid SubjectId { get; set; }
        public Guid SiteId { get; set; }

        [JsonIgnore]
        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; }

        /// <summary>
        /// 单审通过人
        /// </summary>
        public Guid? PreliminaryAuditUserId { get; set; }

        /// <summary>
        /// 双审通过人
        /// </summary>
        public Guid? ReviewAuditUserId { get; set; }

        /// <summary>
        /// 一致性核查人Id
        /// </summary>
        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; }
        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 DateTime? CheckBackTime { 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; }

        /// <summary>
        /// 上一检查批次
        /// </summary>
        public Guid? OutPlanPreviousVisitId { get; set; }

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

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

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

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

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


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

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

        [JsonIgnore]
        [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; }

        public bool IsVisitTaskGenerated { get; set; }

        public bool IsPMBackOrReReading { get; set; }

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


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

        public Guid? DeleteUserId { get; set; }


        public Guid? SubmitUserId { get; set; }

        [JsonIgnore]
        [ForeignKey("SubmitUserId")]
        public User SubmitUser { get; set; }

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

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

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


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

        ////一个检查批次 对应该Site下的多个IC管理   必须加这个  不然生成的sql 会报 TrialSiteUserId  不存在该列名

        //public List<TrialSiteUser> TrialSiteUserList { 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>();

  

        public ReadingStatusEnum ReadingStatus { get; set; }


    }
}
