using Castle.Core.Internal;
using IRaCIS.Application.Contracts;
using IRaCIS.Core.Application.Contracts;
using IRaCIS.Core.Application.Contracts.DTO;
using IRaCIS.Core.Domain.Share;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IRaCIS.Core.Application.Service.Inspection.DTO
{




    public class DataInspectionAddDTO
    {

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

        /// <summary>
        /// 子类
        /// </summary>
        public Guid? ChildrenType { get; set; }
        /// <summary>
        /// 对象名称
        /// </summary>
        public Guid? ObjectType { get; set; }
        /// <summary>
        /// 操作类型
        /// </summary>
        public Guid? OptType { get; set; }
        /// <summary>
        /// 功能模块
        /// </summary>
        public Guid? ModuleType { get; set; }

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


        public bool IsSign { get; set; }
        public string JsonDetail { get; set; } = string.Empty;

        /// <summary>
        /// 创建人名称
        /// </summary>
        public string CreateUserName { get; set; } = string.Empty;

        /// <summary>
        /// 项目名称
        /// </summary>
        public string TrialName { get; set; } = string.Empty;

        /// <summary>
        /// 中心名称
        /// </summary>
        public string SiteName { get; set; } = string.Empty;

        /// <summary>
        /// 患者Code
        /// </summary>
        public string SubjectCode { get; set; } = string.Empty;

        /// <summary>
        /// 检查批次名称
        /// </summary>
        public string SubjectVisitName { get; set; } = string.Empty;

        /// <summary>
        /// 角色名称
        /// </summary>
        public string RoleName { get; set; } = string.Empty;


        /// <summary>
		/// 中心Code
		/// </summary>
		public string SiteCode { get; set; } = string.Empty;

        /// <summary>
        /// 项目编码
        /// </summary>
        public string ResearchProgramNo { get; set; } = string.Empty;

        public List<EnumList> EnumList { get; set; } = new List<EnumList> { };


        /// <summary>
        /// 标识
        /// </summary>
        public string Identification { get; set; } = string.Empty;

        /// <summary>
        /// 检查批次计划ID
        /// </summary>
        public Guid? VisitStageId { get; set; }


        /// <summary>
        /// 通用ID
        /// </summary>
        public Guid? GeneralId { get; set; }



        ////需要单独处理
        //public string IP { get; set; }

        public DateTime? CreateTime { get; set; } = DateTime.Now;

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




    }


    public class EnumList
    {
        public string Key { get; set; } = string.Empty;

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

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

    public interface IInspectionDTO
    {
        public DataInspectionAddDTO AuditInfo { get; set; }
    }

    public interface ISignDTO
    {
        public SignDTO SignInfo { get; set; }

    }

    #region Setting
    /// <summary>
    /// 配置 基础逻辑信息
    /// </summary>
    public class InsBasicTrialConfig : InspectionBase, IInspectionDTO, ISignDTO
    {
        public BasicTrialConfig OptCommand { get; set; }
    }

    /// <summary>
    /// 配置流程
    /// </summary>
    public class InsTrialProcessConfig : InspectionBase, IInspectionDTO, ISignDTO
    {
        public TrialProcessConfig OptCommand { get; set; }
    }

    /// <summary>
    /// 配置加急信息
    /// </summary>
    public class InsTrialUrgentConfig : InspectionBase, IInspectionDTO, ISignDTO
    {
        public TrialUrgentConfig OptCommand { get; set; }
    }
    #endregion

    public class SetCheckPassDto
    {
        public Guid qcChallengeId { get; set; }
        public Guid subjectVisitId { get; set; }
        public QCChallengeCloseEnum closeEnum { get; set; }
        public string closeReason { get; set; }
    }


    public class SetNeedReuploadDto
    {
       public Guid trialId { get; set; }
       public Guid qcChallengeId { get; set; }
    }

    public class SetVisitUrgentDto
    {
        public Guid trialId { get; set; }
        public Guid subjectVisitId { get; set; }
        public bool setOrCancel { get; set; }
    }


    public class UpdateTrialStateDto
    {
        public Guid trialId  {get; set; }
        public string trialStatusStr { get; set; }

        public string? reason { get; set; }
    }
    public class QCPassedOrFailedDto
    {
        public Guid trialId { get; set; }
        public Guid subjectVisitId { get; set; }
       
        public AuditStateEnum auditState { get; set; }
    }

    public class SetSeriesStateDto
    {
        public Guid subjectVisitId { get; set; }
        public Guid studyId { get; set; }
        public Guid seriesId { get; set; }
        public int state { get; set; }
    }

    public class UpdateModalityDto
    {
        public Guid id { get; set; }
        public int type { get; set; }
        public string modality { get; set; }
        public string bodyPart { get; set; }
    }

    public class CloseQCChallengeDto
    {
        public Guid qcChallengeId { get; set; }
        public Guid subjectVisitId { get; set; }
        public QCChallengeCloseEnum closeEnum { get; set; }
        public string closeReason { get; set; }
    }

    public class AddOrUpdateQCChallengeDto
    {
        public QCChallengeCommand qaQuestionCommand { get; set; }
        public Guid trialId { get; set; }
        public TrialQCProcess trialQCProcess { get; set; }
        public CurrentQC currentQCType { get; set; }
    }

    public class AddOrUpdateQCQuestionAnswerListDto
    {
        public QCQuestionAnswerCommand[] qcQuestionAnswerCommands { get; set; }
        public Guid trialId { get; set; }
        public Guid subjectVisitId { get; set; }
        public TrialQCProcess trialQCProcess { get; set; }
        public CurrentQC currentQCType { get; set; }

    }

      public class SetCheckPassDt
    {
        public string ManualPassReason { get; set; } = string.Empty;

        public Guid Id { get; set; }
    }


    public class ObtainOrCancelQCTaskDto
    {
       public Guid trialId { get; set; }
        public Guid subjectVisitId { get; set; }
        public bool obtaionOrCancel { get; set; }
    }

    public class ReadingClinicalDataSignIndto
    {
        /// <summary>
        /// 阅片临床数据ID
        /// </summary>
       public Guid  ReadingClinicalDataId { get; set; }

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

    /// <summary>
    /// 稽查泛型Dto
    /// </summary>
    /// <typeparam name="T">泛型</typeparam>
    public class DataInspectionDto<T> 
    {


        public T Data { get; set; }

       
        public SignDTO SignInfo { get; set; }

      
    }

    #region Qc
    public class DeleteStudyList
    {
        public Guid[] ids { get; set; }
        public Guid subjectVisitId { get; set; }
        public Guid trialId { get; set; }
    }
    #endregion

    #region 患者
    public class InsSubjectCommand : InspectionBase, IInspectionDTO, ISignDTO
    {
        public SubjectCommand OptCommand { get; set; }
    }

    public class InsUpdateSubjectStatus : InspectionBase, IInspectionDTO, ISignDTO
    {
        public SubjectStatusChangeCommand OptCommand { get; set; }
    }


    public class InsDeleteSubjectDto : InspectionBase, IInspectionDTO, ISignDTO
    {
        public DeleteSubjectDto OptCommand { get; set; }
    }


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

        public Guid TrialId { get; set; }

        public Guid SiteId { get; set; }

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

    #endregion

    
      

    /// <summary>
    /// 用户 签名某个文档  Dto
    /// </summary>
    public class TrialDocumentConfirmDTO : InspectionBase, IInspectionDTO, ISignDTO
    {       
        public UserConfirmCommand OptCommand { get; set; }

    }

    public class GetDataInspectionOutDto : DataInspection
    {
        public Guid? TrialReadingCriterionId { get; set; }
        public string TrialReadingCriterionName { get; set; }
        public string BlindName { get; set; }

        public string TaskName { get; set; }

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

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

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

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


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

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

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


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

        public decimal? VisitNum { get; set; }

        public bool? InPlan { get; set; }

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

        public Guid? FrontAuditConfigId { get; set; }


        /// <summary>
        /// 父标识
        /// </summary>
        public string ParentIdentification { get; set; }


        public string ExperimentName { get; set; }


        public string SiteCode { get; set; }

        public string ResearchProgramNo { get; set; }


        public string SiteName { get; set; }


        public string SubjectCode { get; set; }


        public string SubjectVisitName { get; set; }



    }

    public class UpdateTrialState
    {
       public Guid trialId { get; set; }
       public string  trialStatusStr { get; set; }
       public string reason { get; set; }
    }

    public class AbandonTrial
    {
       public Guid trialId { get; set; }
       public bool isAbandon { get; set; }
    }


    public class GetDataInspectionDto : PageInput
    {
       

        /// <summary>
        /// 项目iD
        /// </summary>
        public Guid? TrialId { get; set; }

        /// <summary>
        /// 中心
        /// </summary>
        public Guid? SiteId { get; set; }

        /// <summary>
        /// 患者
        /// </summary>
        public string  SubjectInfo { get; set; } = string.Empty;

        /// <summary>
        /// 
        /// </summary>
        public decimal? VisitPlanInfo { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime? StartTime { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime? EndTime { get; set; }



        /// <summary>
        /// 功能模块
        /// </summary>
        public Guid? ModuleType { get; set; }

        /// <summary>
        /// Description
        /// </summary>
        public string Description { get; set; } = string.Empty;

        /// <summary>
        /// 操作人名称模糊查询
        /// </summary>
        public string OpByUserName { get; set; } = string.Empty;

        /// <summary>
        /// 阅读片人
        /// </summary>
        public string ReaderUser { get; set; } = string.Empty;

        /// <summary>
        /// 是否有签名
        /// </summary>
        public bool? IsSign { get; set; }

        /// <summary>
        /// 批次Id
        /// </summary>
        public Guid? BatchId { get; set; }

        public Guid? GeneralId { get; set; }

        public DateTime? RelationDeadlineTime { get; set; }

        public Guid? ObjectRelationParentId { get; set; }

        public Guid? TrialReadingCriterionId { get; set; }


    }

    public class InspectionBase
    {
        public DataInspectionAddDTO AuditInfo { get; set; }

        public SignDTO SignInfo { get; set; } = new SignDTO();
    }
}
