using System;
using System.Collections.Generic;

using IRaCIS.Core.Infrastructure.Extention;
using IRaCIS.Core.Domain.Share;
using Newtonsoft.Json;
using System.Linq;

namespace IRaCIS.Application.Contracts
{

    #region 医生管理列表

    public class DoctorDTO
    {

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


        //第二专业
        public List<string> SubspecialityList => DictionaryList.Where(t => t.ParentCode == StaticData.Subspeciality).OrderBy(t => t.ShowOrder).Select(t => t.Value).ToList();

        public List<string> SubspecialityCNList => DictionaryList.Where(t => t.ParentCode == StaticData.Subspeciality).OrderBy(t => t.ShowOrder).Select(t => t.ValueCN).ToList();



        //临床实践中使用的模式
        public List<string> ReadingTypeList => DictionaryList.Where(t => t.ParentCode == StaticData.ReadingType).OrderBy(t => t.ShowOrder).Select(t => t.Value).ToList();
        public List<string> ReadingTypeCNList => DictionaryList.Where(t => t.ParentCode == StaticData.ReadingType).OrderBy(t => t.ShowOrder).Select(t => t.ValueCN).ToList();

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


        public string AccountUserName { get; set; }



        public string ReadingTypeOther { get; set; } = String.Empty;
        public string ReadingTypeOtherCN { get; set; } = String.Empty;

        public Guid Id { get; set; }
        public DateTime CreateTime { get; set; }
        public string ReviewerCode { get; set; } = String.Empty;//GUID
        public string FirstName { get; set; } = string.Empty;
        public string LastName { get; set; } = string.Empty;
        public string ChineseName { get; set; } = string.Empty;
        public List<Guid> TitleIdList { get; set; } = new List<Guid>();
        public List<string> TitleList { get; set; } = new List<string>();
        public List<string> TitleCNList { get; set; } = new List<string>();
        public string Phone { get; set; } = string.Empty;
        public string Introduction { get; set; } = string.Empty;
        public string EMail { get; set; } = string.Empty;

        public ReviewerInformationConfirmStatus ReviewStatus { get; set; } = ReviewerInformationConfirmStatus.ConfirmRefuse;
        public string WeChat { get; set; } = string.Empty;

        //部门
        public string Department { get; set; } = string.Empty;
        public string DepartmentCN { get; set; } = string.Empty;
        public Guid? DepartmentId { get; set; }
        public string DepartmentOther { get; set; } = String.Empty;
        public string DepartmentOtherCN { get; set; } = String.Empty;

        //增加的
        public Guid? SpecialityId { get; set; } = Guid.Empty;
        public string SpecialityOther { get; set; } = string.Empty;
        public string SpecialityOtherCN { get; set; } = string.Empty;
        public string Speciality { get; set; } = string.Empty;
        public string SpecialityCN { get; set; } = string.Empty;


        //职称
        public string Rank { get; set; } = string.Empty;
        public string RankCN { get; set; } = string.Empty;
        public Guid? RankId { get; set; }
        public string RankOther { get; set; } = String.Empty;
        public string RankOtherCN { get; set; } = String.Empty;

        //职位 
        public string Position { get; set; } = string.Empty;
        public string PositionCN { get; set; } = string.Empty;
        public Guid? PositionId { get; set; }
        public string PositionOther { get; set; } = String.Empty;
        public string PositionOtherCN { get; set; } = String.Empty;




        public string SubspecialityOther { get; set; } = String.Empty;
        public string SubspecialityOtherCN { get; set; } = String.Empty;

        public int GCP { get; set; }
        public Guid? GCPId { get; set; }
        public string ResumePath { get; set; } = string.Empty;
        public bool HasResume
        {
            get; set;
        }
        public bool Reconfirmed { get; set; }
        public int CooperateStatus { get; set; }
        public int ResumeStatus { get; set; }
        public bool AcceptingNewTrial { get; set; } = false;
        public bool ActivelyReading { get; set; } = false;

        //医院

        public Guid? HospitalId { get; set; }
        public string HospitalOther { get; set; } = String.Empty;
        public string HospitalName { get; set; } = string.Empty;
        public string City { get; set; } = String.Empty;
        public string Country { get; set; } = String.Empty;

