const PLANU_CONFIG_VERSION = '1.0.0';
const DEFAULT_SPEC_LOCATION = 'planu/specs';
/**
 * Create a new PlanuConfig with defaults. Always uses modern spec location.
 * SPEC-313: Accepts optional workMode to embed in the generated config.
 */
export function createPlanuConfig(workMode) {
    const now = new Date().toISOString();
    return {
        version: PLANU_CONFIG_VERSION,
        specLocation: DEFAULT_SPEC_LOCATION,
        specNaming: 'modern',
        createdAt: now,
        updatedAt: now,
        ...(workMode !== undefined ? { workMode } : {}),
    };
}
/**
 * SPEC-313: Read planu.json, update workMode, and write back.
 * Accepts injected readFile/writeFile to keep this function pure/testable.
 */
export async function updatePlanuConfigWorkMode(planuConfigPath, workMode, readFile, writeFile) {
    try {
        const raw = await readFile(planuConfigPath, 'utf-8');
        const config = JSON.parse(raw);
        config.workMode = workMode;
        config.updatedAt = new Date().toISOString();
        await writeFile(planuConfigPath, serializePlanuConfig(config), 'utf-8');
    }
    catch {
        // planu.json absent or invalid — skip silently
    }
}
/**
 * SPEC-313: Read and parse planu.json to retrieve its config (best-effort).
 * Returns null if the file is absent or malformed.
 */
export async function readPlanuConfig(planuConfigPath, readFile) {
    try {
        const raw = await readFile(planuConfigPath, 'utf-8');
        return JSON.parse(raw);
    }
    catch {
        return null;
    }
}
/**
 * Serialize PlanuConfig to JSON string.
 */
export function serializePlanuConfig(config) {
    return JSON.stringify(config, null, 2);
}
/**
 * Determine spec file names based on naming convention.
 */
export function getSpecFileNames(naming) {
    if (naming === 'legacy') {
        return { spec: 'HU.md', technical: 'FICHA-TECNICA.md', progress: 'PROGRESS.md' };
    }
    return { spec: 'spec.md', technical: 'spec.md', progress: 'spec.md' };
}
/**
 * Check if a specLocation uses legacy naming.
 */
export function isLegacyLocation(specLocation) {
    return specLocation.includes('docs/sdd/specs');
}
//# sourceMappingURL=planu-config-writer.js.map