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

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 class TrialToBeDoneDto : TrialBaseInfoDto
    {

        public Guid Id => TrialId;

        public DateTime? CreateTime { get; set; }

        public string Sponsor { get; set; }

        public string TrialStatusStr { get; set; }


        public int? ExpetiedTaskCount { get; set; }


        public int? ReReadingApprovalCount { get; set; }


        public int? PendingReconciliationCount { get; set; }

        public int? PendingResponseCount { get; set; }

        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 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;
    }
}