package com.css.simulation.resource.server.infra.db.mysql.mapper;

import api.common.pojo.po.model.ConfigPO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ModelConfigMapper {
    @Select("select is_deleted\n" +
            "from model_config\n" +
            "where id = #{configId}")
    String selectIsDeletedByConfigId(@Param("configId") String configId);

    @Update("update model_config\n" +
            "set is_unavailable = #{po.isUnavailable}\n" +
            "where id in (select config_id\n" +
            "             from relation_config_sensor\n" +
            "             where is_deleted = '0'" +
            "               and sensor_id = #{po.sensorId})")
    void updateIsUnavailableBySensorId(@Param("po") ConfigPO configPO);

    @Update("update model_config\n" +
            "set is_unavailable = '1'\n" +
            "where vehicle_id = #{po.vehicleId}")
    void updateIsUnavailableByVehicleId(@Param("po") ConfigPO configPO);

    @Select("select is_unavailable\n" +
            "from model_config\n" +
            "where id = #{modelConfigId}")
    String selectIsUnavailableByModelConfigId(@Param("modelConfigId")String modelConfigId);
}
