package com.sckw.transport.handler;


import com.sckw.core.common.enums.enums.ErrorCodeEnum;
import com.sckw.core.exception.BusinessPlatfromException;
import com.sckw.core.model.enums.CarWaybillV1Enum;
import com.sckw.transport.model.KwtWaybillOrder;
import com.sckw.transport.model.param.WaybillOrderLoadingParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * Author: donglang
 * Time: 2025-11-19
 * Des: 已装货 -手动推推送数据
 * Version: 1.0
 */
@Slf4j
@Service
public class LoadingHandler extends AbstractWaybillOrderHandler<WaybillOrderLoadingParam>{

    @Override
    protected KwtWaybillOrder getWaybillOrder(WaybillOrderLoadingParam param) {
        return getWaybillOrder(param.getWaybillOrderId());
    }

    @Override
    protected void checkState(WaybillOrderLoadingParam param, KwtWaybillOrder waybillOrder) {
        if (!Objects.equals(CarWaybillV1Enum.REFUSE_TRAFFIC.getCode(), waybillOrder.getStatus())) {
            throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_STATUS_ERROR, "运单状态非到达装货地点, 无法推进下一节点！");
        }
    }

    @Override
    protected void doBusiness(WaybillOrderLoadingParam param, KwtWaybillOrder waybillOrder) {
        // 装货无额外业务逻辑
    }

    @Override
    protected void updateStatus(WaybillOrderLoadingParam param, KwtWaybillOrder waybillOrder) {
        // 已装货状态
        waybillOrder.setStatus(CarWaybillV1Enum.EXIT_COMPLETED.getCode());
        waybillOrderRepository.updateById(waybillOrder);
    }

    @Override
    protected String getProcessName() {
        return "已装货";
    }

    @Override
    protected String getRemark(WaybillOrderLoadingParam param, KwtWaybillOrder waybillOrder) {
        return "[" + waybillOrder.getDriverName() + "]已装载完成";
    }
}
