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

namespace DAL.Interfaces
{
    /// <summary>
    /// 标签替换请求的数据访问接口
    /// </summary>
    public interface ILabelReplaceRepository
    {
        /// <summary>
        /// 创建标签替换请求记录
        /// </summary>
        /// <param name="entity">标签替换请求实体</param>
        /// <returns>创建的记录ID</returns>
        Task<int> CreateAsync(LabelReplaceEntity entity);
        
        /// <summary>
        /// 根据ID获取标签替换请求记录
        /// </summary>
        /// <param name="id">记录ID</param>
        /// <returns>标签替换请求实体</returns>
        Task<LabelReplaceEntity?> GetByIdAsync(int id);
        
        /// <summary>
        /// 根据中性面单单号获取标签替换请求记录
        /// </summary>
        /// <param name="waybillNumber">中性面单单号</param>
        /// <returns>标签替换请求实体</returns>
        Task<LabelReplaceEntity?> GetByWaybillNumberAsync(string waybillNumber);
        
        /// <summary>
        /// 根据跟踪单号获取标签替换请求记录
        /// </summary>
        /// <param name="trackingNumber">跟踪单号</param>
        /// <returns>标签替换请求实体列表</returns>
        Task<List<LabelReplaceEntity>> GetByTrackingNumberAsync(string trackingNumber);
        
        /// <summary>
        /// 更新标签替换请求记录
        /// </summary>
        /// <param name="entity">标签替换请求实体</param>
        /// <returns>更新是否成功</returns>
        Task<bool> UpdateAsync(LabelReplaceEntity entity);
        
        /// <summary>
        /// 删除标签替换请求记录
        /// </summary>
        /// <param name="id">记录ID</param>
        /// <returns>删除是否成功</returns>
        Task<bool> DeleteAsync(int id);
        
        /// <summary>
        /// 获取所有标签替换请求记录
        /// </summary>
        /// <returns>标签替换请求实体列表</returns>
        Task<List<LabelReplaceEntity>> GetAllAsync();

        /// <summary>
        /// 分页获取标签替换请求记录
        /// </summary>
        /// <param name="page">页码</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="sortBy">排序字段</param>
        /// <param name="sortOrder">排序顺序</param>
        /// <param name="billOfLadingNumber">提单号</param>
        /// <param name="masterPackageNumber">大包号</param>
        /// <param name="referenceNumber">参考号</param>
        /// <param name="neutralWaybillNumber">中性面单单号</param>
        /// <param name="finalMileTrackingNumber">尾程跟踪单号</param>
        /// <param name="replaceStatus">换单状态</param>
        /// <param name="customerId">客户ID</param>
        /// <returns>标签替换请求实体列表和总记录数</returns>
        Task<(List<LabelReplaceWithCustomerDto>, int)> GetByPageAsync(int page, int pageSize, string sortBy, string sortOrder, string billOfLadingNumber, string masterPackageNumber, string referenceNumber, string neutralWaybillNumber, string finalMileTrackingNumber, string replaceStatus, int? customerId, string startCreatedAt, string endCreatedAt, string startReplacedAt, string endReplacedAt);

        /// <summary>
        /// 批量查询换单状态
        /// </summary>
        /// <param name="customerId">客户ID</param>
        /// <param name="waybillNumbers">中性面单单号列表</param>
        /// <param name="trackingNumbers">尾程跟踪单号列表</param>
        /// <returns>标签替换请求实体列表和最新扫描时间映射</returns>
        Task<(List<LabelReplaceEntity>, Dictionary<string, DateTime>)> GetLabelReplaceStatusAsync(int customerId, List<string> waybillNumbers, List<string> trackingNumbers);

        /// <summary>
        /// 根据交接单号列表批量获取标签替换请求记录
        /// </summary>
        /// <param name="handoverNumbers">交接单号列表</param>
        /// <param name="customerId">客户ID</param>
        /// <returns>标签替换请求实体列表</returns>
        Task<List<LabelReplaceEntity>> GetByHandoverNumbersAsync(List<string> handoverNumbers, int? customerId);

        /// <summary>
        /// 将base64编码转换为PDF文件并保存
        /// </summary>
        /// <param name="base64Content">base64编码的PDF内容</param>
        /// <param name="fileName">文件名</param>
        /// <returns>保存的文件路径</returns>
        Task<string> ConvertBase64ToPdfAsync(string base64Content, string fileName);
        
        /// <summary>
        /// 更新Label字段但保持LabelRetrievedAt不变
        /// </summary>
        /// <param name="id">记录ID</param>
        /// <param name="newLabel">新的Label值</param>
        /// <returns>更新是否成功</returns>
        Task<bool> UpdateLabelWithoutChangingRetrievedAtAsync(int id, string newLabel);

        /// <summary>
        /// 获取每日标签统计数据
        /// </summary>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <param name="customerId">客户ID</param>
        /// <returns>每日标签统计数据列表</returns>
        Task<List<DailyLabelStatsDto>> GetDailyLabelStatsAsync(string startDate, string endDate, int? customerId);

        /// <summary>
        /// 获取每日标签统计数据（中文版本，使用自定义SQL）
        /// </summary>
        /// <returns>每日标签统计数据列表</returns>
        Task<List<DailyLabelStatsChineseDto>> GetDailyLabelStatsChineseAsync();
    }
}