        public string HospitalNameCN { get; set; } = string.Empty;
        public string CityCN { get; set; } = String.Empty;
        public string CountryCN { get; set; } = String.Empty;


        public int? Reading { get; set; }
        public int? Approved { get; set; }
        public int? Submitted { get; set; }

        public int? Finished { get; set; }

        public bool IsVirtual { get; set; }
    }

    /// <summary>
    /// Reviewer 列表查询参数
    /// </summary>

    public class DoctorSearchDTO : PageInput
    {
        public string Name { get; set; } = string.Empty;
        public List<Guid> ReadingTypeIdList { get; set; } = new List<Guid>();
        public List<Guid> SubspecialityIdList { get; set; } = new List<Guid>();

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

        public List<Guid> TitleIdList { get; set; } = new List<Guid>();
        public Guid? DepartmentId { get; set; }
        public Guid? SpecialityId { get; set; }
        public Guid? PositionId { get; set; } 
        public Guid? RankId { get; set; }
        public Guid? HospitalId { get; set; } 

        //合作状态
        public ContractorStatusEnum? ContractorStatus { get; set; }

        // 简历审核状态
        public ResumeStatusEnum? InformationConfirmed { get; set; }
        public int? EnrollStatus { get; set; } //入组状态

        public bool? AcceptingNewTrial { get; set; }//是否接受新的项目
        public bool? ActivelyReading { get; set; }// 是否接受新的读片任务
        public int? Nation { get; set; }// 0-中国医生，2-美国医生，3-全部
    }

    /// <summary>
    /// 入组 Selection 列表查询参数
    /// </summary>
    public class ReviewerSelectionQueryDTO : DoctorSearchDTO
    {
        public Guid TrialId { get; set; }
    }

    public class ReviewerSubmissionQueryDTO : PageInput
    {
        public Guid TrialId { get; set; } = Guid.Empty;
        public int IntoGroupSearchState { get; set; }
    }

    public class ReviewerConfirmationQueryDTO : PageInput
    {
        public Guid TrialId { get; set; } = Guid.Empty;
    }

    public class SelectionReviewerDTO : DoctorDTO
    {
        public int DoctorTrialState { get; set; }
        public string OptUserName { get; set; } = string.Empty;
        public DateTime? OptTime { get; set; }
        public string? OptTimeStr => OptTime?.ToString("yyyy-MM-dd HH:mm:ss");
    }

    public class DoctorOptDTO
    {
        public Guid Id { get; set; }
        public string Code { get; set; } = String.Empty;//GUID
        public string FirstName { get; set; } = string.Empty;
        public string LastName { get; set; } = string.Empty;
        public string ChineseName { get; set; } = string.Empty;

        public string City { get; set; } = string.Empty;
        public string HospitalName { get; set; } = string.Empty;
        public string Country { get; set; } = string.Empty;
    }


    public class ConfirmationReviewerDTO : DoctorOptDTO
    {
        public int DoctorTrialState { get; set; } 
        public string OptUserName { get; set; } = string.Empty;
        public DateTime? OptTime { get; set; }
        public string? OptTimeStr => OptTime?.ToString("yyyy-MM-dd HH:mm:ss");

        //SPM  需要看到
        public DateTime? SubmmitTime { get; set; }
        public string SubmmitUserName { get; set; } = string.Empty;
        public string BlindName { get; set; }
        public string BlindNameCN { get; set; } = string.Empty;

        public Guid? SpecialityId { get; set; } = Guid.Empty;

        public string SpecialityCN { get; set; } = string.Empty;
        public string Speciality { get; set; } = string.Empty;
        public string SpecialityOther { get; set; } = string.Empty;
        public string SpecialityOtherCN { get; set; } = string.Empty;

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

        public Guid? HospitalId { get; set; }
    }




    public class DoctorStateModelDTO
    {
        public Guid DoctorId { get; set; }
        public int IntoGroupState { get; set; }
        public string OptUserName { get; set; } = String.Empty;
        public DateTime? OptTime { get; set; }

    }

    #endregion

    public class DoctorDetailDTO
    {
        public DoctorBasicInfoDTO BasicInfoView { get; set; }
        public EmploymentDTO EmploymentView { get; set; }
        public SpecialtyDTO SpecialtyView { get; set; }
       
      
        public ResumeConfirmDTO AuditView { get; set; }
    

