/**
 * SpecVerse Parser - Public API
 *
 * Unified parser architecture with backward compatibility
 * Simple, powerful YAML + conventions parser with optional imports
 */
// Export unified parser
export { UnifiedSpecVerseParser } from './unified-parser.js';
// Export all types from unified parser
export { ConventionProcessor } from './convention-processor.js';
// Spec summary for `spv validate --json` (curated parse facts; single parser).
export { summarizeSpecForCli } from './spec-summary.js';
// Namespace utilities
export { parseNamespace, parseReference, validateNamespace } from './namespace-utils.js';
// Import resolver
export { ImportResolver } from './import-resolver/resolver.js';
// Re-export for convenience
import fs from 'fs';
import path from 'path';
import { createRequire } from 'module';
import { UnifiedSpecVerseParser } from './unified-parser.js';
/**
 * Parse a SpecVerse YAML file
 */
export function parseSpecVerseFile(filePath, schemaPath) {
    const yamlContent = fs.readFileSync(filePath, 'utf8');
    const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8'));
    const parser = new UnifiedSpecVerseParser(schema);
    return parser.parse(yamlContent);
}
/**
 * Parse SpecVerse YAML content with embedded schema
 */
export function parseSpecVerse(yamlContent, schema) {
    const parser = new UnifiedSpecVerseParser(schema);
    return parser.parse(yamlContent);
}
class SpecVerseParserEngine {
    name = 'parser';
    version = '3.5.2';
    capabilities = ['parse', 'validate', 'convention-processing', 'import-resolution'];
    parser = null;
    initialized = false;
    async initialize(config) {
        // Load the canonical SpecVerse schema from @specverse/entities by default.
        // Initialising with `{}` (the prior behaviour) made AJV a no-op — every
        // caller that went through EngineRegistry was running parses without
        // schema validation. That masked schema-invalid output (e.g. controllers/
        // services/caches inside deployments blocks) for months. Bug discovered
        // 2026-04-29; this is the fix.
        let schema = config?.schema;
        if (!schema || (typeof schema === 'object' && Object.keys(schema).length === 0)) {
            schema = loadDefaultSchema();
        }
        this.parser = new UnifiedSpecVerseParser(schema);
        this.initialized = true;
    }
    getInfo() {
        return { name: this.name, version: this.version, capabilities: this.capabilities };
    }
    parseContent(content, filename) {
        if (!this.parser)
            throw new Error('Parser not initialized. Call initialize() first.');
        return this.parser.parseContent(content, filename);
    }
    async parseFileWithImports(filePath, options) {
        if (!this.parser)
            throw new Error('Parser not initialized. Call initialize() first.');
        return this.parser.parseFileWithImports(filePath, options);
    }
}
/**
 * Resolve and load `@specverse/entities/schema/SPECVERSE-SCHEMA.json`.
 * Used by `SpecVerseParserEngine.initialize()` when no schema is provided.
 * Throws a clear error if entities isn't installed alongside engines —
 * better than silently no-op'ing schema validation.
 */
function loadDefaultSchema() {
    const require = createRequire(import.meta.url);
    let entitiesPkg;
    try {
        entitiesPkg = require.resolve('@specverse/entities/package.json');
    }
    catch (err) {
        throw new Error(`SpecVerseParserEngine: could not resolve @specverse/entities to load default schema. ` +
            `Either install @specverse/entities alongside @specverse/engines, or pass an explicit ` +
            `schema to .initialize({ schema }).`);
    }
    const schemaPath = path.join(path.dirname(entitiesPkg), 'schema', 'SPECVERSE-SCHEMA.json');
    if (!fs.existsSync(schemaPath)) {
        throw new Error(`SpecVerseParserEngine: default schema not found at ${schemaPath}. ` +
            `Install a recent @specverse/entities or pass schema explicitly.`);
    }
    return JSON.parse(fs.readFileSync(schemaPath, 'utf8'));
}
/** Singleton engine instance for EngineRegistry discovery */
export const engine = new SpecVerseParserEngine();
export default engine;
//# sourceMappingURL=index.js.map