package com.xindazhou.vehicle.dal.mysql.binding;

import com.xindazhou.framework.mybatis.core.mapper.BaseMapperX;
import com.xindazhou.vehicle.dal.dataobject.binding.UserVehicleBindingDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 用户-车辆关系 Mapper
 *
 * @author xindazhou
 */
@Mapper
public interface UserVehicleBindingMapper extends BaseMapperX<UserVehicleBindingDO> {

    /**
     * 根据用户ID查询绑定关系列表
     *
     * @param userId 用户ID
     * @return 绑定关系列表
     */
    default List<UserVehicleBindingDO> selectListByUserId(Long userId) {
        return selectList(UserVehicleBindingDO::getUserId, userId,
                UserVehicleBindingDO::getDeleted, false);
    }

    /**
     * 根据车辆ID查询绑定关系列表
     *
     * @param vehicleId 车辆ID
     * @return 绑定关系列表
     */
    default List<UserVehicleBindingDO> selectListByVehicleId(Long vehicleId) {
        return selectList(UserVehicleBindingDO::getVehicleId, vehicleId,
                UserVehicleBindingDO::getDeleted, false);
    }

    /**
     * 根据用户ID和车辆ID查询绑定关系
     *
     * @param userId 用户ID
     * @param vehicleId 车辆ID
     * @return 绑定关系
     */
    default UserVehicleBindingDO selectByUserIdAndVehicleId(Long userId, Long vehicleId) {
        return selectOne(UserVehicleBindingDO::getUserId, userId,
                UserVehicleBindingDO::getVehicleId, vehicleId,
                UserVehicleBindingDO::getDeleted, false);
    }

    /**
     * 查询用户的默认车辆
     *
     * @param userId 用户ID
     * @return 默认车辆绑定关系
     */
    default UserVehicleBindingDO selectDefaultByUserId(Long userId) {
        return selectOne(UserVehicleBindingDO::getUserId, userId,
                UserVehicleBindingDO::getIsDefault, 1,
                UserVehicleBindingDO::getDeleted, false);
    }

}

