using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ZhonTai.Admin.Core.Repositories;

namespace NPP.SmartSchedue.Api.Contracts.Domain.Time;

/// <summary>
/// 班次不可用标记仓储接口
/// 提供班次不可用数据的访问方法
/// </summary>
public interface IShiftUnavailabilityRepository : IRepositoryBase<ShiftUnavailabilityEntity>
{
    /// <summary>
    /// 获取指定员工在指定日期范围内的不可用记录
    /// </summary>
    /// <param name="personnelId">员工ID</param>
    /// <param name="startDate">开始日期</param>
    /// <param name="endDate">结束日期</param>
    /// <returns>不可用记录列表</returns>
    Task<List<ShiftUnavailabilityEntity>> GetByPersonnelAndDateRangeAsync(long personnelId, DateTime startDate, DateTime endDate);
    
    /// <summary>
    /// 获取指定日期和班次的不可用员工ID列表
    /// </summary>
    /// <param name="date">日期</param>
    /// <param name="shiftId">班次ID</param>
    /// <returns>不可用员工ID列表</returns>
    Task<List<long>> GetUnavailablePersonnelIdsAsync(DateTime date, long shiftId);

    /// <summary>
    /// 检查人员班次的意愿
    /// </summary>
    /// <param name="date"></param>
    /// <param name="shiftId"></param>
    /// <param name="personnelId"></param>
    /// <returns></returns>
    Task<bool> CheckUnavailablePersonnelByShiftAsync(DateTime date, long shiftId, long personnelId);
    
    /// <summary>
    /// 获取指定日期所有班次的不可用员工分布
    /// </summary>
    /// <param name="date">日期</param>
    /// <returns>班次ID -> 不可用员工ID列表的字典</returns>
    Task<Dictionary<long, List<long>>> GetDailyUnavailablePersonnelAsync(DateTime date);
    
    /// <summary>
    /// 批量获取日期范围内的不可用员工分布
    /// </summary>
    /// <param name="startDate">开始日期</param>
    /// <param name="endDate">结束日期</param>
    /// <returns>日期 -> (班次ID -> 不可用员工ID列表) 的嵌套字典</returns>
    Task<Dictionary<DateTime, Dictionary<long, List<long>>>> GetRangeUnavailablePersonnelAsync(DateTime startDate, DateTime endDate);
    
    /// <summary>
    /// 检查指定员工在指定日期和班次是否已有不可用记录
    /// </summary>
    /// <param name="personnelId">员工ID</param>
    /// <param name="date">日期</param>
    /// <param name="shiftId">班次ID</param>
    /// <returns>是否存在记录</returns>
    Task<bool> ExistsAsync(long personnelId, DateTime date, long shiftId);
    
    /// <summary>
    /// 删除指定条件的记录
    /// </summary>
    /// <param name="personnelId">员工ID</param>
    /// <param name="date">日期</param>
    /// <param name="shiftId">班次ID（可选）</param>
    /// <returns>删除的记录数量</returns>
    Task<int> DeleteByConditionAsync(long personnelId, DateTime date, long? shiftId = null);
    
    /// <summary>
    /// 获取统计信息
    /// </summary>
    /// <param name="personnelId">员工ID</param>
    /// <param name="startDate">开始日期</param>
    /// <param name="endDate">结束日期</param>
    /// <returns>统计结果</returns>
    Task<Dictionary<int, int>> GetStatisticsAsync(long personnelId, DateTime startDate, DateTime endDate);
}