/**
 * Team Mode with Shared Context (Item 101)
 * Enables team collaboration with shared AI context
 */
import { EventEmitter } from 'events';
import crypto from 'crypto';
export class TeamModeManager extends EventEmitter {
    config;
    members = new Map();
    context;
    syncTimer = null;
    constructor(config) {
        super();
        this.config = {
            syncInterval: 30000,
            maxMembers: 50,
            retentionDays: 30,
            ...config,
        };
        this.context = {
            projectInfo: { name: '', path: '', description: '' },
            sharedKnowledge: new Map(),
            codePatterns: [],
            conventions: [],
            history: [],
        };
    }
    addMember(name, role = 'member') {
        if (this.members.size >= this.config.maxMembers) {
            throw new Error('Team is at capacity');
        }
        const member = {
            id: crypto.randomBytes(8).toString('hex'),
            name,
            role,
            joinedAt: new Date(),
            lastActive: new Date(),
        };
        this.members.set(member.id, member);
        this.emit('member-joined', member);
        return member;
    }
    removeMember(memberId) {
        const deleted = this.members.delete(memberId);
        if (deleted)
            this.emit('member-left', memberId);
        return deleted;
    }
    addKnowledge(key, value) {
        this.context.sharedKnowledge.set(key, value);
        this.emit('knowledge-updated', { key, value });
    }
    addPattern(pattern) {
        if (!this.context.codePatterns.includes(pattern)) {
            this.context.codePatterns.push(pattern);
        }
    }
    addConvention(convention) {
        if (!this.context.conventions.includes(convention)) {
            this.context.conventions.push(convention);
        }
    }
    recordAction(memberId, type, summary) {
        const action = {
            id: crypto.randomBytes(8).toString('hex'),
            memberId,
            type,
            summary,
            timestamp: new Date(),
        };
        this.context.history.push(action);
        this.emit('action-recorded', action);
        return action;
    }
    getContext() {
        return this.context;
    }
    getMembers() {
        return Array.from(this.members.values());
    }
    startSync() {
        this.syncTimer = setInterval(() => {
            this.emit('sync', this.context);
        }, this.config.syncInterval);
    }
    stopSync() {
        if (this.syncTimer) {
            clearInterval(this.syncTimer);
            this.syncTimer = null;
        }
    }
    dispose() {
        this.stopSync();
        this.members.clear();
        this.removeAllListeners();
    }
}
export function createTeamMode(config) {
    return new TeamModeManager(config);
}
export default TeamModeManager;
//# sourceMappingURL=team-mode.js.map