package tech.easyflow.datacenter.utils;

import org.junit.Assert;
import org.junit.Test;

import java.util.List;

/**
 * {@link SqlSupportUtils} 内部 MySQL SQL 重写测试。
 */
public class SqlSupportUtilsTest {

    /**
     * 验证逻辑目录只用于表匹配，执行 SQL 使用内部物理表。
     */
    @Test
    public void resolveInternalMysqlShouldDropLogicalCatalog() {
        SqlSupportUtils.ResolvedSql resolved = SqlSupportUtils.resolveInternalMysql(
                """
                        SELECT "token", "token_1"
                        FROM "ama 实验基线模型预算"."Sheet1"
                        WHERE "col_id" = 'deepseek-v4-pro'
                        """,
                List.of(new SqlSupportUtils.ManagedTable(
                        "ama 实验基线模型预算",
                        "Sheet1",
                        "tb_excel_budget")));

        Assert.assertEquals(
                "SELECT `token`, `token_1` FROM tb_excel_budget "
                        + "WHERE `col_id` = 'deepseek-v4-pro'",
                resolved.getExecutableSql());
    }

    /**
     * 验证字符串字面量中的双引号不会被当成标识符转换。
     */
    @Test
    public void resolveInternalMysqlShouldPreserveStringLiteralQuotes() {
        SqlSupportUtils.ResolvedSql resolved = SqlSupportUtils.resolveInternalMysql(
                "SELECT \"token\" FROM \"Sheet1\" WHERE \"col_id\" = 'deep\"seek'",
                List.of(new SqlSupportUtils.ManagedTable(
                        null,
                        "Sheet1",
                        "tb_excel_budget")));

        Assert.assertEquals(
                "SELECT `token` FROM tb_excel_budget WHERE `col_id` = 'deep\"seek'",
                resolved.getExecutableSql());
    }
}
