package com.xindazhou.vehicle.api;

import com.xindazhou.framework.common.pojo.CommonResult;
import com.xindazhou.vehicle.api.dto.bind.VehicleBindReqDTO;
import com.xindazhou.vehicle.api.dto.bind.VehicleBindRespDTO;
import com.xindazhou.vehicle.service.VehicleBindService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import java.util.List;

import static com.xindazhou.framework.common.pojo.CommonResult.success;

/**
 * 车辆绑定 API 实现类
 *
 * @author xindazhou
 */
@RestController
@Validated
public class VehicleBindApiImpl implements VehicleBindApi {

    @Resource
    private VehicleBindService vehicleBindService;

    @Override
    public CommonResult<Long> bindVehicle(VehicleBindReqDTO reqDTO) {
        Long bindId = vehicleBindService.bindVehicle(reqDTO);
        return success(bindId);
    }

    @Override
    public CommonResult<Boolean> unbindVehicle(Long id) {
        vehicleBindService.unbindVehicle(id);
        return success(true);
    }

    @Override
    public CommonResult<List<VehicleBindRespDTO>> listBindByVehicleId(Long vehicleId) {
        List<VehicleBindRespDTO> binds = vehicleBindService.listBindByVehicleId(vehicleId);
        return success(binds);
    }

    @Override
    public CommonResult<List<VehicleBindRespDTO>> listBindByUserId(Long userId, Integer userType) {
        List<VehicleBindRespDTO> binds = vehicleBindService.listBindByUserId(userId, userType);
        return success(binds);
    }

}