        public List<SowDTO> SowList { get; set; }
        public List<SowDTO> AckSowList { get; set; }

        public DoctorEnrollInfoDTO IntoGroupInfo { get; set; }

        public bool InHoliday { get; set; }
        public DoctorDetailDTO()
        {
            BasicInfoView = new DoctorBasicInfoDTO();
            EmploymentView = new EmploymentDTO();
            SpecialtyView = new SpecialtyDTO();
          
            AuditView = new ResumeConfirmDTO();
         
            IntoGroupInfo = new DoctorEnrollInfoDTO();
            SowList = new List<SowDTO>();
            AckSowList = new List<SowDTO>();
        }
    }

    public class DoctorEnrollInfoDTO
    {
        public Guid? DoctorId { get; set; }
        public int? Submitted { get; set; }
        public int? Approved { get; set; }
        public int? Reading { get; set; }
    }



    #region 基本信息模型

    public class DoctorBasicInfo
    {
        public Guid? Id { get; set; }
        public string ReviewerCode { get; set; } = string.Empty;
        public string FirstName { get; set; } = String.Empty;
        public string LastName { get; set; } = String.Empty;
        public string ChineseName { get; set; } = String.Empty;
        public int Sex { get; set; }
        public string Phone { get; set; } = String.Empty;
        public string Introduction { get; set; } = String.Empty;
        public string EMail { get; set; } = String.Empty;
        public string WeChat { get; set; } = String.Empty;
        public int Nation { get; set; }


    }

    public class DoctorBasicInfoCommand : DoctorBasicInfo
    {
       
        //职称
        public List<Guid> TitleIds { get; set; } = new List<Guid>();
    }

    public class TempObj
    {
        public int ShowOrder { get; set; }
        public Guid TitleId { get; set; }
        public string TitleCN { get; set; } = string.Empty;
        public string Title { get; set; } = string.Empty;
    }
    public class DicView
    {
        public int ShowOrder { get; set; }
        public Guid Id { get; set; }
        public string ValueCN { get; set; } = string.Empty;
        public string ParentCode { get; set; } = string.Empty;


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


    public class DoctorBasicInfoDTO : DoctorBasicInfo
    {
        public string BlindName { get; set; }

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

        public List<DicView> DoctorDicViewDtos = new List<DicView>();

        //职称
        public List<Guid> TitleIds => DoctorDicViewDtos.Select(t => t.Id).ToList();
      
        public List<string> TitleList=> DoctorDicViewDtos.Select(t => t.Value).ToList();
       
        public List<string> TitleCNList=> DoctorDicViewDtos.Select(t => t.ValueCN).ToList();
       
        #region ef  select 
        //[JsonIgnore]
        //public List<TempObj> TempObjList { get; set; }
        ////职称
        //public List<Guid> TitleIds
        //{
        //    get
        //    {
        //        if (TempObjList.Count > 0)
        //        {
        //            return TempObjList.Select(t => t.TitleId).ToList();
        //        }
        //        else
        //        {
        //            return new List<Guid>();
        //        }
        //    }

        //}
        //public List<string> TitleList
        //{
        //    get
        //    {
        //        if (TempObjList.Count > 0)
        //        {
        //            return TempObjList.Select(t => t.Title).ToList();
        //        }
        //        else
        //        {
        //            return new List<string>();
        //        }
        //    }
        //}
        //public List<string> TitleCNList
        //{
        //    get
        //    {
        //        if (TempObjList.Count > 0)
        //        {
        //            return TempObjList.Select(t => t.TitleCN).ToList();
        //        }
        //        else
        //        {
        //            return new List<string>();
        //        }
        //    }
        //}

        #endregion
    }

    public class SowDTO
    {
        public string FileName { get; set; } = string.Empty;
        public string TrialCode { get; set; } = string.Empty;
        public string FilePath { get; set; } = string.Empty;
        public string FullPath { get { return  FilePath; } }
        public DateTime CreateTime { get; set; }
    }


    #endregion


    #region 工作信息模型


    //public class DoctorHospitalView
    //{
    //    public string HospitalName { get; set; }
    //    public string UniversityAffiliated { get; set; }
    //    public string Country { get; set; }
    //    public string Province { get; set; }
    //    public string City { get; set; }

    //    public string HospitalNameCN { get; set; }

