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

import api.common.pojo.param.project.MultiSimulationSceneCarParam;
import api.common.pojo.param.project.MultiSimulationSceneParam;
import api.common.pojo.po.project.MultiSimulationScenePO;
import api.common.pojo.vo.project.MultiSimulationSceneCarVO;
import api.common.pojo.vo.project.MultiSimulationSceneVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MultiSimulationSceneCarMapper {
    @Insert("insert into multi_simulation_scene_car (id,scene_id,car_id,algorithm_id,algorithm_type,map_id,path_id,path_start,path_end,car_sort,is_simulation_car) values" +
        "(#{sceneCarId},#{sceneId},#{carId},#{algorithmId},#{algorithmType},#{mapId},#{pathId},#{pathStartStr},#{pathEndStr},#{carSort},#{isSimulationCar})")
    int addMultiSimulationSceneCar(MultiSimulationSceneCarParam param);

    @Select("select count(*) from multi_simulation_scene_car where scene_id = #{sceneId} and deleted = 0")
    int selectSceneCarNumsBySceneId(@Param("sceneId") String sceneId);


    @Update("<script>" +
        "update multi_simulation_scene_car set car_id = #{carId},algorithm_id = #{algorithmId}, algorithm_type = #{algorithmType}, map_id = #{mapId}, path_id = #{pathId}," +
        "path_start = #{pathStartStr},path_end = #{pathEndStr},car_sort = #{carSort} " +
        "where id = #{sceneCarId}" +
        "</script>")
    int updateMultiSimulationSceneCar(MultiSimulationSceneCarParam param);

    @Update("<script>" +
        "update multi_simulation_scene_car set is_simulation_car = #{isSimulationCar} " +
        "where id = #{id}" +
        "</script>")
    int updateMultiSimulationSceneCarView(@Param("id") String id, @Param("isSimulationCar") Integer isSimulationCar);

    @Update("update multi_simulation_scene_car set deleted = 1 where id = #{sceneCarId}")
    int deleteMultiSimulationSceneCar(MultiSimulationSceneCarParam param);
//
    @Select("<script>" +
        "select id,scene_id,car_id,algorithm_id,algorithm_type,map_id,path_id,path_start,path_end,car_sort,is_simulation_car,create_time from multi_simulation_scene_car where deleted = 0 " +
        "and scene_id = #{sceneId} " +

        "<if test='mapId != null'> " +
        " AND map_id = #{mapId}" +
        "</if>" +

        "order by car_sort, create_time desc" +
        "</script>")
    List<MultiSimulationSceneCarVO> selectSceneCarList(MultiSimulationSceneCarParam param);

    @Select("<script>" +
        "select id,scene_id,car_id,algorithm_id,algorithm_type,path_id,path_start,path_end,car_sort,create_time from multi_simulation_scene_car where deleted = 0 " +
        "and id = #{sceneCarId}" +
        "</script>")
    MultiSimulationSceneCarVO selectSceneCarById(MultiSimulationSceneCarParam param);

}
