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

namespace DAL.Interfaces
{
    /// <summary>
    /// 标签历史扫描记录仓储接口
    /// </summary>
    public interface ILabelScanRepository
    {
        /// <summary>
        /// 创建标签扫描记录
        /// </summary>
        /// <param name="entity">标签扫描记录实体</param>
        /// <returns>创建的记录ID</returns>
        Task<int> CreateAsync(LabelScanEntity entity);

        /// <summary>
        /// 根据中性面单单号获取标签扫描记录列表
        /// </summary>
        /// <param name="neutralWaybillNumber">中性面单单号</param>
        /// <returns>标签扫描记录列表</returns>
        Task<List<LabelScanEntity>> GetByNeutralWaybillNumberAsync(string neutralWaybillNumber);
        Task<List<LabelScanEntity>> GetByNeutralWaybillNumbersAsync(List<string> neutralWaybillNumbers);

        /// <summary>
        /// 根据参考号获取标签扫描记录列表
        /// </summary>
        /// <param name="referenceNumber">参考号</param>
        /// <returns>标签扫描记录列表</returns>
        Task<List<LabelScanEntity>> GetByReferenceNumberAsync(string referenceNumber);

        /// <summary>
        /// 根据尾程跟踪单号获取标签扫描记录列表
        /// </summary>
        /// <param name="finalMileTrackingNumber">尾程跟踪单号</param>
        /// <returns>标签扫描记录列表</returns>
        Task<List<LabelScanEntity>> GetByFinalMileTrackingNumberAsync(string finalMileTrackingNumber);

        /// <summary>
        /// 根据客户ID获取标签扫描记录列表
        /// </summary>
        /// <param name="customerId">客户ID</param>
        /// <returns>标签扫描记录列表</returns>
        Task<List<LabelScanEntity>> GetByCustomerIdAsync(int customerId);

        /// <summary>
        /// 根据客户ID和中性面单单号获取标签扫描记录列表
        /// </summary>
        /// <param name="customerId">客户ID</param>
        /// <param name="neutralWaybillNumber">中性面单单号</param>
        /// <returns>标签扫描记录列表</returns>
        Task<List<LabelScanEntity>> GetByCustomerIdAndWaybillNumberAsync(int customerId, string neutralWaybillNumber);

        /// <summary>
        /// 统计客户的订单扫描次数
        /// </summary>
        /// <param name="customerId">客户ID</param>
        /// <param name="neutralWaybillNumber">中性面单单号（可选，不提供则统计所有订单）</param>
        /// <returns>扫描次数</returns>
        Task<int> CountScansByCustomerAndWaybillAsync(int customerId, string neutralWaybillNumber = null);

        /// <summary>
        /// 获取客户的扫描记录分组统计
        /// </summary>
        /// <param name="customerId">客户ID</param>
        /// <returns>按订单分组的扫描统计信息</returns>
        Task<Dictionary<string, int>> GetScanStatsByCustomerAsync(int customerId);

        /// <summary>
        /// 更新标签扫描记录
        /// </summary>
        /// <param name="entity">标签扫描记录实体</param>
        /// <returns>是否更新成功</returns>
        Task<bool> UpdateAsync(LabelScanEntity entity);

        /// <summary>
        /// 获取所有标签扫描记录
        /// </summary>
        /// <returns>标签扫描记录实体列表</returns>
        Task<List<LabelScanEntity>> GetAllAsync();

        /// <summary>
        /// 分页获取标签扫描记录
        /// </summary>
        /// <param name="page">页码</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="sortBy">排序字段</param>
        /// <param name="sortOrder">排序顺序</param>
        /// <param name="customerId">客户ID</param>
        /// <param name="referenceNumber">参考号</param>
        /// <param name="neutralWaybillNumber">中性面单单号</param>
        /// <param name="finalMileTrackingNumber">尾程跟踪单号</param>
        /// <param name="result">扫描结果</param>
        /// <returns>标签扫描记录DTO列表和总记录数</returns>
        Task<(List<MDL.DTOs.LabelScanWithCustomerDto>, int)> GetByPageAsync(int page, int pageSize, string sortBy, string sortOrder, int? customerId, string referenceNumber, string neutralWaybillNumber, string finalMileTrackingNumber, int? result, string startCreatedAt, string endCreatedAt);

        /// <summary>
        /// 根据中性面单单号获取最新的扫描记录
        /// </summary>
        /// <param name="neutralWaybillNumber">中性面单单号</param>
        /// <returns>最新的标签扫描记录</returns>
        Task<LabelScanEntity> GetLatestScanByWaybillAsync(string neutralWaybillNumber);

        /// <summary>
        /// 根据日期范围获取扫描记录
        /// </summary>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <returns>标签扫描记录列表</returns>
        Task<List<LabelScanEntity>> GetByDateRangeAsync(System.DateTime startDate, System.DateTime endDate);
    }
}