package com.erp.waybill.service;

import com.erp.waybill.dto.*;
import com.erp.waybill.entity.LogisticsTrace;
import com.erp.waybill.entity.Waybill;
import com.erp.waybill.entity.WaybillStatus;

import java.util.List;

/**
 * 运单服务接口
 */
public interface WaybillService {

    // ==================== 运单管理 ====================

    /**
     * 申请电子面单
     */
    WaybillResponse applyWaybill(WaybillApplyRequest request, Long operatorId);

    /**
     * 批量申请电子面单
     */
    BatchApplyResult batchApplyWaybill(BatchApplyRequest request, Long operatorId);

    /**
     * 查询运单详情
     */
    WaybillResponse getWaybill(Long waybillId);

    /**
     * 根据运单号查询
     */
    WaybillResponse getWaybillByNo(String waybillNo);

    /**
     * 查询订单的所有运单
     */
    List<WaybillResponse> getWaybillsByOrderId(Long orderId);

    /**
     * 作废运单
     */
    WaybillResponse voidWaybill(WaybillVoidRequest request);

    // ==================== 打印管理 ====================

    /**
     * 打印运单（首次打印）
     */
    PrintResult printWaybill(Long waybillId, Long operatorId);

    /**
     * 补打运单
     */
    PrintResult reprintWaybill(Long waybillId, Long operatorId);

    /**
     * 换单号（面单破损）
     */
    ChangeWaybillNoResult changeWaybillNo(Long waybillId, String reason, Long operatorId);

    // ==================== 取消管理 ====================

    /**
     * 取消运单
     */
    boolean cancelWaybill(WaybillCancelRequest request);

    // ==================== 状态跟踪 ====================

    /**
     * 查询运单物流状态
     */
    WaybillStatus getTrackingStatus(String waybillNo);

    /**
     * 查询物流轨迹明细
     */
    List<LogisticsTrace> getLogisticsTraces(String waybillNo);

    /**
     * 同步运单状态（从快递API拉取）
     */
    WaybillStatus syncTrackingStatus(String waybillNo);

    /**
     * 批量同步待跟踪运单状态
     */
    int batchSyncTrackingStatus(int limit);

    // ==================== 打印日志 ====================

    /**
     * 查询打印日志
     */
    List<com.erp.waybill.entity.PrintLog> getPrintLogs(Long orderId);

    // ==================== 结果封装 ====================

    record BatchApplyResult(
            List<WaybillResponse> success,
            List<BatchError> errors
    ) {
        public record BatchError(Long orderId, String error) {}
    }

    record PrintResult(
            String waybillNo,
            String printContent
    ) {}

    record ChangeWaybillNoResult(
            String oldWaybillNo,
            String newWaybillNo
    ) {}
}
