/**
 * studiograph lint command
 *
 * Schema-aware completeness checker — walks all entities and flags missing
 * recommended fields.
 */
import { Command } from 'commander';
import { Workspace } from '../../core/workspace.js';
import { WorkspaceManager } from '../../core/workspace-manager.js';
import { intro, outro, spinner } from '@clack/prompts';
import { lintWorkspace } from '../../services/lint-service.js';
export const lintCommand = new Command('lint')
    .description('Check for missing or incomplete entity fields across the workspace')
    .option('--fix', 'Suggest fixes for incomplete records (future)', false)
    .action(async (options) => {
    intro('Studiograph Lint');
    const s = spinner();
    s.start('Loading workspace');
    try {
        const workspace = new Workspace();
        if (!workspace.isWorkspace()) {
            console.error('❌ Not a Studiograph workspace. Run `studiograph init` first.');
            process.exit(1);
        }
        const config = await workspace.loadConfig();
        const gitUser = { id: 'system', name: 'system', email: 'system@local' };
        const manager = new WorkspaceManager(process.cwd(), config, gitUser);
        s.message('Scanning entities');
        const issues = await lintWorkspace(manager);
        s.stop('Scan complete');
        if (issues.length === 0) {
            outro('✅ No issues found — all entities are complete!');
            return;
        }
        // Group issues by entity type
        const grouped = new Map();
        for (const issue of issues) {
            const key = issue.entityType;
            if (!grouped.has(key))
                grouped.set(key, []);
            grouped.get(key).push(issue);
        }
        console.log('');
        console.log(`Found ${issues.length} incomplete entities:\n`);
        for (const [entityType, typeIssues] of grouped.entries()) {
            console.log(`${entityType.toUpperCase()} (${typeIssues.length} incomplete)`);
            // Show up to 5 examples per type
            const examples = typeIssues.slice(0, 5);
            for (const issue of examples) {
                console.log(`  - ${issue.repo}/${issue.entityType}/${issue.entityId}`);
                console.log(`    Missing: ${issue.missingFields.join(', ')}`);
            }
            if (typeIssues.length > 5) {
                console.log(`  ... and ${typeIssues.length - 5} more`);
            }
            console.log('');
        }
        if (options.fix) {
            console.log('--fix flag is not yet implemented (future feature)');
        }
        outro('Lint complete');
    }
    catch (error) {
        s.stop('Error');
        console.error('Failed to lint workspace:', error instanceof Error ? error.message : error);
        process.exit(1);
    }
});
//# sourceMappingURL=lint.js.map