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

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

@Mapper
public interface VehicleMapper {

    @Results(id = "vehicle", value = {
            @Result(column = "model_label", property = "modelLabel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "max_speed", property = "maxSpeed", jdbcType = JdbcType.DECIMAL),
            @Result(column = "engine_power", property = "enginePower", jdbcType = JdbcType.DECIMAL),
            @Result(column = "max_deceleration", property = "maxDeceleration", jdbcType = JdbcType.DECIMAL),
            @Result(column = "max_steering_angle", property = "maxSteeringAngle", jdbcType = JdbcType.DECIMAL),
            @Result(column = "mass", property = "mass", jdbcType = JdbcType.DECIMAL),
            @Result(column = "front_surface_effective", property = "frontSurfaceEffective", jdbcType = JdbcType.DECIMAL),
            @Result(column = "air_drag_coefficient", property = "airDragCoefficient", jdbcType = JdbcType.DECIMAL),
            @Result(column = "rolling_resistance_coefficient", property = "rollingResistanceCoefficient", jdbcType = JdbcType.DECIMAL),
            @Result(column = "wheel_diameter", property = "wheelDiameter", jdbcType = JdbcType.DECIMAL),
            @Result(column = "wheel_drive", property = "wheelDrive", jdbcType = JdbcType.VARCHAR),
            @Result(column = "overall_efficiency", property = "overallEfficiency", jdbcType = JdbcType.DECIMAL),
            @Result(column = "front_distance", property = "frontDistance", jdbcType = JdbcType.DECIMAL),
            @Result(column = "rear_distance", property = "rearDistance", jdbcType = JdbcType.DECIMAL),
            @Result(column = "left_distance", property = "leftDistance", jdbcType = JdbcType.DECIMAL),
            @Result(column = "right_distance", property = "rightDistance", jdbcType = JdbcType.DECIMAL),
            @Result(column = "height_distance", property = "heightDistance", jdbcType = JdbcType.DECIMAL),
            @Result(column = "wheelbase", property = "wheelbase", jdbcType = JdbcType.DECIMAL),
    })
    @Select("select model_label,\n" +
            "       max_speed,\n" +
            "       engine_power,\n" +
            "       max_deceleration,\n" +
            "       max_steering_angle,\n" +
            "       mass,\n" +
            "       front_surface_effective,\n" +
            "       air_drag_coefficient,\n" +
            "       rolling_resistance_coefficient,\n" +
            "       wheel_diameter,\n" +
            "       wheel_drive,\n" +
            "       overall_efficiency,\n" +
            "       front_distance,\n" +
            "       rear_distance,\n" +
            "       left_distance,\n" +
            "       right_distance,\n" +
            "       height_distance,\n" +
            "       wheelbase\n" +
            "from model_vehicle\n" +
            "where id = (select mc.vehicle_id\n" +
            "    from model_config mc\n" +
            "    where mc.id = #{vehicleConfigId})")
    VehicleEntity selectByVehicleConfigId(@Param("vehicleConfigId") String vehicleConfigId);

    @Select("select par_file_path\n" +
            "from model_vehicle\n" +
            "where id = (select vehicle_id\n" +
            "            from model_config\n" +
            "            where id = #{vehicleConfigId})")
    String selectParPathByVehicleConfigId(@Param("vehicleConfigId") String vehicleConfigId);
}
