using IRaCIS.Core.Infrastructure.Extention;
using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Application.Contracts.Dicom.DTO;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using IRaCIS.Core.Application.Service.Inspection.DTO;

namespace IRaCIS.Core.Application.Contracts
{
    public class SubjectVisitCommand
    {
        public bool IsFinalVisit { get; set; }

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

        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 VisitExecutedEnum 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 bool IsBaseLine { get; set; } = false;
        public int VisitWindowLeft { get; set; }
        public int VisitWindowRight { get; set; }

        public bool IsLostVisit { get; set; }
        public PDStateEnum? PDState { get; set; }

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



        public Guid? OutPlanPreviousVisitId { get; set; }




    }


    public class IDDto
    {
        public Guid Id { get; set; }

    }

    public class DeleteSVCommand
    {
        public Guid SubjectVisitId { get; set; }
    }

    public class SetSubjectVisitUrgentCommand
    {
       public Guid SubjectVisitId { get; set; }


       public bool isUrgent { get; set; }
    }
    public class SubjectVisitDTO : SubjectVisitCommand
    {
        public SubjectStatus SubjectStatus { get; set; }

    }

    public class SubjectVisitNewDTO : SubjectVisitDTO
    {
        public TrialQCProcess QCProcessEnum { get; set; }
        public CheckStateEnum CheckState { get; set; }
        public SubmitStateEnum SubmitState { get; set; }
        public AuditStateEnum AuditState { get; set; }

        public string CurrentActionUser { get; set; } = String.Empty;
        public DateTime? CurrentActionUserExpireTime { get; set; }
        public string PreliminaryAuitUser { get; set; } = String.Empty;
        public string ReviewAuitUser { get; set; } = String.Empty;
        public DateTime? ReviewAuitTime { get; set; }
        public DateTime? PreliminaryAuditTime { get; set; }


        public int? StudyCount { get; set; }

        public String TrialSiteCode { get; set; } = String.Empty;
        public DateTime UpdateTime { get; set; }

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

        public int SubjectAge { get; set; }

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


        [JsonIgnore]
        public string SubjectName => LastName + " / " + FirstName;
        public string FirstName { get; set; } = string.Empty;
        public string LastName { get; set; } = string.Empty;

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

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




    }

    public class UploadVisitCheckExcelDto
    {
     
        public Guid trialId { get; set; }

        public string AuditInfo { get; set; }
    }
    public class ForwardSVDicomImageDto
    {
        public Guid[] subjectVisitIdList { get; set; }
    }
    public class SubjectVisitSearchDTO : PageInput
    {
        public string SubjectInfo { get; set; } = String.Empty;

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

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

    public class SubjectVisitSelectItem
    {
        public Guid Id { get; set; } 
        public decimal VisitNum { get; set; }
        public string VisitName { get; set; } = String.Empty;

        public int VisitExecuted { get; set; }

        public bool IsUploadedImage { get; set; }
    }

    public class SubjectVisitSelectDTO
    {
        public Guid GuidId { get; set; } = Guid.NewGuid();
        public Guid SubjectVisitId { get; set; } = Guid.Empty;
        public decimal VisitNum { get; set; }
        public string VisitName { get; set; } = string.Empty;

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

        public int? VisitDay { get; set; }

        //public Guid VisitStageId { get; set; } = Guid.Empty;

        public DateTime? SVSTDTC { get; set; }

        public DateTime? SVENDTC { get; set; }


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

        public VisitExecutedEnum VisitExecuted { get; set; }



        public List<SubjectVisitStudyDTO> StudyList = new List<SubjectVisitStudyDTO>();
    }


    public class SubjectVisitStudyDTO
    {
        public Guid SubjectVisitId { get; set; }
        public Guid StudyId { get; set; }
        public string StudyCode { get; set; } = String.Empty;

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

        public int Status { get; set; }

    }

    public class GetReadingVisitStudyListIndto
    {
      public  Guid TrialId { get; set; }
     public  Guid SujectVisitId { get; set; }
        public Guid? VisitTaskId { get; set; }
    }


    public class TempInstance
    {
        public Guid Id { get; set; }
        public string Path { get; set; }
        public int NumberOfFrames { get; set; }
        public int InstanceNumber { get; set; }

        public int ShowOrder { get; set; }

        public decimal RowIndex { get; set; }

    }

    public class VisitStudyDTO
    {
        public Guid StudyId { get; set; }
        public string StudyCode { get; set; } = String.Empty;
        public string Modalities { get; set; } = String.Empty;

        public bool IsCriticalSequence { get; set; } = false;

        public int SeriesCount { get; set; }
        public int InstanceCount { get; set; }

        public bool IsDicom { get; set; } = true;

        public List<DicomSeriesDTO> SeriesList { get; set; } = new List<DicomSeriesDTO>();
    }

    public class PreArchiveStudyCommand
    {
        public Guid SubjectVisitId { get; set; }

        public bool IsDicom { get; set; }


    }

    public class ArchiveStudyCommand
    {
        //[NotDefault]
        //public Guid StudyMonitorId { get; set; }
        public Guid? AbandonStudyId { get; set; }

     
        public Guid SubjectVisitId { get; set; }

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



        //public Guid TrialId { get; set; }
        //public Guid SiteId { get; set; }
        //public Guid SubjectId { get; set; }
        //public DateTime? SVSTDTC { get; set; }
        //public DateTime? SVENDTC { get; set; }

