package com.ruoyi.ccdi.project.sql;

import org.junit.jupiter.api.Test;

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

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

class CcdiAbnormalAccountRuleSqlMetadataTest {

    @Test
    void abnormalAccountMetadataSql_shouldContainModelAndRuleDefinitions() throws IOException {
        Path path = Path.of("..", "sql", "migration",
            "2026-03-31-create-ccdi-account-info-and-abnormal-account-rules.sql");

        assertTrue(Files.exists(path), "异常账户模型迁移脚本应存在");

        String sql = Files.readString(path, StandardCharsets.UTF_8);
        assertAll(
            () -> assertTrue(sql.contains("ABNORMAL_ACCOUNT")),
            () -> assertTrue(sql.contains("SUDDEN_ACCOUNT_CLOSURE")),
            () -> assertTrue(sql.contains("DORMANT_ACCOUNT_LARGE_ACTIVATION")),
            () -> assertTrue(sql.contains("'OBJECT'"))
        );
    }

    @Test
    void abnormalAccountMetadataSql_shouldContainAccountInfoTableDefinition() throws IOException {
        Path path = Path.of("..", "sql", "migration",
            "2026-03-31-create-ccdi-account-info-and-abnormal-account-rules.sql");

        assertTrue(Files.exists(path), "异常账户模型迁移脚本应存在");

        String sql = Files.readString(path, StandardCharsets.UTF_8).toLowerCase();
        assertAll(
            () -> assertTrue(sql.contains("create table if not exists `ccdi_account_info`")),
            () -> assertTrue(sql.contains("`account_no`")),
            () -> assertTrue(sql.contains("`owner_type`")),
            () -> assertTrue(sql.contains("`effective_date`")),
            () -> assertTrue(sql.contains("`invalid_date`"))
        );
    }
}
