using IRaCIS.Core.Domain.Share;
using System.ComponentModel.DataAnnotations;

namespace IRaCIS.Core.Application.Contracts
{

    public class CRCVisitSearchDTO : PageInput
    {

        public AuditStateEnum[]? AuditStateArray { get; set; }
        public SubmitStateEnum? SubmitState { get; set; }
        public ChallengeStateEnum? ChallengeState { get; set; }

        [NotDefault]
        public Guid TrialId { get; set; }
        public Guid? SiteId { get; set; }
        public Guid? SubjectId { get; set; }

        public bool? IsUrgent { get; set; }
        public string SubjectInfo { get; set; } = string.Empty;
        //public string VisitPlanInfo { get; set; } = string.Empty;

        public string[]? VisitPlanArray { get; set; }

    }

    public class QCVisitSearchDTO : PageInput
    {

        //public AuditStateEnum? AuditState { get; set; }

        public AuditStateEnum[]? AuditStateArray { get; set; }

        public ChallengeStateEnum? ChallengeState { get; set; }

        public bool? IsUrgent { get; set; }
        public Guid TrialId { get; set; }
        public Guid? SiteId { get; set; }
        public Guid? SubjectId { get; set; }

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

        public string[]? VisitPlanArray { get; set; }
        //public string VisitPlanInfo { get; set; } = String.Empty;

        public Guid? HandleUserId { get; set; }
    }


    public class CRCRequestToQCCommand
    {
        [NotDefault]
        public Guid TrialId { get; set; }


        public Guid[] SubjectVisitIds { get; set; }=new Guid[0];
    }



    public class CRCReuploadFinishedCommand
    {
        [NotDefault]
        public Guid TrialId { get; set; }

        [NotDefault]
        public Guid QCChallengeId { get; set; }

        public bool SetOrCancel { get; set; }

    }

    public class UploadSubjectAndVisitCommand
    {
        public Guid SubjectVisitId { get; set; }
        public Guid SubjectId { get; set; }
        public PDStateEnum PDState { get; set; }

        //前端有可能不传递  不是基线的时候
        public bool? IsEnrollmentConfirm { get; set; }
        public DateTime? SubjectFirstGiveMedicineTime { get; set; }

    }

    public class TrialSubjectAndSVConfig
    {
        public bool IsHaveFirstGiveMedicineDate { get; set; }
        public bool IsSubjectSexView { get; set; } = false;
        public bool IsSubjectExpeditedView { get; set; } = false;

        public bool IsEnrollementQualificationConfirm { get; set; }
        public bool IsPDProgressView { get; set; }


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

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

        public string Modalitys { get; set; } = String.Empty;
        public string DocumentConfirmSignText { get; set; } = String.Empty;

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

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

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

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

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

        public int ClinicalInformationTransmissionEnum { get; set; }

        public TrialQCProcess QCProcessEnum { get; set; }

    }



    public class QCCRCVisitViewModel : QCVisitBasicListViewModel
    {
        public Guid? OutPlanPreviousVisitId { get; set; }
        public bool IsOutEnromentVisit { get; set; }

        public PDStateEnum PDState { get; set; }
        public bool IsEnrollmentConfirm { get; set; }
        public DateTime? SubjectFirstGiveMedicineTime { get; set; }

        public SubjectStatus SubjectStatus { get; set; }
        public string SubjectCode { get; set; } = String.Empty;

        //public int? StudyCount { get; set; }
        public String TrialSiteCode { get; set; } = String.Empty;

        public DateTime? SubmitTime { get; set; }
        public AuditStateEnum AuditState { get; set; }


        public int? DicomStudyCount { get; set; }
        public int? NoneDicomStudyCount { get; set; }

        public bool IsHaveClinicalData { get; set; }

        public string MedicalNo { get; set; } 

        public int? Age { get; set; }
        public string Sex { get; set; } = string.Empty;

    }


    public class ChallengeQuery : PageInput
    {
        [NotDefault]
        public Guid TrialId { get; set; }

        public string[]? VisitPlanArray { get; set; }

