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

namespace IRaCIS.Application.Contracts
{


    public class TrialBaseModel
    {
        public int? PlanSiteCount { get; set; }
        public int? PlanVisitCount { get; set; }
        public TrialType TrialType { get; set; }
        public Guid? Id { get; set; }
        public string TrialCode { get; set; } = string.Empty;
        public string Indication { get; set; } = string.Empty;

        public int IndicationEnum { get; set; }

        //public Guid? ReviewTypeId { get; set; } = Guid.Empty;

        //public Guid? CriterionId { get; set; } = Guid.Empty;
        public Guid? CROId { get; set; } = Guid.Empty;
        public Guid? SponsorId { get; set; } = Guid.Empty;
        public Guid? ReviewModeId { get; set; } = Guid.Empty;
        public string Note { get; set; } = string.Empty;
        public string ProjectCycle { get; set; } = string.Empty;
        public int ExpectedPatients { get; set; }
        public decimal TimePointsPerPatient { get; set; }
        public int? GRRReviewers { get; set; } 
        public int TotalReviewers { get; set; }
        public int? Expedited { get; set; }


        //研究方案号
        public string ResearchProgramNo { get; set; } = string.Empty;

        //实验名称
        public string ExperimentName { get; set; } = string.Empty;

        //主研单位
        public string MainResearchUnit { get; set; } = string.Empty;

        // 负责人PI
        public string HeadPI { get; set; } = string.Empty;

        //public Guid DeclarationTypeId { get; set; }
        //public int? AttendedReviewerType { get; set; }

        public Guid IndicationTypeId { get; set; }
        public Guid? PhaseId { get; set; }


        public List<DeclarationType> DeclarationTypeEnumList { get; set; }

        public List<AttendedReviewerType> AttendedReviewerTypeEnumList { get; set; }
        public string DeclarationTypes { get; set; }=string.Empty;
        public string AttendedReviewerTypes { get; set; } = string.Empty;

        public bool IsDeclaration { get; set; }

    }


    public class QuestionTypeDto 
    {
        public Guid DictionaryId { get; set; }

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

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

        public bool IsSelect { get; set; }
    }

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

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

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

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

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

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


    }

    public class TrialModalitySelectDto
    {
        public Guid ModalityId { get; set; }
        public string Modality { get; set; } = string.Empty;
    }

    public class TrialDetailDTO : TrialBaseModel
    {

        [JsonIgnore]
        public List<DicView> DictionaryList { get; set; } = new List<DicView>();
  
        public List<string> ModalityList => DictionaryList.Where(t => t.ParentCode == StaticData.Modality).OrderBy(t => t.ShowOrder).Select(t => t.Value).ToList();
        public List<Guid> ModalityIds => DictionaryList.Where(t => t.ParentCode == StaticData.Modality).OrderBy(t => t.ShowOrder).Select(t => t.Id).ToList();

        public List<string> CriterionList { get; set; }


        public string Modalitys { get; set; }


        //public List<Guid> CriterionIds => DictionaryList.Where(t => t.ParentCode == StaticData.ReadingStandard).OrderBy(t => t.ShowOrder).Select(t => t.Id).ToList();

        public List<Guid> ReviewTypeIds => DictionaryList.Where(t => t.ParentCode == StaticData.ReviewType).OrderBy(t => t.ShowOrder).Select(t => t.Id).ToList();

        public List<string> ReviewTypeList  => DictionaryList.Where(t => t.ParentCode == StaticData.ReviewType).OrderBy(t => t.ShowOrder).Select(t => t.Value).ToList();

        //public string ReviewType { get; set; } = string.Empty;



        //统计字段
        public string Phase { get; set; } = string.Empty;



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


        public int EnrollStatus { get; set; }


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


        public int ReadingType { get; set; } 


        public string CRO { get; set; } = string.Empty;
        public string Sponsor { get; set; } = string.Empty;
        public int TrialEnrollStatus { get; set; }
        public string TrialStatusStr { get; set; } = string.Empty;

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

        public bool IsLocked { get; set; }


        //public string DeclarationType { get; set; } = string.Empty;
        //public int? SubjectCount { get; set; }

        //public int? StudyCount { get; set; } = 0;
        //public int? SiteCount { get; set; } = 0;


    }

    public class TrialAndTrialStateVieModel
    {
        public TrialDetailDTO TrialView { get; set; } = new TrialDetailDTO();

        public int TrialMaxState { get; set; }

        
    }



    public class TrialCommand : TrialBaseModel
    {

        public List<Guid> ModalityIds { get; set; } = new List<Guid>();

        public List<Guid> CriterionIds { get; set; } = new List<Guid>();

        public List<Guid> ReviewTypeIds { get; set; } = new List<Guid>();

    }



    public class TrialQueryDTO : PageInput
    {
        //public Guid? DeclarationTypeId { get; set; }

        public List<DeclarationType> DeclarationTypeEnumList { get; set; }=new List<DeclarationType>();

        public List<AttendedReviewerType> AttendedReviewerTypeEnumList { get; set; } = new List<AttendedReviewerType>();

        public Guid? IndicationTypeId { get; set; }
        public Guid? SponsorId { get; set; }
        public Guid? CROId { get; set; }

       

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

        public string ExperimentName { get; set; } = String.Empty;
        public List<Guid> ModalityIds { get; set; }=new List<Guid>();
        public List<Guid> CriterionIds { get; set; } = new List<Guid>();

        public List<Guid> ReviewTypeIds { get; set; } = new List<Guid>();
        //public Guid? ReviewTypeId { get; set; }

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

        public string Indication { get; set; } = String.Empty;
        public Guid? PhaseId { get; set; }
        public string TrialStatusStr { get; set; } = String.Empty;

        public DateTime? BeginDate { get; set; }
        public DateTime? EndDate { get; set; }
        public int? Expedited { get; set; }
        //public AttendedReviewerType? AttendedReviewerType { get; set; } 
    }

    public class ReviewerTrialQueryDTO : PageInput
    {
        public string Code { get; set; } = string.Empty;
        public string Indication { get; set; } = string.Empty;
        public EnrollStatus? EnrollStatus { get; set; }
        public int? Expedited { get; set; }
    }


    public class TrialByStatusQueryDTO : PageInput
    {
        public Guid DoctorId { get; set; }
        public int Status { get; set; }
    }







}