package top.imwork.assist.generator.config;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import top.imwork.assist.generator.dao.*;
import top.imwork.commons.core.exception.BusinessException;

@Configuration
public class DbConfig {
    @Value("${imwork.database}")
    private String database;
    @Autowired
    private MySQLMapper mySQLMapper;
    @Autowired
    private OracleMapper oracleMapper;
    @Autowired
    private SQLServerMapper sqlServerMapper;
    @Autowired
    private PostgreSQLMapper postgreSQLMapper;

    @Bean
    @Primary
    public BaseMapper getGeneratorDao(){
        if("mysql".equalsIgnoreCase(database)){
            return mySQLMapper;
        }else if("oracle".equalsIgnoreCase(database)){
            return oracleMapper;
        }else if("sqlserver".equalsIgnoreCase(database)){
            return sqlServerMapper;
        }else if("postgresql".equalsIgnoreCase(database)){
            return postgreSQLMapper;
        }else {
            throw new BusinessException("不支持当前数据库：" + database);
        }
    }
}
