package com.seer.teach.mall.order.service.impl;

import com.seer.teach.common.enums.ResultCodeEnum;
import com.seer.teach.common.utils.AssertUtils;
import com.seer.teach.mall.entity.OrderEntity;
import com.seer.teach.mall.factory.LogisticsServiceFactory;
import com.seer.teach.mall.order.service.IAdminLogisticsService;
import com.seer.teach.mall.service.ILogisticsService;
import com.seer.teach.mall.service.IOrderService;
import com.seer.teach.mall.shipping.jt.resp.TraceResp;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class AdminLogisticsServiceImpl implements IAdminLogisticsService {

    private final LogisticsServiceFactory logisticsServiceFactory;

    private final IOrderService orderService;

    @Override
    public List<TraceResp> getLogisticsTrace(String orderSn) {
        OrderEntity order = orderService.getOneByOrderSn(orderSn);
        AssertUtils.notNull(order, ResultCodeEnum.ORDER_NOT_FOUND);

        ILogisticsService logisticsService = logisticsServiceFactory.getService(order.getLogisticsCode());

        return logisticsService.queryLogisticsTrace(order.getShippingNo());
    }
}