package com.xindazhou.vehicle.service.impl;

import com.xindazhou.framework.common.exception.util.ServiceExceptionUtil;
import com.xindazhou.vehicle.api.dto.status.VehicleStatusRespDTO;
import com.xindazhou.vehicle.convert.status.VehicleStatusConvert;
import com.xindazhou.vehicle.dal.dataobject.status.VehicleStatusDO;
import com.xindazhou.vehicle.dal.mysql.status.VehicleStatusMapper;
import com.xindazhou.vehicle.service.VehicleStatusService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import static com.xindazhou.vehicle.enums.ErrorCodeConstants.VEHICLE_STATUS_NOT_EXISTS;

/**
 * 车辆状态 Service 实现类
 *
 * @author xindazhou
 */
@Service
@Slf4j
public class VehicleStatusServiceImpl implements VehicleStatusService {

    @Resource
    private VehicleStatusMapper vehicleStatusMapper;

    @Override
    public VehicleStatusRespDTO getVehicleStatus(Long vehicleId) {
        VehicleStatusDO status = vehicleStatusMapper.selectByVehicleId(vehicleId);
        if (status == null) {
            // 如果状态不存在，返回默认状态或从TSP平台查询
            // TODO: 可以从TSP平台查询实时状态
            throw ServiceExceptionUtil.exception(VEHICLE_STATUS_NOT_EXISTS);
        }
        return VehicleStatusConvert.INSTANCE.convert(status);
    }

}

