using System.Collections.Generic;
using System.Threading.Tasks;
using MDL.Models;

namespace DAL.Interfaces
{
    /// <summary>
    /// 面单PDF缓存的数据访问接口
    /// </summary>
    public interface ILabelPdfCacheRepository
    {
        /// <summary>
        /// 根据中性面单单号获取缓存记录
        /// </summary>
        /// <param name="waybillNumber">中性面单单号</param>
        /// <returns>缓存记录实体</returns>
        Task<LabelPdfCache?> GetByWaybillNumberAsync(string waybillNumber);
        
        /// <summary>
        /// 创建缓存记录
        /// </summary>
        /// <param name="entity">缓存实体</param>
        /// <returns>创建的记录ID</returns>
        Task<long> CreateAsync(LabelPdfCache entity);
        
        /// <summary>
        /// 更新缓存记录
        /// </summary>
        /// <param name="entity">缓存实体</param>
        /// <returns>更新是否成功</returns>
        Task<bool> UpdateAsync(LabelPdfCache entity);
        
        /// <summary>
        /// 标记缓存为失效状态
        /// </summary>
        /// <param name="waybillNumber">中性面单单号</param>
        /// <returns>操作是否成功</returns>
        Task<bool> InvalidateCacheAsync(string waybillNumber);
        
        /// <summary>
        /// 获取待处理的缓存任务列表
        /// </summary>
        /// <param name="maxRetryCount">最大重试次数</param>
        /// <param name="limit">最大返回数量</param>
        /// <returns>待处理的缓存任务列表</returns>
        Task<List<LabelPdfCache>> GetPendingTasksAsync(int maxRetryCount, int limit);
        
        /// <summary>
        /// 获取订单表中新的有标签订单（缓存表中不存在的）
        /// </summary>
        /// <param name="limit">最大返回数量</param>
        /// <returns>新订单的面单号列表</returns>
        Task<List<string>> GetNewOrdersWithLabelsAsync(int limit);
        
        /// <summary>
        /// 获取需要重新处理的失效缓存列表
        /// </summary>
        /// <param name="limit">最大返回数量</param>
        /// <returns>失效的缓存记录列表</returns>
        Task<List<LabelPdfCache>> GetInvalidCachesAsync(int limit);
        
        /// <summary>
        /// 异步更新条码信息
        /// </summary>
        /// <param name="waybillNumber">中性面单单号</param>
        /// <param name="barcodeNumber">条码号</param>
        /// <param name="barcodeType">条码类型</param>
        /// <param name="confidence">识别置信度</param>
        /// <returns>更新是否成功</returns>
        Task<bool> UpdateBarcodeInfoAsync(string waybillNumber, string barcodeNumber, byte barcodeType, int confidence);
    }
}
