"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TeamAdvancedEngine = void 0;
const cell_store_1 = require("../walls/06-memory/stores/cell-store");
class TeamAdvancedEngine {
    store;
    data;
    constructor(cellDir) {
        this.store = new cell_store_1.CellStore(cellDir);
        this.data = this.store.read('advanced.json', 'team') || {
            version: 1, updated: Date.now(),
            currentSprint: 1, sprints: [],
            experts: [], recentPrs: 0,
            collectiveBlindSpots: [],
        };
    }
    recordBlindSpot(spotId, description, member) {
        const current = this.getCurrentSprint();
        current.blindSpotHits[spotId] = (current.blindSpotHits[spotId] || 0) + 1;
        if (member && !current.members.includes(member))
            current.members.push(member);
        current.date = Date.now();
        this.updateCollective(spotId, description);
        this.save();
    }
    recordPr() {
        this.getCurrentSprint().prCount++;
        this.data.recentPrs++;
        this.save();
    }
    addExpert(module, expert) {
        const existing = this.data.experts.find(e => e.module === module && e.expert === expert);
        if (existing) {
            existing.count++;
            existing.lastActive = Date.now();
        }
        else
            this.data.experts.push({ module, expert, count: 1, lastActive: Date.now() });
        this.save();
    }
    findExpert(module) {
        return this.data.experts
            .filter(e => e.module.toLowerCase().includes(module.toLowerCase()))
            .sort((a, b) => b.count - a.count)
            .map(e => `${e.expert} (${e.count} edits)`);
    }
    getCollectiveBlindSpots() {
        return this.data.collectiveBlindSpots
            .filter(s => s.sprintCount >= 2)
            .map(s => ({
            description: s.description,
            prPercent: this.data.recentPrs > 0 ? Math.round(s.count / this.data.recentPrs * 100) : 0,
            sprintCount: s.sprintCount,
        }))
            .slice(0, 3);
    }
    getSummary() {
        const lines = [];
        const spots = this.getCollectiveBlindSpots();
        if (spots.length > 0) {
            lines.push(`⚠️  Team blind spots (${spots.length}): ${spots.map(s => `${s.description.slice(0, 20)}... ${s.prPercent}%`).join(', ')}`);
        }
        const topExperts = this.data.experts.sort((a, b) => b.count - a.count).slice(0, 3);
        if (topExperts.length > 0)
            lines.push(`Experts: ${topExperts.map(e => `${e.module}: ${e.expert}`).join(', ')}`);
        if (this.data.recentPrs > 0)
            lines.push(`PRs: ${this.data.recentPrs} total across ${this.data.sprints.length} sprints`);
        return lines;
    }
    getCurrentSprint() {
        let sprint = this.data.sprints.find(s => s.sprint === this.data.currentSprint);
        if (!sprint) {
            sprint = { sprint: this.data.currentSprint, date: Date.now(), prCount: 0, blindSpotHits: {}, members: [] };
            this.data.sprints.push(sprint);
        }
        return sprint;
    }
    updateCollective(spotId, description) {
        const existing = this.data.collectiveBlindSpots.find(s => s.id === spotId);
        if (existing) {
            existing.count++;
            if (!existing.sprintCount || existing.sprintCount < this.data.sprints.length)
                existing.sprintCount++;
        }
        else
            this.data.collectiveBlindSpots.push({ id: spotId, description, count: 1, sprintCount: 1 });
    }
    save() { this.data.updated = Date.now(); this.store.write('advanced.json', this.data, 'team'); }
}
exports.TeamAdvancedEngine = TeamAdvancedEngine;
//# sourceMappingURL=team-advanced-engine.js.map