using TakeoutSaaS.Domain.Orders.Entities;
using TakeoutSaaS.Domain.Orders.Enums;
using TakeoutSaaS.Domain.Deliveries.Entities;
using TakeoutSaaS.Domain.Payments.Entities;
using TakeoutSaaS.Domain.Payments.Enums;
namespace TakeoutSaaS.Domain.Orders.Repositories;
///
/// 订单聚合仓储契约。
///
public interface IOrderRepository
{
///
/// 依据标识获取订单。
///
/// 订单 ID。
/// 租户 ID。
/// 取消标记。
/// 订单实体或 null。
Task FindByIdAsync(long orderId, long tenantId, CancellationToken cancellationToken = default);
///
/// 依据订单号获取订单。
///
/// 订单号。
/// 租户 ID。
/// 取消标记。
/// 订单实体或 null。
Task FindByOrderNoAsync(string orderNo, long tenantId, CancellationToken cancellationToken = default);
///
/// 按状态筛选订单列表。
///
/// 租户 ID。
/// 订单状态。
/// 支付状态。
/// 取消标记。
/// 订单集合。
Task> SearchAsync(long tenantId, OrderStatus? status, PaymentStatus? paymentStatus, CancellationToken cancellationToken = default);
///
/// 全部订单列表筛选查询。
///
/// 租户 ID。
/// 门店 ID。
/// 开始时间(含)。
/// 结束时间(不含)。
/// 订单状态。
/// 履约方式。
/// 支付方式。
/// 关键词(订单号/手机号)。
/// 取消标记。
/// 订单集合。
Task> SearchAllOrdersAsync(
long tenantId,
long? storeId,
DateTime? startAt,
DateTime? endAt,
OrderStatus? status,
DeliveryType? deliveryType,
PaymentMethod? paymentMethod,
string? keyword,
CancellationToken cancellationToken = default);
///
/// 获取订单明细行。
///
/// 订单 ID。
/// 租户 ID。
/// 取消标记。
/// 订单明细集合。
Task> GetItemsAsync(long orderId, long tenantId, CancellationToken cancellationToken = default);
///
/// 按订单集合读取明细。
///
/// 订单 ID 集合。
/// 租户 ID。
/// 取消标记。
/// 订单明细字典。
Task>> GetItemsByOrderIdsAsync(
IReadOnlyCollection orderIds,
long tenantId,
CancellationToken cancellationToken = default);
///
/// 获取订单状态流转记录。
///
/// 订单 ID。
/// 租户 ID。
/// 取消标记。
/// 状态变更记录列表。
Task> GetStatusHistoryAsync(long orderId, long tenantId, CancellationToken cancellationToken = default);
///
/// 获取订单退款申请。
///
/// 订单 ID。
/// 租户 ID。
/// 取消标记。
/// 退款申请列表。
Task> GetRefundsAsync(long orderId, long tenantId, CancellationToken cancellationToken = default);
///
/// 按订单集合查询已退款订单 ID。
///
/// 订单 ID 集合。
/// 租户 ID。
/// 取消标记。
/// 已退款订单 ID 集合。
Task> GetRefundedOrderIdsAsync(
IReadOnlyCollection orderIds,
long tenantId,
CancellationToken cancellationToken = default);
///
/// 获取订单最近支付记录。
///
/// 订单 ID。
/// 租户 ID。
/// 取消标记。
/// 支付记录或 null。
Task GetLatestPaymentRecordAsync(long orderId, long tenantId, CancellationToken cancellationToken = default);
///
/// 获取订单最近配送单。
///
/// 订单 ID。
/// 租户 ID。
/// 取消标记。
/// 配送单或 null。
Task GetLatestDeliveryOrderAsync(long orderId, long tenantId, CancellationToken cancellationToken = default);
///
/// 新增订单。
///
/// 订单实体。
/// 取消标记。
/// 异步任务。
Task AddOrderAsync(Order order, CancellationToken cancellationToken = default);
///
/// 新增订单明细。
///
/// 明细集合。
/// 取消标记。
/// 异步任务。
Task AddItemsAsync(IEnumerable items, CancellationToken cancellationToken = default);
///
/// 新增订单状态记录。
///
/// 状态记录。
/// 取消标记。
/// 异步任务。
Task AddStatusHistoryAsync(OrderStatusHistory history, CancellationToken cancellationToken = default);
///
/// 新增退款申请。
///
/// 退款申请实体。
/// 取消标记。
/// 异步任务。
Task AddRefundAsync(RefundRequest refund, CancellationToken cancellationToken = default);
///
/// 持久化变更。
///
/// 取消标记。
/// 异步任务。
Task SaveChangesAsync(CancellationToken cancellationToken = default);
///
/// 更新订单。
///
/// 订单实体。
/// 取消标记。
/// 异步任务。
Task UpdateOrderAsync(Order order, CancellationToken cancellationToken = default);
///
/// 删除订单。
///
/// 订单 ID。
/// 租户 ID。
/// 取消标记。
/// 异步任务。
Task DeleteOrderAsync(long orderId, long tenantId, CancellationToken cancellationToken = default);
}