using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NPP.SmartSchedue.Api.Contracts.Domain.Notification;
using NPP.SmartSchedue.Api.Contracts.Core.Enums;
using ZhonTai.Admin.Core.Repositories;

namespace NPP.SmartSchedue.Api.Contracts.Core.Repositories;

/// <summary>
/// 通知历史记录仓储接口
/// </summary>
public interface INotificationHistoryRepository : IRepositoryBase<NotificationHistoryEntity>
{
    /// <summary>
    /// 根据通知设置ID获取历史记录列表
    /// </summary>
    /// <param name="notificationSettingId">通知设置ID</param>
    /// <returns></returns>
    Task<List<NotificationHistoryEntity>> GetByNotificationSettingIdAsync(long notificationSettingId);

    /// <summary>
    /// 根据接收人员ID获取历史记录列表
    /// </summary>
    /// <param name="recipientPersonnelId">接收人员ID</param>
    /// <returns></returns>
    Task<List<NotificationHistoryEntity>> GetByRecipientPersonnelIdAsync(long recipientPersonnelId);

    /// <summary>
    /// 根据发送状态获取历史记录列表
    /// </summary>
    /// <param name="sendStatus">发送状态</param>
    /// <returns></returns>
    Task<List<NotificationHistoryEntity>> GetBySendStatusAsync(NotificationStatusEnum sendStatus);

    /// <summary>
    /// 根据通知方式获取历史记录列表
    /// </summary>
    /// <param name="notificationType">通知方式</param>
    /// <returns></returns>
    Task<List<NotificationHistoryEntity>> GetByNotificationTypeAsync(NotificationTypeEnum notificationType);

    /// <summary>
    /// 根据业务类型和业务ID获取历史记录列表
    /// </summary>
    /// <param name="businessType">业务类型</param>
    /// <param name="businessId">业务ID</param>
    /// <returns></returns>
    Task<List<NotificationHistoryEntity>> GetByBusinessAsync(string businessType, long? businessId = null);

    /// <summary>
    /// 获取需要重试的失败通知列表
    /// </summary>
    /// <param name="maxRetryCount">最大重试次数</param>
    /// <returns></returns>
    Task<List<NotificationHistoryEntity>> GetFailedNotificationsForRetryAsync(int? maxRetryCount = null);

    /// <summary>
    /// 获取指定时间范围内的通知统计信息
    /// </summary>
    /// <param name="startTime">开始时间</param>
    /// <param name="endTime">结束时间</param>
    /// <param name="notificationSettingId">通知设置ID（可选）</param>
    /// <returns></returns>
    Task<Dictionary<string, int>> GetNotificationStatisticsAsync(
        DateTime startTime,
        DateTime endTime,
        long? notificationSettingId = null);

    /// <summary>
    /// 根据日期范围获取历史记录列表
    /// </summary>
    /// <param name="startDate">开始日期</param>
    /// <param name="endDate">结束日期</param>
    /// <returns></returns>
    Task<List<NotificationHistoryEntity>> GetByDateRangeAsync(DateTime startDate, DateTime endDate);

    /// <summary>
    /// 更新通知发送状态
    /// </summary>
    /// <param name="id">历史记录ID</param>
    /// <param name="sendStatus">发送状态</param>
    /// <param name="sendResult">发送结果</param>
    /// <param name="errorMessage">错误信息</param>
    /// <returns></returns>
    Task UpdateSendStatusAsync(long id, NotificationStatusEnum sendStatus, string sendResult = "", string errorMessage = "");

    /// <summary>
    /// 批量更新通知发送状态
    /// </summary>
    /// <param name="updates">更新信息列表</param>
    /// <returns></returns>
    Task BatchUpdateSendStatusAsync(List<(long Id, NotificationStatusEnum Status, string Result, string Error)> updates);
}