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


import com.css.simulation.resource.scheduler.infra.entity.IndexTemplateEntity;
import com.css.simulation.resource.scheduler.infra.entity.SceneEntity;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * 场景查询
 * scene_natural
 * scene_standard
 * scene_accident
 */
@Mapper
public interface SceneMapper {


    @Results(id = "scenes", value = {
            @Result(column = "scene_natural_ids", property = "scenarioOsc", jdbcType = JdbcType.VARCHAR),
            @Result(column = "scene_traffic_ids", property = "scenarioOdr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "scene_statue_ids", property = "scenarioOsgb", jdbcType = JdbcType.VARCHAR)
    })
    @Select("select scene_natural_ids,\n" +
            "       scene_traffic_ids,\n" +
            "       scene_statue_ids\n" +
            "from scene_package_sublist sps\n" +
            "         left join scene_package sp on parent_id = sp.package_id\n" +
            "where parent_id = '#{packageId}'\n" +
            "  and ((scene_natural_ids is not null and scene_natural_ids != '')\n" +
            "    or (scene_traffic_ids is not null and scene_traffic_ids != '')\n" +
            "    or (scene_statue_ids is not null and scene_statue_ids != ''))")
    List<IndexTemplateEntity> selectLeafIndexByPackageId(@Param("packageId") String packageId);


    @Results(id = "scene", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.VARCHAR),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "type", property = "type", jdbcType = JdbcType.VARCHAR),
            @Result(column = "osc", property = "scenarioOsc", jdbcType = JdbcType.VARCHAR),
            @Result(column = "osgb", property = "scenarioOsgb", jdbcType = JdbcType.VARCHAR),
            @Result(column = "odr", property = "scenarioOdr", jdbcType = JdbcType.VARCHAR)
    })
    @Select("<script>" +
            "select natural_id id,\n" +
            "       natural_name name,\n" +
            "        '1' type,\n" +
            "       xosc_address osc,\n" +
            "       osgb_address osgb,\n" +
            "       xodr_address odr\n" +
            "from scene_natural\n" +
            "where 1=1\n" +
            "<if test='idList != null and idList.size() > 0'>\n" +
            "   and natural_id in\n" +
            "       <foreach collection='idList' index='index' item='item' open='(' close=')' separator=','>\n" +
            "           #{item}" +
            "       </foreach>\n" +
            "</if>\n" +
            "</script>")
    List<SceneEntity> selectNaturalByIdList(@Param("idList") List<String> idList);


    @ResultMap("scene")
    @Select("<script>" +
            "select regulations_id id,\n" +
            "       scene_name name,\n" +
            "        '2'  type,\n" +
            "       xml_address osc,\n" +
            "       osgb_address osgb,\n" +
            "       xodr_address odr\n" +
            "from scene_standards_regulations\n" +
            "where 1=1\n" +
            "<if test='idList != null and idList.size() > 0'>\n" +
            "   and regulations_id in\n" +
            "       <foreach collection='idList' index='index' item='item' open='(' close=')' separator=','>\n" +
            "           #{item}" +
            "       </foreach>\n" +
            "</if>\n" +
            "</script>")
    List<SceneEntity> selectStandardByIdList(@Param("idList") List<String> idList);

    @ResultMap("scene")
    @Select("<script>" +
            "select accident_id id,\n" +
            "       scene_name name,\n" +
            "        '3'  type,\n" +
            "       xml_address osc,\n" +
            "       osgb_address osgb,\n" +
            "       xodr_address odr\n" +
            "from scene_accident\n" +
            "where 1=1\n" +
            "<if test='idList != null and idList.size() > 0'>\n" +
            "   and accident_id in\n" +
            "       <foreach collection='idList' index='index' item='item' open='(' close=')' separator=','>\n" +
            "           #{item}" +
            "       </foreach>\n" +
            "</if>\n" +
            "</script>")
    List<SceneEntity> selectAccidentByIdList(@Param("idList") List<String> idList);

    @ResultMap("scene")
    @Select("<script>" +
            "select id           id,\n" +
            "       scene_id     name,\n" +
            "       '4'          type,\n" +
            "       xosc_address osc,\n" +
            "       osgb_address osgb,\n" +
            "       xodr_address odr\n" +
            "from scene_general_data\n" +
            "where 1 = 1\n\n" +
            "<if test='idList != null and idList.size() > 0'>\n" +
            "   and id in\n" +
            "       <foreach collection='idList' index='index' item='item' open='(' close=')' separator=','>\n" +
            "           #{item}" +
            "       </foreach>\n" +
            "</if>\n" +
            "</script>")
    List<SceneEntity> selectGeneralizationByIdList(@Param("idList")List<String> idList);

    @ResultMap("scene")
    @Select("<script>" +
            "select scene_id           id,\n" +
            "       scene_name     name,\n" +
            "       '5'          type,\n" +
            "       xml_address osc,\n" +
            "       osgb_address osgb,\n" +
            "       xodr_address odr\n" +
            "from scene_reference_lib\n" +
            "where 1 = 1\n\n" +
            "<if test='idList != null and idList.size() > 0'>\n" +
            "   and scene_id in\n" +
            "       <foreach collection='idList' index='index' item='item' open='(' close=')' separator=','>\n" +
            "           #{item}" +
            "       </foreach>\n" +
            "</if>\n" +
            "</script>")
    List<SceneEntity> selectReferenceLibByIdList(@Param("idList")List<String> idList);
}
