"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildStrategyCommand = void 0;
const commander_1 = require("commander");
const buildStrategyManager_1 = require("../utils/buildStrategyManager");
const chalk_1 = __importDefault(require("chalk"));
const inquirer_1 = __importDefault(require("inquirer"));
exports.buildStrategyCommand = new commander_1.Command("build-strategy")
    .description("Generate AI-powered build strategy for your project")
    .option("-r, --recommend", "Get strategy recommendations")
    .option("-p, --plan", "Generate detailed build plan")
    .option("-t, --tasks", "Generate task list for current phase")
    .option("-c, --compare", "Compare all available strategies")
    .option("--context", "Show loaded project context")
    .option("--list", "List all saved strategy files")
    .option("--load <type>", "Load saved strategy data (recommendations|plan|tasks|comparison)")
    .action(async (options) => {
    const manager = new buildStrategyManager_1.BuildStrategyManager();
    try {
        if (options.context) {
            await showProjectContext(manager);
        }
        else if (options.list) {
            await listStrategyFiles(manager);
        }
        else if (options.load) {
            await loadStrategyData(manager, options.load);
        }
        else if (options.recommend) {
            await getStrategyRecommendations(manager);
        }
        else if (options.plan) {
            await generateBuildPlan(manager, options.strategy);
        }
        else if (options.tasks) {
            await generateTaskList(manager, options.strategy);
        }
        else if (options.compare) {
            await compareStrategies(manager);
        }
        else {
            await interactiveStrategySelection(manager);
        }
    }
    catch (error) {
        console.error(chalk_1.default.red("❌ Error:"), error);
        process.exit(1);
    }
});
async function showProjectContext(manager) {
    console.log(chalk_1.default.blue("📋 Project Context Analysis\n"));
    try {
        const context = await manager.loadProjectContext();
        console.log(chalk_1.default.bold("📁 Project Information:"));
        console.log(chalk_1.default.gray(`   Name: ${context.projectName}`));
        console.log(chalk_1.default.gray(`   Description: ${context.description}`));
        console.log();
        console.log(chalk_1.default.bold("🧩 Components Found:"));
        if (context.components.length > 0) {
            context.components.forEach((comp, index) => {
                console.log(chalk_1.default.gray(`   ${index + 1}. ${comp}`));
            });
        }
        else {
            console.log(chalk_1.default.yellow("   No components found in component list"));
        }
        console.log();
        console.log(chalk_1.default.bold("👥 User Roles Identified:"));
        context.userRoles.forEach((role, index) => {
            console.log(chalk_1.default.gray(`   ${index + 1}. ${role}`));
        });
        console.log();
        console.log(chalk_1.default.bold("⚙️ Tech Stack Detected:"));
        context.techStack.forEach((tech, index) => {
            console.log(chalk_1.default.gray(`   ${index + 1}. ${tech}`));
        });
        console.log();
        const loadedFiles = [
            context.prd,
            context.types,
            context.brand,
            context.componentList,
            context.features,
            context.userFlows,
            context.edgeCases,
            context.technicalSpecs,
        ].filter(Boolean).length;
        console.log(chalk_1.default.bold("📊 Context Completeness:"));
        console.log(chalk_1.default.gray(`   ${loadedFiles}/8 context files loaded`));
        if (loadedFiles >= 6) {
            console.log(chalk_1.default.green("   ✅ Excellent context coverage - build plans will be highly accurate"));
        }
        else if (loadedFiles >= 4) {
            console.log(chalk_1.default.yellow("   ⚠️ Good context coverage - build plans will be reasonably accurate"));
        }
        else {
            console.log(chalk_1.default.red("   ❌ Limited context coverage - consider running 'mycontext generate context --full' first"));
        }
    }
    catch (error) {
        console.log(chalk_1.default.red("❌ Error loading project context:"));
        console.log(chalk_1.default.gray(`   ${error}`));
        console.log(chalk_1.default.yellow("\n💡 Try running 'mycontext init' or 'mycontext generate context --full' first"));
    }
}
async function getStrategyRecommendations(manager) {
    console.log(chalk_1.default.blue("🎯 Getting AI-Powered Strategy Recommendations\n"));
    const answers = await inquirer_1.default.prompt([
        {
            type: "list",
            name: "projectType",
            message: "What type of project are you building?",
            choices: [
                { name: "Client Work", value: "client" },
                { name: "Personal Project", value: "personal" },
                { name: "Team Development", value: "team" },
                { name: "MVP Development", value: "mvp" },
                { name: "Enterprise Application", value: "enterprise" },
            ],
        },
        {
            type: "list",
            name: "complexity",
            message: "How complex is your application?",
            choices: [
                { name: "Simple (few features, single user type)", value: "simple" },
                {
                    name: "Medium (multiple features, some complexity)",
                    value: "medium",
                },
                {
                    name: "Complex (many features, multiple user types)",
                    value: "complex",
                },
            ],
        },
        {
            type: "list",
            name: "timeline",
            message: "What's your timeline?",
            choices: [
                { name: "Urgent (need demo ASAP)", value: "urgent" },
                { name: "Moderate (balanced approach)", value: "moderate" },
                { name: "Flexible (quality over speed)", value: "flexible" },
            ],
        },
        {
            type: "list",
            name: "teamSize",
            message: "What's your team size?",
            choices: [
                { name: "Solo developer", value: "solo" },
                { name: "Small team (2-5 people)", value: "small" },
                { name: "Large team (6+ people)", value: "large" },
            ],
        },
    ]);
    const recommendations = await manager.recommendStrategies(answers);
    console.log(chalk_1.default.green("\n✅ Recommended Strategies:\n"));
    recommendations.recommended.forEach((strategy) => {
        console.log(chalk_1.default.bold(`${strategy.icon} ${strategy.name}`));
        console.log(chalk_1.default.gray(`   ${strategy.description}`));
        console.log(chalk_1.default.cyan(`   Time to first demo: ${strategy.timeToFirstDemo}`));
        console.log(chalk_1.default.yellow(`   Complexity: ${strategy.complexity}`));
        console.log();
    });
    console.log(chalk_1.default.blue("💡 Reasoning:"));
    console.log(chalk_1.default.gray(`   ${recommendations.reasoning}\n`));
    if (recommendations.alternatives.length > 0) {
        console.log(chalk_1.default.yellow("🔄 Alternative Strategies:"));
        recommendations.alternatives.forEach((strategy) => {
            console.log(chalk_1.default.gray(`   ${strategy.icon} ${strategy.name}`));
        });
    }
}
async function generateBuildPlan(manager, strategyId) {
    console.log(chalk_1.default.blue("📋 Generating Detailed Build Plan\n"));
    if (!strategyId) {
        const { strategy } = await inquirer_1.default.prompt([
            {
                type: "list",
                name: "strategy",
                message: "Which strategy would you like to plan?",
                choices: [
                    { name: "🏗️ Foundation First", value: "foundation-first" },
                    { name: "🎯 Vertical Slice", value: "vertical-slice" },
                    { name: "📊 Horizontal Slice", value: "horizontal-slice" },
                    { name: "🔄 Iterative Scaffolding", value: "iterative-scaffolding" },
                    { name: "⚡ Hybrid Approach", value: "hybrid" },
                ],
            },
        ]);
        strategyId = strategy;
    }
    const plan = await manager.generateBuildPlan(strategyId);
    console.log(chalk_1.default.green(`✅ Build Plan for ${plan.strategy?.name || strategyId}:\n`));
    plan.plan?.forEach((phase) => {
        console.log(chalk_1.default.bold(`Phase ${phase.phase}: ${phase.name}`));
        console.log(chalk_1.default.gray(`   Duration: ${phase.duration}`));
        console.log(chalk_1.default.gray(`   Tasks: ${phase.tasks?.join(", ")}`));
        console.log(chalk_1.default.gray(`   Deliverables: ${phase.deliverables?.join(", ")}`));
        console.log();
    });
    if (plan.totalDuration) {
        console.log(chalk_1.default.cyan(`📅 Total Duration: ${plan.totalDuration}`));
    }
    if (plan.milestones?.length > 0) {
        console.log(chalk_1.default.yellow("\n🎯 Key Milestones:"));
        plan.milestones.forEach((milestone) => {
            console.log(chalk_1.default.gray(`   • ${milestone}`));
        });
    }
}
async function generateTaskList(manager, strategyId) {
    console.log(chalk_1.default.blue("📝 Generating Task List\n"));
    if (!strategyId) {
        const { strategy } = await inquirer_1.default.prompt([
            {
                type: "list",
                name: "strategy",
                message: "Which strategy?",
                choices: [
                    { name: "🏗️ Foundation First", value: "foundation-first" },
                    { name: "🎯 Vertical Slice", value: "vertical-slice" },
                    { name: "📊 Horizontal Slice", value: "horizontal-slice" },
                    { name: "🔄 Iterative Scaffolding", value: "iterative-scaffolding" },
                    { name: "⚡ Hybrid Approach", value: "hybrid" },
                ],
            },
        ]);
        strategyId = strategy;
    }
    const { phaseNumber } = await inquirer_1.default.prompt([
        {
            type: "number",
            name: "phaseNumber",
            message: "Which phase?",
            default: 1,
            min: 1,
        },
    ]);
    const taskList = await manager.generateTaskList(strategyId, phaseNumber);
    console.log(chalk_1.default.green(`✅ Tasks for Phase ${phaseNumber}: ${taskList.phase?.name}\n`));
    taskList.tasks?.forEach((task) => {
        console.log(chalk_1.default.bold(`${task.title}`));
        console.log(chalk_1.default.gray(`   ${task.description}`));
        console.log(chalk_1.default.cyan(`   Priority: ${task.priority}`));
        console.log(chalk_1.default.yellow(`   Time: ${task.estimatedTime}`));
        if (task.dependencies?.length > 0) {
            console.log(chalk_1.default.red(`   Dependencies: ${task.dependencies.join(", ")}`));
        }
        console.log();
    });
}
async function compareStrategies(manager) {
    console.log(chalk_1.default.blue("⚖️ Comparing All Strategies\n"));
    const comparison = await manager.compareStrategies();
    console.log(chalk_1.default.green("📊 Strategy Comparison:\n"));
    comparison.strategies?.forEach((strategy) => {
        console.log(chalk_1.default.bold(`${strategy.icon} ${strategy.name}`));
        console.log(chalk_1.default.gray(`   ${strategy.description}`));
        console.log(chalk_1.default.cyan(`   Time to demo: ${strategy.timeToFirstDemo}`));
        console.log(chalk_1.default.yellow(`   Complexity: ${strategy.complexity}`));
        console.log(chalk_1.default.green(`   Score: ${strategy.score}/10`));
        console.log();
    });
    console.log(chalk_1.default.bold(`🎯 Recommendation: ${comparison.recommendation}`));
    console.log(chalk_1.default.gray(`   ${comparison.reasoning}`));
}
async function interactiveStrategySelection(manager) {
    console.log(chalk_1.default.blue("🚀 MyContext Build Strategy Assistant\n"));
    const { action } = await inquirer_1.default.prompt([
        {
            type: "list",
            name: "action",
            message: "What would you like to do?",
            choices: [
                { name: "Get strategy recommendations", value: "recommend" },
                { name: "Compare all strategies", value: "compare" },
                { name: "Generate build plan", value: "plan" },
                { name: "Generate task list", value: "tasks" },
                { name: "Show project context", value: "context" },
            ],
        },
    ]);
    switch (action) {
        case "recommend":
            await getStrategyRecommendations(manager);
            break;
        case "compare":
            await compareStrategies(manager);
            break;
        case "plan":
            await generateBuildPlan(manager);
            break;
        case "tasks":
            await generateTaskList(manager);
            break;
        case "context":
            await showProjectContext(manager);
            break;
    }
}
async function listStrategyFiles(manager) {
    console.log(chalk_1.default.blue("📁 Saved Strategy Files\n"));
    try {
        const files = await manager.listStrategyFiles();
        if (files.length === 0) {
            console.log(chalk_1.default.yellow("No strategy files found."));
            console.log(chalk_1.default.gray("Run 'mycontext build-strategy --recommend' to generate your first strategy file."));
            return;
        }
        console.log(chalk_1.default.green("Available strategy files:\n"));
        files.forEach((file, index) => {
            console.log(chalk_1.default.bold(`${index + 1}. ${file.type.toUpperCase()}`));
            console.log(chalk_1.default.gray(`   Date: ${file.date}`));
            console.log(chalk_1.default.gray(`   Path: ${file.filepath}`));
            console.log();
        });
        console.log(chalk_1.default.cyan("💡 Usage:"));
        console.log(chalk_1.default.gray("   mycontext build-strategy --load recommendations"));
        console.log(chalk_1.default.gray("   mycontext build-strategy --load plan"));
        console.log(chalk_1.default.gray("   mycontext build-strategy --load tasks"));
        console.log(chalk_1.default.gray("   mycontext build-strategy --load comparison"));
    }
    catch (error) {
        console.log(chalk_1.default.red("❌ Error listing strategy files:"));
        console.log(chalk_1.default.gray(`   ${error}`));
    }
}
async function loadStrategyData(manager, type) {
    console.log(chalk_1.default.blue(`📂 Loading ${type} Strategy Data\n`));
    try {
        const data = await manager.loadStrategyData(type);
        console.log(chalk_1.default.green(`✅ Loaded ${type} strategy data:\n`));
        // Pretty print the JSON data
        console.log(chalk_1.default.gray(JSON.stringify(data, null, 2)));
        console.log(chalk_1.default.cyan("\n💡 TypeScript Usage:"));
        console.log(chalk_1.default.gray("```typescript"));
        console.log(chalk_1.default.gray("import { BuildStrategyManager } from './buildStrategyManager';"));
        console.log(chalk_1.default.gray(""));
        console.log(chalk_1.default.gray("const manager = new BuildStrategyManager();"));
        console.log(chalk_1.default.gray(`const ${type}Data = await manager.loadStrategyData('${type}');`));
        console.log(chalk_1.default.gray(""));
        console.log(chalk_1.default.gray("// Access the data"));
        console.log(chalk_1.default.gray(`console.log(${type}Data);`));
        console.log(chalk_1.default.gray("```"));
    }
    catch (error) {
        console.log(chalk_1.default.red(`❌ Error loading ${type} strategy data:`));
        console.log(chalk_1.default.gray(`   ${error}`));
        console.log(chalk_1.default.yellow("\n💡 Try running 'mycontext build-strategy --list' to see available files"));
    }
}
//# sourceMappingURL=build-strategy.js.map