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

namespace BLL.Interfaces
{
    /// <summary>
    /// 标签扫描服务接口
    /// </summary>
    public interface ILabelScanService
    {
        /// <summary>
        /// 记录标签扫描
        /// </summary>
        /// <param name="customerId">客户ID</param>
        /// <param name="neutralWaybillNumber">中性面单单号</param>
        /// <param name="result">扫描结果</param>
        /// <param name="createdBy">创建人</param>
        /// <param name="referenceNumber">参考号</param>
        /// <param name="finalMileTrackingNumber">尾程跟踪单号</param>
        /// <param name="description">描述</param>
        /// <returns>创建的标签扫描记录</returns>
        Task<LabelScanEntity> RecordScanAsync(int customerId, string neutralWaybillNumber, ScanResult result, string createdBy,
            string? referenceNumber = null, string? finalMileTrackingNumber = null, string? description = null,
            string? deviceCode = null, string? deviceName = null);

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


        Task<List<LabelScanEntity>> GetScanRecordsByNeutralWaybillNumbersAsync(List<string> neutralWaybillNumbers);

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

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

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

        /// <summary>
        /// 根据客户ID和中性面单单号获取扫描记录列表
        /// </summary>
        /// <param name="customerId">客户ID</param>
        /// <param name="neutralWaybillNumber">中性面单单号</param>
        /// <returns>标签扫描记录列表</returns>
        Task<List<LabelScanEntity>> GetScanRecordsByCustomerIdAndWaybillNumberAsync(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>
        /// <returns>标签扫描记录实体列表</returns>
        Task<List<LabelScanEntity>> GetAllLabelScanRecordsAsync();

        /// <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)> GetLabelScanRecordsByPageAsync(int page, int pageSize, string sortBy, string sortOrder, int? customerId, string referenceNumber, string neutralWaybillNumber, string finalMileTrackingNumber, int? result, string startCreatedAt, string endCreatedAt);

        /// <summary>
        /// 获取当天扫描后未下单数量
        /// </summary>
        /// <returns>当天未下单数据</returns>
        Task<MDL.DTOs.TodayUnorderedDataDto> GetTodayUnorderedCountAsync();

        /// <summary>
        /// 获取指定条件的最新扫描记录（按订单号分组，取最新的一条）
        /// </summary>
        /// <param name="waybillNumbers">中性面单单号列表（可选）</param>
        /// <param name="startTime">开始时间（可选）</param>
        /// <param name="endTime">结束时间（可选）</param>
        /// <param name="customerId">客户ID（可选）</param>
        /// <returns>最新扫描记录列表</returns>
        Task<List<LabelScanEntity>> GetLatestScanRecordsAsync(
            List<string> waybillNumbers = null,
            DateTime? startTime = null,
            DateTime? endTime = null,
            int? customerId = null);
    }
}