package com.erp.order.service;

import com.erp.order.dto.request.*;
import com.erp.order.dto.response.*;
import com.erp.order.entity.Order;
import java.util.List;
import java.util.Map;

public interface OrderService {

    // ============ 订单查询 ============

    /**
     * 分页查询订单列表
     */
    OrderPageResponse listOrders(OrderQueryRequest request);

    /**
     * 获取订单详情
     */
    OrderResponse getOrder(Long id);

    /**
     * 根据订单短ID查询
     */
    OrderResponse getOrderByShortId(String shortId);

    // ============ 待审核 & 待匹配订单查询 ============

    /**
     * 分页查询待审核订单（audit_status = 'pending'）
     */
    OrderPageResponse listPendingAuditOrders(String platform, Long shopId, String keyword, int page, int limit);

    /**
     * 分页查询待匹配订单（存在订单项但 erp_sku_id 未匹配的订单）
     */
    OrderPageResponse listPendingMatchOrders(String platform, Long shopId, String keyword, int page, int limit);

    // ============ 订单创建 & 拉取 ============

    /**
     * 从平台拉取订单
     */
    PullOrdersResult pullOrders(PullOrdersRequest request);

    /**
     * 批量创建订单（内部使用）
     */
    int createOrders(List<OrderCreateRequest> orders);

    // ============ 订单审核 ============

    /**
     * 单个审核订单
     */
    OrderResponse auditOrder(Long orderId, String action, String comment, OperatorInfo operator);

    /**
     * 批量审核订单
     */
    BatchOperationResult batchAudit(BatchAuditRequest request, OperatorInfo operator);

    // ============ 仓库 & 发货 ============

    /**
     * 设置仓库和快递信息
     */
    OrderResponse setWarehouseExpress(Long orderId, SetWarehouseExpressRequest request, OperatorInfo operator);

    /**
     * 订单发货（扣减库存）
     */
    OrderResponse shipOrder(Long orderId, ShipOrderRequest request, OperatorInfo operator);

    // ============ 订单状态流转 ============

    /**
     * 完成订单
     */
    OrderResponse completeOrder(Long orderId, OperatorInfo operator);

    /**
     * 取消订单
     */
    OrderResponse cancelOrder(Long orderId, String reason, OperatorInfo operator);

    // ============ 批量操作 ============

    /**
     * 批量操作
     */
    BatchOperationResult batchOperation(BatchOperationRequest request, OperatorInfo operator);

    // ============ 统计 & 导出 ============

    /**
     * 订单统计
     */
    OrderStatisticsResponse getStatistics(OrderQueryRequest request);

    /**
     * 仪表盘统计
     */
    DashboardStatsResponse getDashboardStats();

    /**
     * 导出订单
     */
    ExportResult exportOrders(OrderQueryRequest request, String exportType);

    // ============ 备注 & 日志 ============

    /**
     * 更新订单备注
     */
    OrderResponse updateRemark(Long orderId, String remark, OperatorInfo operator);

    /**
     * 获取订单操作日志
     */
    List<OperationLogResponse> getOrderLogs(Long orderId);

    /**
     * 同步订单到平台
     */
    OrderResponse syncToPlatform(Long orderId, OperatorInfo operator);

    // ============ 辅助方法 ============

    /**
     * 获取订单状态选项
     */
    List<StatusOption> getOrderStatusOptions();

    /**
     * 获取审核状态选项
     */
    List<StatusOption> getAuditStatusOptions();

    /**
     * 获取发货状态选项
     */
    List<StatusOption> getDeliveryStatusOptions();

    /**
     * 获取平台选项
     */
    List<StatusOption> getPlatformOptions();

    /**
     * 获取店铺选项
     */
    List<ShopOption> getShopOptions();

    // ============ 内部结果类 ============

    @lombok.Data
    @lombok.Builder
    class PullOrdersResult {
        private int count;
        private List<String> createdOrderIds;
    }

    @lombok.Data
    @lombok.Builder
    class ExportResult {
        private String filename;
        private int count;
        private List<java.util.Map<String, Object>> data;
        private List<String> headers;
    }

    @lombok.Data
    @lombok.Builder
    class StatusOption {
        private String value;
        private String label;
    }

    @lombok.Data
    @lombok.Builder
    class ShopOption {
        private Long value;
        private String label;
    }

    @lombok.Data
    @lombok.Builder
    class OperatorInfo {
        private Long operatorId;
        private String operatorName;
        private String ip;
        private String userAgent;
    }
}