    //    public string UniversityAffiliatedCN { get; set; }
    //    public string CountryCN { get; set; }

    //    public string ProvinceCN { get; set; }

    //    public string CityCN { get; set; }
    //}

    public class EmploymentDTO : EmploymentInfo
    {
        //public DoctorHospitalView Hospital { get; set; }

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

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

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

        #region 医院信息
        public string HospitalName { get; set; } = String.Empty;

        public string UniversityAffiliated { get; set; } = String.Empty;
        public string Country { get; set; } = String.Empty;

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

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

        #endregion

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

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

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


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

        public string UniversityAffiliatedCN { get; set; } = String.Empty;
        public string CountryCN { get; set; } = String.Empty;

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

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

    public class EmploymentCommand : EmploymentInfo
    {

    }

    public class EmploymentInfo
    {
        public Guid Id { get; set; }
        //部门
        public Guid? DepartmentId { get; set; } = Guid.Empty;
        public string DepartmentOther { get; set; } = string.Empty;
        public string DepartmentOtherCN { get; set; } = string.Empty;
        //职称
        public Guid? RankId { get; set; } = Guid.Empty;
        public string RankOther { get; set; } = string.Empty;
        public string RankOtherCN { get; set; } = string.Empty;
        //职位  主席 副主席
        public Guid? PositionId { get; set; } = Guid.Empty;
        public string PositionOther { get; set; } = string.Empty;
        public string PositionOtherCN { get; set; } = string.Empty;

        public Guid? HospitalId { get; set; } = Guid.Empty;

        public Guid? PhysicianId { get; set; }
        public string Physician { get; set; } = string.Empty;
        public string PhysicianCN { get; set; } = string.Empty;

    }

    #endregion

    #region Specialty模型
    public class SpecialtyDTO : SpecialtyCommand
    {
        [JsonIgnore]
        public List<DicView> DictionaryList { get; set; } = new List<DicView>();

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


        //临床实践中使用的模式
        public new List<Guid> ReadingTypeIds
        {
            get
            {
                if (DictionaryList.Count > 0)
                {
                    return DictionaryList.Where(t => t.ParentCode == StaticData.ReadingType).Select(t => t.Id).ToList();
                }
                else
                {
                    return new List<Guid>();
                }
            }

        }

        public new List<Guid> SubspecialityIds
        {
            get
            {
                if (DictionaryList.Count > 0)
                {
                    return DictionaryList.Where(t => t.ParentCode == StaticData.Subspeciality).Select(t => t.Id).ToList();
                }
                else
                {
                    return new List<Guid>();
                }
            }

        }


        public List<string> ReadingTypeList
        {
            get
            {
                if (DictionaryList.Count > 0)
                {
                    return DictionaryList.Where(t => t.ParentCode == StaticData.ReadingType).Select(t => t.Value).ToList();
                }
                else
                {
                    return new List<string>();
                }
            }

        }
        public List<string> SubspecialityList
        {
            get
            {
                if (DictionaryList.Count > 0)
                {
                    return DictionaryList.Where(t => t.ParentCode == StaticData.Subspeciality).Select(t => t.Value).ToList();
                }
                else
                {
                    return new List<string>();
                }
            }

        }

        public List<string> ReadingTypeCNList
        {
            get
            {
                if (DictionaryList.Count > 0)
                {
                    return DictionaryList.Where(t => t.ParentCode == StaticData.ReadingType).Select(t => t.ValueCN).ToList();
                }
                else
                {
                    return new List<string>();
                }
            }

        }
        public List<string> SubspecialityCNList
        {
            get
            {
                if (DictionaryList.Count > 0)
                {
                    return DictionaryList.Where(t => t.ParentCode == StaticData.Subspeciality).Select(t => t.ValueCN).ToList();
                }
                else
                {
                    return new List<string>();
                }
            }

        }
    }



    public class SpecialtyCommand
    {
        public List<Guid> ReadingTypeIds { get; set; } = new List<Guid>();

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

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

        public string ReadingTypeOther { get; set; } = string.Empty;
        public string ReadingTypeOtherCN { get; set; } = string.Empty;
        //亚专科

        public string SubspecialityOther { get; set; } = string.Empty;
        public string SubspecialityOtherCN { get; set; } = string.Empty;

