import { expect, test, describe } from "bun:test";
import { postgres } from "../lib/DrizzleClient";

describe("Database Indexes", () => {
    test("should have indexes on users table", async () => {
        const result = await postgres`
            SELECT indexname FROM pg_indexes 
            WHERE tablename = 'users'
        `;
        const indexNames = (result as unknown as { indexname: string }[]).map(r => r.indexname);
        expect(indexNames).toContain("users_balance_idx");
        expect(indexNames).toContain("users_level_xp_idx");
    });

    test("should have index on transactions table", async () => {
        const result = await postgres`
            SELECT indexname FROM pg_indexes 
            WHERE tablename = 'transactions'
        `;
        const indexNames = (result as unknown as { indexname: string }[]).map(r => r.indexname);
        expect(indexNames).toContain("transactions_created_at_idx");
    });

    test("should have indexes on moderation_cases table", async () => {
        const result = await postgres`
            SELECT indexname FROM pg_indexes 
            WHERE tablename = 'moderation_cases'
        `;
        const indexNames = (result as unknown as { indexname: string }[]).map(r => r.indexname);
        expect(indexNames).toContain("moderation_cases_user_id_idx");
        expect(indexNames).toContain("moderation_cases_case_id_idx");
    });

    test("should have indexes on user_timers table", async () => {
        const result = await postgres`
            SELECT indexname FROM pg_indexes 
            WHERE tablename = 'user_timers'
        `;
        const indexNames = (result as unknown as { indexname: string }[]).map(r => r.indexname);
        expect(indexNames).toContain("user_timers_expires_at_idx");
        expect(indexNames).toContain("user_timers_lookup_idx");
    });
});
