import { Inject, Injectable } from '@nestjs/common'; import { COURIER_PROVIDER } from './courier.constants'; import type { BatchShipmentQuery, CreateShipmentInput, CreateShipmentResult, DeliveryCoverageResult, FreightEstimateResult, ICourierProvider, ShipmentDetail, ShipmentQuery, TrackCallbackResponse, TrackNode, } from './courier.types'; /** * 快递统一门面:业务层只依赖本 Service,不感知具体快递商实现。 */ @Injectable() export class CourierService { constructor(@Inject(COURIER_PROVIDER) private readonly provider: ICourierProvider) {} get activeProvider() { return this.provider.code; } createShipment(input: CreateShipmentInput): Promise { return this.provider.createShipment(input); } cancelShipment(query: ShipmentQuery): Promise { return this.provider.cancelShipment(query); } getShipment(query: ShipmentQuery): Promise { return this.provider.getShipment(query); } batchGetShipments(query: BatchShipmentQuery): Promise { return this.provider.batchGetShipments(query); } getTrack(query: ShipmentQuery): Promise { return this.provider.getTrack(query); } checkDeliveryCoverage(toAddress: string): Promise { return this.provider.checkDeliveryCoverage(toAddress); } estimateFreight(weight: number): Promise { return this.provider.estimateFreight(weight); } buildTrackCallbackResponse(success?: boolean): TrackCallbackResponse { return this.provider.buildTrackCallbackResponse(success); } }