        public Guid? SpecialityId { get; set; } = Guid.Empty;
        public string SpecialityCN { get; set; } = string.Empty;
        public string SpecialityOther { get; set; } = string.Empty;
        public string SpecialityOtherCN { get; set; } = string.Empty;


    }


    #endregion

    #region 医生账户
    public class DoctorAccountLoginDTO
    {
        public string Phone { get; set; } = String.Empty;
        public string Password { get; set; } = String.Empty;
    }

    public class DoctorAccountDTO
    {
        public Guid Id { get; set; }
        public string FirstName { get; set; } = String.Empty;
        public string LastName { get; set; } = String.Empty;
        public string Phone { get; set; } = String.Empty;
        public string PhotoPath { get; set; } = String.Empty;
    }

    public class DoctorAccountUpdatePasswordCommand
    {
        public string Phone { get; set; } = String.Empty;
        public string OldPassword { get; set; } = String.Empty;
        public string NewPassword { get; set; } = String.Empty;
    }
    #endregion

    #region  审核模型

    public class ResumeConfirmCommand
    {
        //int userId, int doctorId, int status, string memo
        //public Guid FromUserId { get; set; }
        public Guid Id { get; set; }
        public ResumeStatusEnum ResumeStatus { get; set; }
        public ReviewerInformationConfirmStatus ReviewStatus { get; set; }
        public bool AcceptingNewTrial { get; set; } = false;
        public bool ActivelyReading { get; set; } = false;
        public string AdminComment { get; set; } = String.Empty;
        public string MessageContent { get; set; } = String.Empty;
        public ContractorStatusEnum CooperateStatus { get; set; }

        public bool IsVirtual { get; set; }

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

        public string BlindNameCN { get; set; } = string.Empty;
        public string BlindPublications { get; set; }

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

    }

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

        public Guid? TrialId { get; set; }

        public Guid? TrialReadingCriterionId { get; set; }

        public string CriterionName { get; set; }

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

        /// <summary>
        /// 文件名称
        /// </summary>
		public string FileName { get; set; }

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

        /// <summary>
        /// 标准类型
        /// </summary>
        public CriterionType CriterionType { get; set; }

        /// <summary>
        /// 医生Id
        /// </summary>
        public Guid DoctorId { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }



        /// <summary>
        /// 文件类型
        /// </summary>
        public CriterionFileType FileType { get; set; }
    }


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

        /// <summary>
        /// 文件名称
        /// </summary>
        public string FileName { get; set; }

        public bool IsEnable { get; set; }

        public string CriterionName { get; set; }

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

        /// <summary>
        /// 标准类型
        /// </summary>
        public CriterionType CriterionType { get; set; }

        /// <summary>
        /// 医生Id
        /// </summary>
        public Guid DoctorId { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }

        /// <summary>
        /// 文件类型
        /// </summary>
        public CriterionFileType FileType { get; set; }

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

        /// <summary>
        /// CreateTime
        /// </summary>
        public DateTime CreateTime { get; set; }


       
    }

    public class GetDoctorCriterionFileInDto    
    {
        public  Guid DoctorId { get; set; }

        /// <summary>
        /// 文件类型
        /// </summary>
        public CriterionFileType? FileType { get; set; }


        /// <summary>
        /// 标准类型
        /// </summary>
		public CriterionType? CriterionType { get; set; }
    }

    public class ResumeConfirmDTO
    {
        public Guid Id { get; set; }
        public int CooperateStatus { get; set; }
        public int ResumeStatus { get; set; }
        public int ReviewStatus { get; set; } //复审状态
        public bool AcceptingNewTrial { get; set; }
        public bool ActivelyReading { get; set; }
        public string AdminComment { get; set; } = String.Empty;
        public bool InHoliday { get; set; }

        public bool IsVirtual { get; set; }

        public string BlindName { get; set; } = String.Empty;
        public string BlindNameCN { get; set; } = string.Empty;
        public string BlindPublications { get; set; }
    }

    #endregion


    public class TrialPaymentPriceQueryDTO : PageInput
    {
        public string KeyWord { get; set; } = String.Empty;

        public Guid? CroId { get; set; } 

    }

    public class DoctorPaymentInfoQueryDTO : PageInput
    {
        public string SearchName { get; set; } = String.Empty;
        public Guid? HospitalId { get; set; }
    }
}