        //public string  DTFPath { get; set; }
        //public string FileRealName { get; set; }

    }


    public class UploadDTFCommand
    {
        public Guid TrialId { get; set; }
        public Guid SiteId { get; set; }
        public Guid SubjectId { get; set; }
        public Guid SubjectVisitId { get; set; }

    }


    public class StudyCommand
    {
        public Guid Id { get; set; } = Guid.Empty;
        public Guid TrialId { get; set; }
        public Guid SiteId { get; set; }
        public Guid SubjectId { get; set; }
        public Guid SubjectVisitId { get; set; }

    }

    public class StudyEditCommand : StudyCommand
    {
        public Guid VisitStageId { get; set; }
        public DateTime? SVSTDTC { get; set; }
        public DateTime? SVENDTC { get; set; }
        public string Comment { get; set; } = String.Empty;
    }



    public class StudyStatDTO
    {

        public int StudyCount { get; set; }
        public decimal VisitNum { get; set; }
        public string VisitName { get; set; } = String.Empty;
        public int VisitDay { get; set; }
        public string Description { get; set; } = String.Empty;
        public Guid TrialId { get; set; }
        public Guid SubjectVisitId { get; set; }

    }

    public class DistributeReviewerStudyStatusDTO
    {
        public string NameCN { get; set; } = String.Empty;
        public string Name { get; set; } = String.Empty;
        public string ReviewerCode { get; set; } = String.Empty;
        public string StudyCode { get; set; } = String.Empty;

        public int Status { get; set; }

    }

    public class StudyStatusQueryDTO : PageInput
    {
        public Guid TrialId { get; set; }
        public Guid? ReviewerId { get; set; }

        public int? StudyStatus { get; set; }
    }




    public class VerifyStudyUploadResult
    {
        public string StudyInstanceUid { get; set; } = String.Empty;

        public VerifyStudyDto? StudyInfo { get; set; }

        public bool AllowUpload { get; set; } = false;

        public bool AllowReUpload { get; set; } = false;

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

    }

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

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

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


        public decimal VisitNum { get; set; }

        public List<VerifyUploadStudyBasicInfo> StudyInstanceUidList { get; set; } = new List<VerifyUploadStudyBasicInfo>();
    }

    public class VerifyUploadStudyBasicInfo
    {
        public string StudyInstanceUid { get; set; } = String.Empty;

        public DateTime? StudyDate { get; set; }  
    }


    public class VerifyStudyDto
    {

        public Guid Id { get; set; }
        public string StudyCode { get; set; } = String.Empty;

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

        public string SubjectCode { get; set; } = String.Empty;
        public string VisitName { get; set; } = String.Empty;
        public string SubjectName => LastName + " / " + FirstName;
        public string FirstName { get; set; } = string.Empty;
        public string LastName { get; set; } = string.Empty;

        public DateTime? StudyTime { get; set; }
    }

    public class StudyDTO
    {
        public Guid SubjectVisitId { 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 Guid Id { get; set; }
        public Guid TrialId { get; set; }
        public string StudyCode { get; set; } = String.Empty;


        public int StudyStatus { get; set; }
        public DateTime? StudyDate { get; set; }
        public string Modalities { get; set; } = String.Empty;
        public int SeriesCount { get; set; }
        public int InstanceCount { get; set; }

        public bool IsDoubleReview { get; set; }

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

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

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

        public DateTime UpdateTime { get; set; }

        public DateTime? UploadedTime { get; set; }

        public DateTime? DeadlineTime { get; set; }

        //public List<DistributeReviewer> DistributeReviewers { get; set; }=new List<DistributeReviewer>();


        public Guid SiteId { get; set; }
        public string SiteName { get; set; } = String.Empty;
        public string InstitutionName { get; set; } = String.Empty;
        public string StudyId { get; set; } = String.Empty;//这个Id是dicom文件中的Id
        public Guid SubjectId { get; set; }
        public string SubjectCode { get; set; } = String.Empty;

        public string SubjectName => LastName + " / " + FirstName;
        public string FirstName { get; set; } = string.Empty;
        public string LastName { get; set; } = string.Empty;
        public int? SubjectAge { get; set; }

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

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

        public string PatientId { get; set; } = String.Empty;
        public string PatientName { get; set; } = String.Empty;
        public string PatientAge { get; set; } = String.Empty;
        public string PatientSex { get; set; } = String.Empty;
        public string AccessionNumber { get; set; } = string.Empty;
        public string PatientBirthDate { get; set; } = string.Empty;


        //public int? NeedDealMessageCount { get; set; }
        //public int? TotalMessageCount { get; set; }
        public int? DTFCount { get; set; }


        public string UploaderFirstName { get; set; } = String.Empty;
        public string UploaderLastName { get; set; } = String.Empty;
    }

    public class DistributeReviewer
    {
        public Guid StudyId { get; set; }

        public Guid ReviewerId { get; set; }
        public string NameCN { get; set; } = String.Empty;
        public string Name { get; set; } = String.Empty;

        public int Status { get; set; }
    }

    public class StudyQueryDTO : PageInput
    {
        public Guid? SubjectId { get; set; }

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

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

        public Guid? SubjectVisitId { get; set; }
       

        public DateTime? StudyTimeBegin { get; set; }

        public DateTime? StudyTimeEnd { get; set; }

        public DateTime? UpdateTimeBegin { get; set; }

        public DateTime? UpdateTimeEnd { get; set; }
    }
}
