function isHashSource(x) {
    return typeof x === 'object' && x !== null && typeof x.getFileHash === 'function';
}
export function getFileHash(db, file) {
    const row = db.prepare('SELECT hash FROM file_hashes WHERE file = ?').get(file);
    return row ? row.hash : null;
}
/** Pick the 4-field symbol reference from any row that carries at least {name, kind, file, line}. */
export function toSymbolRef(row) {
    return { name: row.name, kind: row.kind, file: row.file, line: row.line };
}
export function kindIcon(kind) {
    switch (kind) {
        case 'function':
            return 'f';
        case 'class':
            return '*';
        case 'method':
            return 'o';
        case 'file':
            return '#';
        case 'interface':
            return 'I';
        case 'type':
            return 'T';
        case 'parameter':
            return 'p';
        case 'property':
            return '.';
        case 'constant':
            return 'C';
        default:
            return '-';
    }
}
/**
 * Resolve a file hash, using the cache when available.
 * Accepts a raw DB handle (with .prepare) or a Repository (with .getFileHash).
 */
function resolveFileHash(db, file, hashCache) {
    const lookupHash = isHashSource(db)
        ? (f) => db.getFileHash(f)
        : (f) => getFileHash(db, f);
    if (!hashCache)
        return lookupHash(file);
    if (!hashCache.has(file)) {
        hashCache.set(file, lookupHash(file));
    }
    return hashCache.get(file) ?? null;
}
/**
 * Normalize a raw DB/query row into the stable 7-field symbol shape.
 * Accepts a raw DB handle (with .prepare), a Repository (with .getFileHash), or null.
 */
export function normalizeSymbol(row, db, hashCache) {
    const fileHash = db ? resolveFileHash(db, row.file, hashCache) : null;
    return {
        name: row.name,
        kind: row.kind,
        file: row.file,
        line: row.line,
        endLine: row.end_line ?? row.endLine ?? null,
        role: row.role ?? null,
        fileHash,
    };
}
//# sourceMappingURL=normalize.js.map