/**
 * Lazy data accessors for the generated specialist blobs.
 *
 * The raw data lives in src/engines/data/*.json so it is loaded by Node's JSON
 * parser on first access instead of being evaluated as ~14 k LOC of JavaScript
 * at module import time.
 *
 * Sync API is preserved: callers that were synchronous remain synchronous.
 * Generation: run `node scripts/extract-specialist-data.mjs` after re-generating
 * specialists to refresh the JSON snapshots.
 */
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
/**
 * Resolve the data file by trying a small set of candidate locations.
 * - Unbundled (dist/engines/generated-specialist-loader.js): __dirname is
 *   dist/engines, so the data lives at __dirname/data.
 * - Bundled (dist/cli.bundle.js): __dirname is dist, so the data lives at
 *   __dirname/engines/data.
 * - Source (tsx/dev): __dirname is src/engines, so the data lives at
 *   __dirname/data.
 * The first candidate that exists wins; absent that we throw the original
 * (most-likely-correct) path so the error message stays useful.
 */
function resolveDataFile(name) {
    const candidates = [
        path.join(__dirname, 'data', name),
        path.join(__dirname, 'engines', 'data', name),
        path.join(__dirname, '..', 'engines', 'data', name),
    ];
    for (const candidate of candidates) {
        if (fs.existsSync(candidate))
            return candidate;
    }
    return candidates[0];
}
let _profiles = null;
let _specialists = null;
/** Returns the 139 specialist profile seeds, loading from JSON on first call. */
export function getImportedSpecialistProfiles() {
    if (_profiles)
        return _profiles;
    const raw = fs.readFileSync(resolveDataFile('specialist-profiles.json'), 'utf8');
    _profiles = JSON.parse(raw);
    return _profiles;
}
/** Returns the 139 specialist seeds, loading from JSON on first call. */
export function getImportedSpecialists() {
    if (_specialists)
        return _specialists;
    const raw = fs.readFileSync(resolveDataFile('specialists.json'), 'utf8');
    _specialists = JSON.parse(raw);
    return _specialists;
}
/** Invalidate the in-process cache (useful after re-generating data files). */
export function resetSpecialistCache() {
    _profiles = null;
    _specialists = null;
}
