using IRaCIS.Application.Contracts;
using IRaCIS.Core.Application.Helper;
using IRaCIS.Core.Domain.Share;
using System.ComponentModel.DataAnnotations;

namespace IRaCIS.Core.Application.Contracts
{

    public class PersonalStataDTO
    {
        // 项目数量(排除 废除的)
        public int? TrialCount { get; set; }

        //废除的
        public int? DeletedCount { get; set; }

        //项目数量  （包括废除的）
        public int? TotalTrialCount => TrialCount + DeletedCount;


        //总共需要签署项目文档的数量 （排除掉废除的 +  废除的但是签署了）
        public int? TotalNeedSignTrialDocCount { get; set; }


        //已签署的项目文档总数
        public int? HaveSignedTrialDocCount { get; set; }

        //现在需要签署的项目文档总数
        public int? WaitSignTrialDocCount => TotalNeedSignTrialDocCount - HaveSignedTrialDocCount;




        public int? TotalNeedSignSystemDocCount { get; set; }

        public int? HaveSignedSystemDocCount { get; set; }

        public int? WaitSignSystemDocCount => TotalNeedSignSystemDocCount - HaveSignedSystemDocCount;



        //现在需要签署的总数（项目待签署 +系统待签署）
        public int? TotalNeedSignDocCount => TotalNeedSignTrialDocCount + TotalNeedSignSystemDocCount;


        public int? TotalApprovalRequiredCount { get; set; }


        public int? TotalSystemNoticeCount { get; set; }

        public int? NeedReadSystemNoticeCount { get; set; }

    }

    public class TrialSiteSurveyStatQuery : PageInput
    {

    }

    public class TrialSiteSurveyStat : TrialSelectDTO
    {
        public int? ApprovalRequiredCount { get; set; }



        public int? ApprovalRequiredSiteCount { get; set; }
    }


    public class DocSignStat : TrialSelectDTO
    {

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

        public int? WaitSignCount { get; set; }
    }


    public class CheckToBeDoneQuery : PageInput
    {

    }

    public class CheckToBeDoneDto : TrialBaseInfoDto
    {
        public int? UrgentCount { get; set; }

        public int? ToBeCheckedCount { get; set; }

        public int? ToBeRepliedCount { get; set; }
    }


    public class ReReadingApplyToBeDoneQuery : PageInput
    {

    }

    public class ReReadingApplyToBeDoneDto : TrialBaseInfoDto
    {
        public int? UrgentCount { get; set; }



        public int? ToBeApprovalCount { get; set; }
    }

    public class GetPMClinicalDataToBeDoneListOutDto : TrialBaseInfoDto
    {
        public int? ToBeApprovalCount { get; set; }
    }

    public class ReviewerSelectToBeDoneQuery : PageInput
    {
    }

    public class ReviewerSelectToBeDoneDto : TrialBaseInfoDto
    {
        public bool IsUrgent { get; set; }

        public int? ToBeApprovalCount { get; set; }
    }


    public class ReReadingApprovalToBeDoneQuery : PageInput
    {

    }

    public class ReReadingApprovalToBeDoneDto : TrialBaseInfoDto
    {
        public int? UrgentCount { get; set; }

        public int? ToBeApprovalCount { get; set; }
    }

    public class ImageQuestionToBeDoneQuery : PageInput
    {

    }

    public class ImageQuestionToBeDoneDto : TrialBaseInfoDto
    {
        public int? UrgentCount { get; set; }

        public int? ToBeDealedCount { get; set; }
    }

    public class IRImageReadingToBeDoneQuery : PageInput
    {

    }

    public class IRImageReadingToBeDoneDto : TrialBaseInfoDto
    {
        public Guid TrialReadingCriterionId { get; set; }
        public string CriterionName { get; set; }


        public int? UrgentCount { get; set; }

        public int? UnReadCount { get; set; }

        public int? HaveSignedCount { get; set; }
    }





    public class MedicalCommentsToBeDoneQuery : PageInput
    {

    }

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

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

    public class MedicalCommentsToBeDoneDto : TrialBaseInfoDto
    {
        public Guid TrialReadingCriterionId { get; set; }
        public string CriterionName { get; set; }
        public int? UrgentCount { get; set; }

        public int? ToBeReplyedCount { get; set; }

        public int? ToBeReviewedCount { get; set; }
    }

    public class ImageCheckQuestionToBeDoneQuery : PageInput
    {

    }

    public class ImageCheckQuestionToBeDoneDto : TrialBaseInfoDto
    {
        public int? UrgentCount { get; set; }

        public int? ToBeReplyedCount { get; set; }
    }

