using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Performance.Services
{
    public class AprAmountService : IAutoInjection
    {
        private readonly PerforPeremployeeRepository _peremployeeRepository;
        private readonly PerforPerapramountRepository _perapramountRepository;

        public AprAmountService(
            PerforPeremployeeRepository peremployeeRepository,
            PerforPerapramountRepository perapramountRepository)
        {
            _peremployeeRepository = peremployeeRepository;
            _perapramountRepository = perapramountRepository;
        }

        /// <summary>
        /// 获取医院其他绩效 默认审核通过 status = 3
        /// 科室及核算组别使用人员字典
        /// </summary>
        /// <param name="allotId"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public List<AprAmount> GetAprAmount(int allotId, int status = 3)
        {
            var perapramounts = _perapramountRepository.GetEntities(t => t.AllotId == allotId && t.Status == status);
            var employees = _peremployeeRepository.GetEntities(t => t.AllotId == allotId);

            var result = perapramounts.Join(employees, amt => amt.PersonnelNumber, epy => epy.PersonnelNumber,
                 (amt, epy) => new AprAmount
                 {
                     AccountingUnit = epy.AccountingUnit,
                     UnitType = epy.UnitType,
                     PersonnelNumber = amt.PersonnelNumber,
                     DoctorName = amt.DoctorName,
                     PerforType = amt.PerforType,
                     Amount = amt.Amount
                 });
            return result?.ToList() ?? new List<AprAmount>();
        }
    }

    public class AprAmount
    {
        /// <summary>
        /// 核算单元
        /// </summary>
        public string UnitType { get; set; }

        /// <summary>
        /// 人员工号
        /// </summary>
        public string PersonnelNumber { get; set; }

        /// <summary>
        /// 医生姓名
        /// </summary>
        public string DoctorName { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string PerforType { get; set; }

        /// <summary>
        /// 金额
        /// </summary>
        public Nullable<decimal> Amount { get; set; }

        /// <summary>
        /// 核算单元
        /// </summary>
        public string AccountingUnit { get; set; }
    }
}
