package com.payment_system.service;

import com.payment_system.entity.Car;
import com.payment_system.entity.CarInfo;
import com.payment_system.mapper.CarMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class CarService {
    @Autowired
    private CarMapper carMapper;

    public boolean bind(Car car){
        Car c2 = carMapper.findByNo(car.getNumber());
        if (c2 != null) {
            return false;
        }else {
            car.setBindTime(LocalDateTime.now());
            carMapper.insert(car);
            return true;
        }
    }

    public void unbind(Long userId){
        carMapper.delete(userId);
    }

    public boolean judge(long userId){
        Car c1 = carMapper.findById(userId);
        if(c1 != null){
            return true;
        }else{
            return false;
        }
    }

    public CarInfo query(long userId){
        CarInfo info = carMapper.query(userId);
        return info;
    }
}
