import fs from "node:fs";
import path from "node:path";
import { planningSqliteDatabaseRelativePath } from "./planning-config.js";
import { collectTaskStateProjectionDoctorIssues } from "./persistence/task-state-projection-health.js";
export async function collectDoctorTaskStateProjectionIssues(cwd, effective) {
    let Database;
    try {
        ({ default: Database } = await import("better-sqlite3"));
    }
    catch {
        return [];
    }
    const ctx = { workspacePath: cwd, effectiveConfig: effective };
    const dbRel = planningSqliteDatabaseRelativePath(ctx);
    const dbAbs = path.resolve(cwd, dbRel);
    if (!fs.existsSync(dbAbs)) {
        return [];
    }
    let db;
    try {
        db = new Database(dbAbs, { readonly: true });
    }
    catch {
        return [];
    }
    try {
        return collectTaskStateProjectionDoctorIssues(cwd, dbRel, db);
    }
    finally {
        db.close();
    }
}
