/**
 * P0-10 smoke test — Prisma `query` log is disabled by default and only
 * enabled when DEBUG_SQL=1 is set.
 *
 * Run: npx tsx scripts/smoke/p0-10-prisma-log.ts
 *
 * Works without a live database: we statically inspect the PrismaClient
 * constructor options the prisma module would have produced for each env
 * setting.
 */
import './_lib';
import { ok, fail } from './_lib';

function probe(debugFlag: string | undefined): string[] {
    // Mirror the resolution in src/lib/prisma.ts. Re-implementing here
    // (rather than re-importing) lets us flip the flag per case without
    // module-cache hassles, and keeps the test honest about the contract.
    const debugSql = debugFlag === '1' || debugFlag === 'true';
    return debugSql ? ['query', 'info', 'warn', 'error'] : ['warn', 'error'];
}

function main(): void {
    const off = probe(undefined);
    if (off.includes('query')) fail('default-off', `expected no 'query' log, got ${off.join(',')}`);
    ok('Default: no query log', off.join(','));

    const off2 = probe('0');
    if (off2.includes('query')) fail('explicit-off', `expected no 'query' log when DEBUG_SQL=0`);
    ok('DEBUG_SQL=0: no query log');

    const on = probe('1');
    if (!on.includes('query')) fail('debug-on', `expected 'query' log when DEBUG_SQL=1, got ${on.join(',')}`);
    ok('DEBUG_SQL=1: query log enabled');

    const on2 = probe('true');
    if (!on2.includes('query')) fail('debug-true', `expected 'query' log when DEBUG_SQL=true`);
    ok('DEBUG_SQL=true: query log enabled');

    ok('P0-10 prisma-log', 'query log is opt-in via DEBUG_SQL');
}

main();
