using IRaCIS.Application.Contracts;
using IRaCIS.Core.Application.MediatR.CommandAndQueries;
using IRaCIS.Core.Domain.Share;
using Newtonsoft.Json;

namespace IRaCIS.Core.Application.Contracts.DTO
{








    public class UpdateModalityCommand
    {
        public Guid Id { get; set; }
        public Guid SubjectVisitId { get; set; }

        public int Type { get; set; }

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

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

    }

    public class QCQuestionAnswerCommand
    {
        public Guid? Id { get; set; }
        public string Answer { get; set; } = String.Empty;

        //public string ChildAnswer { get; set; } = String.Empty;

        public Guid? TrialQCQuestionConfigureId { get; set; }

    }


    public class QCQuestionAnswerItemDto
    {
        //public string ChildAnswer { get; set; } = String.Empty;

        [JsonIgnore]
        public List<QCQuestionAnswerCommand> QCQuestionAnswerList { get; set; } = new List<QCQuestionAnswerCommand>();


        public TrialQCProcess? QCProcessEnum { get; set; }

        // 1代表第一个人QC数据  2 代表第二个人QC数据
        public CurrentQC? CurrentQCEnum { get; set; }

        public Guid? SubjectVisitId { get; set; }

        public Guid? Id { get; set; }
        public string Answer { get; set; } = String.Empty;

        public Guid TrialQCQuestionConfigureId { get; set; }
        public Guid TrialId { get; set; }
        public string QuestionName { get; set; } = String.Empty;
        public bool IsRequired { get; set; }
        public bool IsEnable { get; set; }
        public string Type { get; set; } = String.Empty;
        public Guid? ParentId { get; set; }
        public string TypeValue { get; set; } = String.Empty;
        public string ParentTriggerValue { get; set; } = String.Empty;
        public int ShowOrder { get; set; }

        public int? ParentShowOrder { get; set; }

        public bool IsChild => ParentId != null;
    }


    public class QATrialTemplateItemDto
    {
        public Guid QATrialTemplateId { get; set; }
        public string TemplateItemName { get; set; } = String.Empty;
        public Guid QATrialTemplateItemId { get; set; }
        public int ShowOrder { get; set; }
    }


    public class QARecordItemQuery
    {
        public Guid QaTrialTemplateId { get; set; }
        public Guid? QaRecordId { get; set; }

    }

    public class QATemplateQuery
    {
        public Guid TrialId { get; set; }

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


    public class CloseQCChallengeInDto
    {
        public Guid qcChallengeId { get; set; }

        public Guid trialId { get; set; }

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


    public class QCChallengeCommand
    {
        public Guid? Id { get; set; }

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

        public Guid SubjectVisitId { get; set; }

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

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

        public QCChanllengeReuploadEnum ReuploadEnum { get; set; }


        public DateTime? DeadlineTime { get; set; }

    }


    public class GetUserUploadFileDto/*: UserUploadFile*/
    {
        /// <summary>
		/// 文件名称
		/// </summary>
		public string FileName { get; set; }

        /// <summary>
        /// 文件路径
        /// </summary>
        public string FilePath { get; set; }

        /// <summary>
        /// 相对路径
        /// </summary>
        public string RelativePath { get; set; }


        /// <summary>
        /// 创建人
        /// </summary>
        public Guid CreateUserId { get; set; }


        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }

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

        /// <summary>
        /// 创建者名称
        /// </summary>
        public string CreateUserName { get; set; }
    }


     public class GetUserUploadFileInDto
    {
        public Guid TrialId { get; set; }

        public int PageIndex { get; set; } = 1;
        public int PageSize { set; get; } = 10;
    }


    public class QCChanllengeCreatorDto
    {
        public Guid CreateUserId { get; set; }

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

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

        //public string FirstName { get; set; }
        //public string LastName { get; set; }

    }

    public class ParticipantDTO
    {
        public Guid HandleUserId { get; set; }
        public string HandleUser { get; set; } = String.Empty;

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

    public class QCChallengeWithUser : QCChallengeCommand
    {

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

        public Guid? CurrentActionUserId { get; set; }

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

