"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReadmeDeducer = void 0;
class ReadmeDeducer {
    /**
     * Deduce a full README.md content from project context and/or snapshot
     */
    deduceFullReadme(context, snapshot) {
        const projectName = context?.metadata?.projectConfig?.name || snapshot?.keyFiles?.find(f => f.path.endsWith('package.json'))
            ? this.extractPackageName(snapshot?.keyFiles?.find(f => f.path.endsWith('package.json'))?.content)
            : "The Project";
        const description = context?.metadata?.projectConfig?.description || "A high-fidelity workspace built with MyContext.";
        let content = `# ${projectName}\n\n`;
        content += `${description}\n\n`;
        // 1. Overview Section
        content += `## 🎯 Project Overview\n`;
        content += `${context?.prd?.problemStatement || "This project is built using a spec-driven development paradigm guided by a central 'Living Brain'."}\n\n`;
        // 2. Key Features
        const features = context?.features;
        if (features && features.length > 0) {
            content += `## ✨ Key Features\n`;
            features.slice(0, 10).forEach(f => {
                content += `- **${f.name}**: ${f.description}\n`;
            });
            content += `\n`;
        }
        // 3. Technical Stack
        const techStack = context?.specs?.techStack;
        if (techStack) {
            content += `## 🛠️ Technical Stack\n`;
            if (techStack.frontend?.length)
                content += `- **Frontend**: ${techStack.frontend.join(", ")}\n`;
            if (techStack.backend?.length)
                content += `- **Backend**: ${techStack.backend.join(", ")}\n`;
            if (techStack.database?.length)
                content += `- **Database**: ${techStack.database.join(", ")}\n`;
            if (techStack.other?.length)
                content += `- **Tools**: ${techStack.other.join(", ")}\n`;
            content += `\n`;
        }
        // 4. Project Structure (Deduce from Snapshot)
        if (snapshot) {
            content += `## 📂 Project Structure\n`;
            content += `\`\`\`bash\n`;
            // Filter for top-level directories and interesting files
            const structure = snapshot.fileTree
                .filter(f => f.path.split('/').length <= 2 && !f.path.includes('node_modules') && !f.path.includes('.git'))
                .map(f => {
                const parts = f.path.split('/');
                const depth = parts.length;
                const name = parts[parts.length - 1];
                return `${'  '.repeat(depth - 1)}${f.type === 'dir' ? '📁' : '📄'} ${name}`;
            })
                .slice(0, 30) // Cap it
                .join('\n');
            content += structure + "\n";
            content += `\`\`\`\n\n`;
        }
        // 5. Quick Start
        content += `## 🚀 Quick Start\n`;
        content += `1. **Install Dependencies**:\n   \`\`\`bash\n   pnpm install\n   \`\`\`\n`;
        content += `2. **Run Dev Server**:\n   \`\`\`bash\n   npm run dev\n   \`\`\`\n\n`;
        // 6. MyContext Markers
        content += `<!-- mycontext:start -->\n`;
        content += `<!-- mycontext:end -->\n\n`;
        content += `---\n*Generated by MyContext CLI - Living Brain JSON Source*\n`;
        return content;
    }
    /**
     * Update syncable sections in an existing README
     */
    generateSyncContent(context, extraContent) {
        let content = "\n";
        content += `### 🎯 Project Overview\n`;
        content += `${context.prd?.problemStatement || "AI-driven development platform."}\n\n`;
        if (context.features && context.features.length > 0) {
            content += `### ✨ Key Features\n`;
            context.features.slice(0, 5).forEach(f => {
                content += `- ${f.name}\n`;
            });
            content += "\n";
        }
        if (context.specs?.techStack) {
            content += `### 🛠️ Technical Stack\n`;
            const stack = context.specs.techStack;
            if (stack.frontend?.length)
                content += `- **Frontend**: ${stack.frontend.slice(0, 3).join(", ")}\n`;
        }
        if (extraContent) {
            content += `\n${extraContent}\n\n`;
        }
        content += `--- \n`;
        content += `_Last synchronized with MyContext Living DB on ${new Date().toLocaleDateString() || "today"}_\n`;
        return content;
    }
    extractPackageName(pkgJsonContent) {
        if (!pkgJsonContent)
            return "The Project";
        try {
            const pkg = JSON.parse(pkgJsonContent);
            return pkg.name || "The Project";
        }
        catch {
            return "The Project";
        }
    }
}
exports.ReadmeDeducer = ReadmeDeducer;
//# sourceMappingURL=ReadmeDeducer.js.map