    public class ImageSubmittedToBeDoneQuery : PageInput
    {

    }

    public class ImageSubmittedToBeDoneDto : TrialBaseInfoDto
    {
        public int? UrgentCount { get; set; }

        public int? ToBeDealedCount { get; set; }
    }

    public class ImageQualityToBeDoneQuery : PageInput
    {

    }

    public class ImageQualityToBeDoneDto : TrialBaseInfoDto
    {
        public int? UrgentCount { get; set; }

        public int? ToBeReviewedCount { get; set; }

        public int? ToBeClaimedCount { get; set; }
    }




    public class ImageReUploadToBeDoneQuery : PageInput
    {

    }

    public class ImageReUploadToBeDoneDto : TrialBaseInfoDto
    {
        public int? UrgentCount { get; set; }

        public int? ToBeReUploadCount { get; set; }
    }

    public class ImageClinicalDataToBeDoneQuery : PageInput
    {

    }

    public class ImageClinicalDataToBeDoneDto : TrialBaseInfoDto
    {
        public int? UrgentCount { get; set; }

        public int? ToBeDealedCount { get; set; }

        public int? ToAllCount { get; set; }

        public int? ToBeVisitCount { get; set; }

        public int? ReadModuleCount { get; set; }
    }

    public class TrialToBeDoneQuery : PageInput
    {
        public string ExperimentName { get; set; } = string.Empty;

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

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

        public Guid? SponsorId { get; set; }

        public CriterionType? CriterionType { get; set; }

        public string? PM_EMail { get; set; }

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

    public class TrialToBeDoneDto : TrialBaseInfoDto
    {

        public Guid Id => TrialId;

        public DateTime? CreateTime { get; set; }

        public string Sponsor { get; set; }

        [DictionaryTranslateAttribute("TrialStatusEnum")]
        public string TrialStatusStr { get; set; }

        #region PM
        public int? ExpetiedTaskCount { get; set; }


        public int? ReReadingApprovalCount { get; set; }


        public int? PendingReconciliationCount { get; set; }

        public int? PendingResponseCount { get; set; }


        #endregion

        #region SPM


        public int? SPM_ReReadingApprovalCount { get; set; }

        public int? SPM_ReviewerSelectApprovalCount { get; set; }

        #endregion


        #region MIM

        public int? MIM_UrgentCount { get; set; }

        public int? MIM_PendingReviewCount { get; set; }

        public int? MIM_PendingResponseCount { get; set; }

        #endregion

        #region CRC

        public int? CRC_UrgentCount { get; set; }

        public int? CRC_QCQuestionCount { get; set; }

        public int? CRC_CheckQuestionCount { get; set; }
        #endregion

        #region IQC
        public int? IQC_UrgentCount { get; set; }

        public int? IQC_ToBeClaimedCount { get; set; }

        public int? IQC_AuditToBeDealedCount { get; set; }

        public int? IQC_QuestionToBeDealedCount { get; set; }

        #endregion

        #region IR

        public List<string>? IR_ReadingCriterionList { get; set; }

        public List<string>? IR_PMEmailList { get; set; }

        public int? IR_TotalReadCount { get; set; }

        public int? IR_UnReadCount { get; set; }

        public int? IR_UrgentCount { get; set; }


        #endregion


        //public bool IsIQCHaveToBeDone { get; set; }
        //public bool IsCRCHaveToBeDone { get; set; }

        //public bool IsMIMHaveToBeDone { get; set; }


        //public bool IsIRHaveToBeDone { get; set; }

        //public bool IsSPMOrCPMHaveToBeDone { get; set; }

    }

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

    }

    public class UserToBeDoneRecord
    {
        public int? TrialWaitSignDocCount { get; set; }

        public int? SysWaitSignDocCount { get; set; }

        public int? TrialSignedDocCount { get; set; }
        public int? SysSignedDocCount { get; set; }

        public int? SysNoticeUnReadCount { get; set; }

        #region PM/APM
        public int? PM_SiteSurveryCount { get; set; }
        public int? PM_CheckCount { get; set; }
        public int? PM_ReviewerSelectCount { get; set; }

        public int? PM_ReReadingApprovalCount { get; set; }

        public int? PM_ClinicalDataCount { get; set; }

        #endregion

        #region CRC

        public int? CRC_ImageSubmitCount { get; set; }
        public int? CRC_ImageQuestionCount { get; set; }
        public int? CRC_CheckQuestionCount { get; set; }

        public int? CRC_ImageReUploadCount { get; set; }

        public int? CRC_ClinicalDataTobeDoneCount { get; set; }
        public int? CRC_ClinialDataTobeConfirmCount { get; set; }


