using System.Collections.Generic;
using System.Linq;

namespace NPP.SmartSchedue.Api.Services.Integration.Models
{
    /// <summary>
    /// 任务-人员匹配矩阵类
    /// </summary>
    public class TaskPersonnelMatrix
    {
        /// <summary>
        /// 匹配评分字典 (任务ID -> 人员ID -> 评分)
        /// </summary>
        public Dictionary<long, Dictionary<long, double>> MatchScores { get; set; } 
            = new Dictionary<long, Dictionary<long, double>>();
        
        /// <summary>
        /// 设置评分
        /// </summary>
        /// <param name="taskId">任务ID</param>
        /// <param name="personnelId">人员ID</param>
        /// <param name="score">评分</param>
        public void SetScore(long taskId, long personnelId, double score)
        {
            if (!MatchScores.ContainsKey(taskId))
                MatchScores[taskId] = new Dictionary<long, double>();
            MatchScores[taskId][personnelId] = score;
        }
        
        /// <summary>
        /// 获取评分
        /// </summary>
        /// <param name="taskId">任务ID</param>
        /// <param name="personnelId">人员ID</param>
        /// <returns>评分值</returns>
        public double GetScore(long taskId, long personnelId)
        {
            return MatchScores.ContainsKey(taskId) && MatchScores[taskId].ContainsKey(personnelId)
                ? MatchScores[taskId][personnelId] : 0;
        }

        /// <summary>
        /// 获取所有人员ID
        /// </summary>
        /// <returns>人员ID列表</returns>
        public List<long> GetAllPersonnelIds()
        {
            return MatchScores.SelectMany(kvp => kvp.Value.Keys).Distinct().ToList();
        }
    }
}