package com.ruoyi.ccdi.project.sql;

import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.assertTrue;

class CcdiProjectStatusSqlTest {

    @Test
    void shouldContainTaggingStatusInInitAndMigrationSql() throws IOException {
        Path repoRoot = Path.of("..");
        String initSql = Files.readString(repoRoot.resolve("sql/ccdi_project.sql"));
        String prodInitSql = Files.readString(repoRoot.resolve("sql/ccdi_prod_init.sql"));
        String migrationSql = Files.readString(repoRoot.resolve("sql/migration/2026-03-18-add-project-tagging-status.sql"));
        String tagFailedMigrationSql =
            Files.readString(repoRoot.resolve("sql/migration/2026-05-27-add-project-tag-failed-status.sql"));
        String deletedMigrationSql =
            Files.readString(repoRoot.resolve("sql/migration/2026-07-02-add-project-deleted-status.sql"));

        assertTrue(initSql.contains("打标中"));
        assertTrue(initSql.contains("'3'"));
        assertTrue(migrationSql.contains("ccdi_project_status"));
        assertTrue(migrationSql.contains("打标中"));
        assertTrue(migrationSql.contains("'3'"));

        assertTrue(initSql.contains("打标失败"));
        assertTrue(initSql.contains("'4'"));
        assertTrue(prodInitSql.contains("打标失败"));
        assertTrue(prodInitSql.contains("'4','ccdi_project_status'"));
        assertTrue(tagFailedMigrationSql.contains("ccdi_project_status"));
        assertTrue(tagFailedMigrationSql.contains("打标失败"));
        assertTrue(tagFailedMigrationSql.contains("'4'"));
        assertTrue(tagFailedMigrationSql.contains("latest_task.status = 'FAILED'"));
        assertTrue(tagFailedMigrationSql.contains("project.status IN ('0', '3')"));

        assertTrue(initSql.contains("已删除"));
        assertTrue(initSql.contains("'5'"));
        assertTrue(prodInitSql.contains("已删除"));
        assertTrue(prodInitSql.contains("'5','ccdi_project_status'"));
        assertTrue(deletedMigrationSql.contains("ccdi_project_status"));
        assertTrue(deletedMigrationSql.contains("已删除"));
        assertTrue(deletedMigrationSql.contains("'5'"));
        assertTrue(deletedMigrationSql.contains("utf8mb4_general_ci"));
    }
}