        #endregion


        #region SPM/CPM

        public int? SPM_SiteSurveryCount { get; set; }
        public int? SPM_ReviewerApprovalCount { get; set; }

        public int? SPM_ReReadingApprovalCount { get; set; }


        #endregion


        #region IQC

        public int? IQC_IamgeQCCount { get; set; }
        public int? IQC_QCQuestionCount { get; set; }



        #endregion

        #region IR
        public int? IR_IamgeWaitReadingCount { get; set; }
        public int? IR_MedicalReviewCount { get; set; }

        #endregion

        #region MIM
        public int? MIM_MedicalReviewCount { get; set; }


        #endregion

        public int? TotalCount => TrialWaitSignDocCount + SysWaitSignDocCount
            + PM_SiteSurveryCount + PM_CheckCount + PM_ReviewerSelectCount + PM_ReReadingApprovalCount /*+ PM_ClinicalDataCount*/
            + CRC_ImageSubmitCount + CRC_ImageQuestionCount + CRC_CheckQuestionCount + CRC_ImageReUploadCount /*+ CRC_ClinicalDataTobeDoneCount + CRC_ClinialDataTobeConfirmCount*/
            + SPM_SiteSurveryCount + SPM_ReviewerApprovalCount + SPM_ReReadingApprovalCount
            + IQC_IamgeQCCount + IQC_QCQuestionCount
            + IR_IamgeWaitReadingCount + IR_MedicalReviewCount
            + MIM_MedicalReviewCount;

        public bool IsHaveSysDocNeedNeedSign { get; set; }

        //public List<TrialDocNeedSign> TrialNeedSignList { get; set; }=new List<TrialDocNeedSign>();

    }

    //public class TrialDocNeedSign: TrialBaseInfoDto
    //{
    //    public bool IsHaveTrialDocNeedSign { get; set; }
    //}

    public class TrialUserToBeDoneDto
    {
        public string UserName { get; set; }

        public string FullName { get; set; }

        public UserTypeEnum UserType { get; set; }




        public int? ReviewerSelect_SPM_ToBeApprovalCount { get; set; }
        public int? ReviewerSelect_PM_ToBeConfirmCount { get; set; }

        public int? ImageUpload_CRC_ToBeReUploadCount { get; set; }
        public int? ImageUpload_CRC_ToBeSubmitCount { get; set; }


        public int? QC_IQC_ToBeReviewedCount { get; set; }
        public int? QC_IQC_ToBeClaimedCount { get; set; }

        public int? QC_IQC_ToBeDealedCount { get; set; }

        public int? QC_CRC_ToBeDealedCount { get; set; }


        public int? Check_CRC_ToBeDealedCount { get; set; }

        public int? Check_PM_ToBeDealedCount { get; set; }

        public int? Check_PM_ToBeReplyedCount { get; set; }

        public int? Reading_IR_UnReadCount { get; set; }

        public int? Reading_SPM_ToBeApprovalCount { get; set; }
        public int? Reading_PM_ToBeApprovalCount { get; set; }

        public int? Medical_MIM_ToBeDealedCount { get; set; }

        public int? Medical_MIM_ToBeReviewedCount { get; set; }

        public int? Medical_IR_ToBeDealedCount { get; set; }

        public int UserTotalToBeDoneCount => new[]
        {
            ReviewerSelect_SPM_ToBeApprovalCount ?? 0,
            ReviewerSelect_PM_ToBeConfirmCount ?? 0,
            ImageUpload_CRC_ToBeReUploadCount ?? 0,
            ImageUpload_CRC_ToBeSubmitCount ?? 0,
            QC_IQC_ToBeReviewedCount ?? 0,
            QC_IQC_ToBeClaimedCount ?? 0,
            QC_IQC_ToBeDealedCount ?? 0,
            QC_CRC_ToBeDealedCount ?? 0,
            Check_CRC_ToBeDealedCount ?? 0,
            Check_PM_ToBeDealedCount ?? 0,
            Check_PM_ToBeReplyedCount ?? 0,
            Reading_IR_UnReadCount ?? 0,
            Reading_SPM_ToBeApprovalCount ?? 0,
            Reading_PM_ToBeApprovalCount ?? 0,
            Medical_MIM_ToBeDealedCount ?? 0,
            Medical_IR_ToBeDealedCount ?? 0,
            Medical_MIM_ToBeReviewedCount??0
        }.Sum();

    }

    public class TrialBaseInfoDto
    {
        public Guid TrialId { get; set; }
        public string ExperimentName { get; set; } = string.Empty;

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

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