        //public string VisitPlanInfo { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;
        public QCChanllengeReuploadEnum? ReuploadEnum { get; set; }

        public bool? IsUrgent { get; set; }
        public Guid? SubjectId { get; set; }
        public Guid? SiteId { get; set; }
        public bool? IsClosed { get; set; }
        public bool? IsOverTime { get; set; }
        public Guid? CreateUserId { get; set; }

    }

    public class QCCRCChallengeViewModel
    {
        public Guid? PreliminaryAuditUserId { get; set; }
        public Guid? CurrentActionUserId { get; set; }

        public string? CurrentActionUserName { get; set; }

        public bool IsBaseLine { get; set; }
        public bool IsUrgent { get; set; }
        public Guid? ClinicalDataSignUserId { get; set; }

        public bool IsQCConfirmedReupload { get; set; }

        //public string CreatorFirstName { get; set; }
        //public string CreatorLastName { get; set; }
        public string BlindName { get; set; } = String.Empty;

        //public string ReplyerRealName { get; set; }

        public DateTime? ReUploadedTime { get; set; }
        public Guid SubjectVisitId { get; set; }
        public Guid SubjectId { get; set; }
        public Guid Id { get; set; }
        public String TrialSiteCode { get; set; } = String.Empty;

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

        public decimal VisitNum { get; set; }
        public string VisitName { get; set; } = string.Empty;

        public RequestBackStateEnum RequestBackState { get; set; }

        public bool IsClosed { get; set; }

        public DateTime? ClosedTime { get; set; }

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

        //public string ClosedUserUserName { get; set; } = String.Empty;

        public DateTime? CreateTime { get; set; }

        public Guid CreateUserId { get; set; }

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

        //public bool NeedReUpload { get; set; }
        public QCChanllengeReuploadEnum ReuploadEnum { get; set; }
        public DateTime? DeadlineTime { get; set; }

        public Guid SiteId { get; set; }
        public AuditStateEnum AuditState { get; set; }
        public CurrentQC CurrentQCEnum { get; set; }
        public TrialQCProcess QCProcessEnum { get; set; }

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

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

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


        public bool IsOverTime => IsClosed ? ClosedTime > DeadlineTime : DateTime.Now > DeadlineTime;

        public Guid LatestReplyUserId { get; set; }


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

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

        public UserTypeEnum UserTypeEnum { get; set; }


        public DateTime? LatestMsgTime { get; set; }

        public string ChallengeDuration
        {
            get
            {
                if (!ClosedTime.HasValue)
                    return "";
                else return string.Format("{0}天{1}小时{2}分钟", (ClosedTime - CreateTime)?.Days, (ClosedTime - CreateTime)?.Hours, (ClosedTime - CreateTime)?.Minutes);
            }
        }


    }

    public class CheckQuery : PageInput
    {
        public string SubjectInfo { get; set; } = String.Empty;

        //public string VisitPlanInfo { get; set; } = String.Empty;
        public string[]? VisitPlanArray { get; set; }

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

        public Guid TrialId { get; set; }

        public Guid? SiteId { get; set; }

        //public bool? IsClosed { get; set; }
    }


    public class ForwardQuery : PageInput
    {
        public Guid TrialId { get; set; }

        public Guid? SiteId { get; set; }
        public string SubjectInfo { get; set; } = String.Empty;

        public string[]? VisitPlanArray { get; set; }

        //public string VisitPlanInfo { get; set; } = String.Empty;

        public ForwardStateEnum? ForwardState { get; set; }
    }

    public class ForWardViewModel
    {
        public Guid Id { get; set; }
        public string BlindName { get; set; } = String.Empty;
        public String TrialSiteCode { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;

        public decimal VisitNum { get; set; }
        public string VisitName { get; set; } = string.Empty;

        public Guid? ForwardUserId { get; set; }

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

        public DateTime? ForwardTime { get; set; }

        public ForwardStateEnum ForwardState { get; set; }

        public CheckStateEnum CheckState { get; set; }


    }

