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

namespace IRaCIS.Application.Contracts
{ 
    public class SubjectCommand
    {
        public Guid? Id { get; set; }
        public string Code { get; set; } = String.Empty;
      
        public int? Age { get; set; }
        public string Sex { get; set; } = string.Empty;
        public Guid SiteId { get; set; }
        public Guid TrialId { get; set; }
        public string MedicalNo { get; set; } = string.Empty;

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

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

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

        public DateTime? BirthDate { get; set; }
        public DateTime? SignDate { get; set; }

        public bool IsUrgent { get; set; }

        public DateTime? FirstGiveMedicineTime { get; set; }


        //public DateTime? OutEnrollmentTime { get; set; }
        //public DateTime? VisitOverTime { get; set; }
        //public SubjectStatus Status { get; set; }
        //public string Reason { get; set; } = string.Empty;

    }

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

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

        public SubjectStatus Status { get; set; }
        public DateTime? OutEnrollmentTime { get; set; }
        public DateTime? VisitOverTime { get; set; }
        public string Reason { get; set; } = string.Empty;

        public Guid? FinalSubjectVisitId { get; set; }
    }


    public class TrialSubjectConfig
    {
        public string SubjectCodeRule { get; set; } = string.Empty;
        public bool IsNoticeSubjectCodeRule { get; set; } 
        public bool IsHaveFirstGiveMedicineDate { get; set; }
        public bool IsEnrollementQualificationConfirm { get; set; } 
        public bool IsHaveSubjectAge { get; set; }
        public string OutEnrollmentVisitName { get; set; } = string.Empty;
        public bool VisitPlanConfirmed { get; set; }

        public bool IsSubjectSexView { get; set; } = false;
        public bool IsSubjectExpeditedView { get; set; } = false;

        public bool IsPDProgressView { get; set; }

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


    public class SubjectQueryView: SubjectCommand
    {

        public DateTime? OutEnrollmentTime { get; set; }
        public DateTime? VisitOverTime { get; set; }
        public SubjectStatus Status { get; set; }
        public string Reason { get; set; } = string.Empty;


        //public int? StudyCount { get; set; }
        //public int? VisitCount { get; set; }
        //public int? PlanVisitCount { get; set; }


        //public int? InPlanDicomStudyUploadCount { get; set; }
        //public int? OutPlanDicomStudyUploadCount { get; set; }
        //public int? InPlanNoneDicomStudyUploadCount { get; set; }
        //public int? OutPlanNoneDicomStudyUploadCount { get; set; }

        public Guid? FinalSubjectVisitId { get; set; }

        public int? TotalVisitCount => OutPlanVisitCount + InPlanVisitCount;
        public int? TotalVisitSubmmitCount => OutPlanVisitSubmmitCount + InPlanVisitSubmmitCount;

        public int? OutPlanVisitCount { get; set; }
        public int? OutPlanVisitSubmmitCount { get; set; }

        public int? InPlanVisitCount { get; set; }
        public int? InPlanVisitSubmmitCount { get; set; }

        public string? FinalSubjectVisitName { get; set; }


        public int? MissingSubmmitCount { get; set; }

        public int? LostVisitCount { get; set; }

        public DateTime? CreateTime { get; set; }
        public DateTime? UpdateTime { get; set; }
        public string SiteName { get; set; } = string.Empty;
        public string TrialSiteCode { get; set; } = string.Empty;

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

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

        public bool IsMissingImages => MissingSubmmitCount > 0;

        public Guid LatestSubmitSubjectVisitId { get; set; }

       

    }



    public class SubjectQueryParam : PageInput
    {
        [NotDefault]
        public Guid TrialId { get; set; } 
        public string Code { get; set; } = string.Empty;

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

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

        public Guid? SiteId { get; set; }
        public SubjectStatus? Status { get; set; } 
    }


    public class SubjectSelect
    {
        public Guid SubjectId { get; set; }

        public string Name => LastName + " / " + FirstName;
        public string FirstName { get; set; } = string.Empty;
        public string LastName { get; set; } = string.Empty;

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

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

        public int? Age { get; set; }
        public SubjectStatus Status { get; set; }

        public DateTime? FirstGiveMedicineTime { get; set; }

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