        public Guid SubjectId { get; set; }
        public UserTypeEnum UserTypeEnum { get; set; }
        public Guid CreateUserId { get; set; }
        public string ChallengeCode { get; set; } = String.Empty;

        public DateTime? LatestMsgTime { get; set; }

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

        public DateTime? ClosedTime { get; set; }

        public bool IsClosed { get; set; }
        public DateTime? ReUploadedTime { get; set; }
        public string CreateUserName { get; set; } = String.Empty;
        public DateTime CreateTime { get; set; }

        public bool IsOverTime => IsClosed ? ClosedTime > DeadlineTime : DateTime.Now > DeadlineTime;

        public string ChallengeDuration
        {
            get
            {
                if (!ClosedTime.HasValue)
                    return "";
                else return string.Format("{0}Days{1}Hours{2}Minutes", (ClosedTime - CreateTime)?.Days, (ClosedTime - CreateTime)?.Hours, (ClosedTime - CreateTime)?.Minutes);
            }
        }



    }

    public class ChallengeAndDialog: QCChallengeWithUser
    {
      
        public List<QCChanllengeDialogDTO> DialogList { get; set; } = new List<QCChanllengeDialogDTO>();
    }





    public class TrialVisitQADTO
    {
        public bool ExistsManual { get; set; }
        public SubjectClinicalDataDto SubjectClinicalData { get; set; } = new SubjectClinicalDataDto();

        public List<NoneDicomStudyView> NoneDicomStudyList { get; set; } = new List<NoneDicomStudyView>();

        public List<QCQuestionAnswerItemDto> QCQuestionAnswerList { get; set; } = new List<QCQuestionAnswerItemDto>();

        public List<QAStudyInfoDTO> StudyList { get; set; } = new List<QAStudyInfoDTO>();

        public List<QASeriesInfoDto> SeriesList { get; set; } = new List<QASeriesInfoDto>();

        public QARelationInfo RelationInfo { get; set; } = new QARelationInfo();

    }


    public class QAStudySeriesInfo
    {
        public List<QAStudyInfoDTO> StudyList { get; set; } = new List<QAStudyInfoDTO>();

        public List<QASeriesInfoDto> SeriesList { get; set; } = new List<QASeriesInfoDto>();
    }


    public class QADictionaryCommand
    {

        public string Note { get; set; } = String.Empty;
        public Guid DictionaryId { get; set; }

    }

    public class QADictionaryDTO : QADictionaryCommand
    {
        public string DictionaryValue { get; set; } = String.Empty;
    }

    public class QADicView
    {
        public Guid QARecordId { get; set; }
        public string DictionaryValue { get; set; } = String.Empty;
        public string Note { get; set; } = String.Empty;
        public Guid DictionaryId { get; set; }
    }





    public class QARelationInfo
    {
        public int TrialClinicalInformationTransmissionEnum { get; set; }
        public int TrialChangeDefalutDays { get; set; }
        public TrialQCProcess TrialQCProcessEnum { get; set; }
        public string TrialChallengeTypes { get; set; } = String.Empty;
        public string TrialBodyPartTypes { get; set; } = String.Empty;
        public string TrialImageQCSignText { get; set; } = String.Empty;
        public string TrialModalitys { get; set; } = String.Empty;

        //public string FirstName { get; set; }
        //public string LastName { get; set; }
        //public string Modalities { get; set; }

        public Guid SiteId { get; set; }
        public string SiteName { get; set; } = String.Empty;
        public Guid SubjectId { get; set; }
        public Guid SubjectVisitId { get; set; }

        public string SubjectCode { get; set; } = String.Empty;
        public string SubjectName { get; set; } = String.Empty;
        public int SubjectAge { get; set; }
        public string SubjectSex { get; set; } = String.Empty;

        public DateTime? EarliestScanDate { get; set; }

        public DateTime? LatestScanDate { get; set; }
        public decimal VisitNum { get; set; }
        public string VisitName { get; set; } = string.Empty;
        //public DateTime? SVSTDTC { get; set; }
        //public DateTime? SVENDTC { get; set; }
        public bool InPlan { get; set; }
        public int? VisitDay { get; set; }
        public bool IsBaseLine { get; set; } = false;
        public string AnonymousVisitName { get; set; } = string.Empty;
        public int? VisitWindowLeft { get; set; }
        public int? VisitWindowRight { get; set; }

