import fs from 'fs';
import path from 'path';
import readline from 'readline';
function ask(rl, question) {
    return new Promise(resolve => rl.question(question, resolve));
}
export async function onboardingCommand() {
    const cwd = process.cwd();
    const companyPath = path.join(cwd, '_expxagents', '_memory', 'company.md');
    const prefsPath = path.join(cwd, '_expxagents', '_memory', 'preferences.md');
    if (!fs.existsSync(path.dirname(companyPath))) {
        console.error('Project not initialized. Run `expxagents init` first.');
        process.exit(1);
    }
    const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
    console.log('\n  Welcome to ExpxAgents!\n');
    try {
        const userName = await ask(rl, '  Your name: ');
        const language = await ask(rl, '  Preferred language (pt-BR, en, es) [pt-BR]: ') || 'pt-BR';
        const ide = await ask(rl, '  Primary IDE (claude-code, cursor, codex, vscode-copilot) [claude-code]: ') || 'claude-code';
        const companyName = await ask(rl, '  Company name: ');
        const companyUrl = await ask(rl, '  Company website URL (optional): ');
        const sector = await ask(rl, '  Company sector: ');
        const description = await ask(rl, '  Brief company description: ');
        const audience = await ask(rl, '  Target audience: ');
        const toneStyle = await ask(rl, '  Tone of voice (formal, casual, technical, friendly): ');
        // Save preferences
        const prefsContent = `# ExpxAgents Preferences\n\n- **User Name:** ${userName}\n- **Language:** ${language}\n- **IDE:** ${ide}\n- **Date Format:** DD/MM/YYYY\n`;
        fs.writeFileSync(prefsPath, prefsContent, 'utf-8');
        // Save company profile
        const companyContent = `# Company Profile\n\n## Company\n- **Name:** ${companyName}\n- **Website:** ${companyUrl}\n- **Sector:** ${sector}\n- **Description:** ${description}\n\n## Target Audience\n- **Primary:** ${audience}\n\n## Tone of Voice\n- **Style:** ${toneStyle}\n`;
        fs.writeFileSync(companyPath, companyContent, 'utf-8');
        console.log('\n  Profile saved! You can edit it anytime at _expxagents/_memory/company.md');
        console.log('  Run `expxagents create` to design your first squad.\n');
    }
    finally {
        rl.close();
    }
}
