import { readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
export const OAT_MARKER_PREFIX = '<!-- OAT-managed: do not edit directly.';
export const OAT_DIRECTORY_SENTINEL = '.oat-generated';
function buildMarkerLine(canonicalPath) {
    return `${OAT_MARKER_PREFIX} Source: ${canonicalPath} -->`;
}
export async function hasMarker(filePath) {
    const contents = await readFile(filePath, 'utf8');
    return contents.startsWith(OAT_MARKER_PREFIX);
}
export async function insertMarker(filePath, canonicalPath) {
    const contents = await readFile(filePath, 'utf8');
    if (contents.startsWith(OAT_MARKER_PREFIX)) {
        return;
    }
    const marker = buildMarkerLine(canonicalPath);
    await writeFile(filePath, `${marker}\n${contents}`, 'utf8');
}
export async function writeDirectorySentinel(directoryPath, canonicalPath) {
    const sentinelPath = join(directoryPath, OAT_DIRECTORY_SENTINEL);
    const marker = buildMarkerLine(canonicalPath);
    await writeFile(sentinelPath, `${marker}\n`, 'utf8');
}