        public DateTime? SubjectFirstGiveMedicineTime { get; set; }

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




        public int TotalChallengeCount { get; set; }

        public int NotClosedChallengeCount { get; set; }



    }
    public class QAStudyInfoDTO
    {

        public bool IsDeleted { get; set; }
        public string StudyInstanceUid { get; set; } = string.Empty;

        public Guid TrialId { get; set; }

        public Guid StudyId { get; set; }

        public int StudyStatus { get; set; }

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

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

        public int SeriesCount { get; set; }

        public int InstanceCount { get; set; }

        public string Uploader { get; set; } = string.Empty;
        public DateTime? StudyTime { get; set; }

        public DateTime? UploadedTime { get; set; }
        public string BodyPartExamined { get; set; } = String.Empty;

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

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


    }

    public class QASeriesInfoDto
    {
        public DateTime? StudyTime { get; set; }

        public string StudyCode { get; set; } = string.Empty;
        public Guid Id { get; set; }
        public Guid StudyId { get; set; }

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

        public string SeriesInstanceUid { get; set; } = String.Empty;
        public int SeriesNumber { get; set; }
        public DateTime? SeriesTime { get; set; }
        public string Modality { get; set; } = String.Empty;
        public string Description { get; set; } = String.Empty;
        public int InstanceCount { get; set; }

        public DateTime CreateTime { get; set; }

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

        public bool IsReading { get; set; }

        public bool IsDeleted { get; set; }

        //public Guid[] InstanceList = new Guid[0];
        //public List<string> InstancePathList = new List<string>();

    }



    public class QADialogCommand
    {
        public string TalkContent { get; set; } = String.Empty;
        public Guid QCChallengeId { get; set; }

        public Guid SubjectVisitId { get; set; }
    }


    /// <summary>
    /// 关闭一致性质疑Dto
    /// </summary>
    public class CloseCheckChallengeDto
    {
        public Guid subjectVisitId { get; set; }

        public string CloseCheckChallenge { get; set; }
    }


    public class CheckChallengeDialogCommand
    {
        public string TalkContent { get; set; } = String.Empty;

        public Guid SubjectVisitId { get; set; }
    }


    public class CheckChanllengeDialogDTO
    {
        public Guid Id { get; set; }
        public string TalkContent { get; set; } = String.Empty;

        public DateTime CreateTime { get; set; }

        public Guid CreateUserId { get; set; }

        public string CreateUserName { get; set; } = String.Empty;
        public string CreateUserFullName { get; set; } = String.Empty;

        public bool IsCurrentUser { get; set; }

        public bool? IsCRCNeedReply { get; set; }

        public UserTypeEnum UserTypeEnum { get; set; }

        public string ParamInfo { get; set; }

        public List<ParamInfoDto> ParamInfoList
        {
            get {
                try
                {
                   return  JsonConvert.DeserializeObject<List<ParamInfoDto>>(ParamInfo);
                }
                catch (Exception e)
                {

                    return new List<ParamInfoDto>();
                }
            }
        }
    }




    public class QCChanllengeDialogDTO : CheckChanllengeDialogDTO
    {
        public Guid QCChallengeId { get; set; }

    }






    public class DialogDTO
    {
        public Guid Id { get; set; }
        public string TalkContent { get; set; } = String.Empty;
        public string From { get; set; } = String.Empty;
        public string To { get; set; } = string.Empty;
        public Guid UserId { get; set; }

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

        public bool HasReply { get; set; }

        public DateTime CreateTime { get; set; }
    }

    public class DialogNode
    {
        public Guid Id { get; set; }
        public Guid ParentId { get; set; }
        public Guid UserId { get; set; }
        public string UserName { get; set; } = String.Empty;
        public bool HasReply { get; set; }

        public string TalkContent { get; set; } = String.Empty;
        //public Guid QARecordId { get; set; }
        public DateTime CreateTime { get; set; }
    }

}