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


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

@Mapper
public interface UserMapper {


    @Results(id = "user", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.VARCHAR),
            @Result(column = "role_code", property = "roleCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "use_type", property = "useType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_user_id", property = "createUserId", jdbcType = JdbcType.VARCHAR)
    })
    @Select("select id,\n" +
            "       role_code,\n" +
            "       use_type,\n" +
            "       create_user_id\n" +
            "from system_user\n" +
            "where id = #{userId}")
    UserEntity selectById(@Param("userId") String userId);

    @ResultMap("user")
    @Select("select su.id,\n" +
            "       su.role_code,\n" +
            "       su.use_type,\n" +
            "       su.create_user_id\n" +
            "from system_user su\n" +
            "where su.id = (select smp.create_user_id from simulation_manual_project smp where smp.id = #{projectId})\n")
    UserEntity selectByManualProjectId(@Param("projectId") String projectId);

    @ResultMap("user")
    @Select("select su.id,\n" +
        "       su.role_code,\n" +
        "       su.use_type,\n" +
        "       su.create_user_id\n" +
        "from system_user su\n" +
        "where su.id = (select smp.project_user_id from multi_simulation_project smp where smp.id = #{projectId})\n")
    UserEntity selectByMultiManualProjectId(@Param("projectId") String projectId);

    @ResultMap("user")
    @Select("select su.id,\n" +
            "       su.role_code,\n" +
            "       su.use_type,\n" +
            "       su.create_user_id\n" +
            "from system_user su\n" +
            "where su.id = (select sas.create_user_id from simulation_automatic_subproject sas where sas.id = #{projectId})\n")
    UserEntity selectByAutoSubProjectId(String projectId);
}