    public class QCCheckViewModel
    {
        public string? TalkContent { get; set; } = String.Empty;
        public string BlindName { get; set; } = String.Empty;
        public bool IsUrgent { get; set; }

        public DateTime? CheckPassedTime { get; set; }
        public Guid Id { get; set; }

        public Guid? CheckChallengeLatestUserId { get; set; }

        public AuditStateEnum AuditState { get; set; }

        public CheckStateEnum CheckState { get; set; }
        public String TrialSiteCode { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;

        public decimal VisitNum { get; set; }
        public string VisitName { get; set; } = string.Empty;

        public Guid SubjectId { get; set; }
        public Guid SiteId { get; set; }

        //public string Modality { get; set; }

        public RequestBackStateEnum RequestBackState { get; set; }

        public DateTime? StudyTime { get; set; }
        public DateTime? CheckTime { get; set; }
        public CheckChanllengeTypeEnum CheckChallengeState { get; set; }

        public bool? IsCheckBack { get; set; }

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

    public class QCVisitViewModel : QCVisitBasicListViewModel
    {
        public int? DicomStudyCount { get; set; }
        public int? NoneDicomStudyCount { get; set; }
        public bool IsHaveClinicalData { get; set; }

        public SubjectStatus SubjectStatus { get; set; }
        public int? StudyCount { get; set; }

        public string SubjectCode { get; set; } = String.Empty;
        public String TrialSiteCode { get; set; } = String.Empty;



        public int? ChallengeCount { get; set; }


        public AuditStateEnum AuditState { get; set; }

        public DateTime? SubmitTime { get; set; }

        public string CurrentActionUserName { get; set; } = String.Empty;
        public string PreliminaryAuditUserName { get; set; } = String.Empty;


        public string ReviewAuditUserName { get; set; } = String.Empty;
        public DateTime? ReviewAuditTime { get; set; }
        public DateTime? PreliminaryAuditTime { get; set; }

        public bool IsEnrollmentConfirm { get; set; } = false;
        public DateTime? SubjectFirstGiveMedicineTime { get; set; }

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

    //public class QCHistoryChallengeViewModel: QCCRCChallengeViewModel
    //{



    //}

    public class QCChallengeViewModel : QCCRCChallengeViewModel
    {


    }



    public class QCVisitBasicListViewModel
    {
        public ChallengeStateEnum ChallengeState { get; set; }
        public bool? IsConfirmedClinicalData { get; set; }
        public bool IsQCConfirmedReupload { get; set; }

        public bool IsFinalVisit { get; set; }
        public string BlindName { get; set; } = String.Empty;
        public bool IsUrgent { get; set; }
        //public bool IsReuploaded { get; set; }
        //public bool NeedReUpload { get; set; }
        public QCChanllengeReuploadEnum ReuploadEnum { get; set; }
        public Guid? Id { get; set; }
        public Guid TrialId { get; set; }
        public Guid SubjectId { get; set; }
        public Guid SiteId { get; set; }
        public bool InPlan { get; set; } = true;
        public int VisitExecuted { get; set; }
        public decimal VisitNum { get; set; }
        public string VisitName { get; set; } = string.Empty;
        public int VisitDay { get; set; }
        public string SVUPDES { get; set; } = string.Empty;
        public DateTime? SVSTDTC { get; set; }
        public DateTime? SVENDTC { get; set; }

        public TrialQCProcess QCProcessEnum { get; set; }
        public DateTime? EarliestScanDate { get; set; }
        public DateTime? LatestScanDate { get; set; }

        public bool IsBaseLine { get; set; } = false;
        public string AnonymousVisitName { get; set; } = string.Empty;
        public int VisitWindowLeft { get; set; }
        public int VisitWindowRight { get; set; }

        public bool IsTake { get; set; }
        public Guid? CurrentActionUserId { get; set; }
        public Guid? PreliminaryAuditUserId { get; set; }
        public DateTime? CurrentActionUserExpireTime { get; set; }

        public SubmitStateEnum SubmitState { get; set; }

        public RequestBackStateEnum RequestBackState { get; set; }

        public bool IsLostVisit { get; set; }

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



}
