import { readFileSync } from 'node:fs';
import { relative } from 'node:path';
import { compile } from '@duckcodeailabs/dql-compiler';
import { collectInputFiles } from '@duckcodeailabs/dql-core';
export function discoverScheduledBlocks(projectRoot) {
    const files = collectInputFiles({ projectRoot }).filter((f) => f.endsWith('.dql'));
    const out = [];
    for (const path of files) {
        let source;
        try {
            source = readFileSync(path, 'utf-8');
        }
        catch {
            continue;
        }
        const result = compile(source, { file: path });
        for (const dashboard of result.dashboards) {
            const meta = dashboard.metadata;
            if (!meta.schedule?.cron)
                continue;
            out.push({
                path,
                name: deriveBlockName(projectRoot, path),
                schedule: meta.schedule,
                notifications: meta.notifications ?? [],
                alerts: meta.alerts ?? [],
            });
        }
    }
    return out;
}
export function deriveBlockName(projectRoot, absPath) {
    const rel = relative(projectRoot, absPath);
    return rel.replace(/\.dql$/, '').replace(/\\/g, '/');
}
//# sourceMappingURL=discovery.js.map