/**
 * Real-time Collaboration and Workspace Synchronization Service
 * Enables shared contexts, collaborative workflows, and team synchronization
 */
import { EventEmitter } from 'events';
import type { Logger, OptimizelyProduct } from '../types/index.js';
export interface WorkspaceContext {
    id: string;
    name: string;
    description?: string;
    owner: string;
    collaborators: string[];
    createdAt: number;
    updatedAt: number;
    isPublic: boolean;
    settings: {
        allowEditing: boolean;
        requireApproval: boolean;
        syncFrequency: number;
        maxCollaborators: number;
    };
    data: {
        sharedRules: Array<{
            id: string;
            name: string;
            content: string;
            author: string;
            version: number;
            lastModified: number;
        }>;
        projectSettings: Record<string, any>;
        detectedProducts: OptimizelyProduct[];
        learningPatterns: Array<{
            pattern: string;
            confidence: number;
            sharedBy: string;
            votes: number;
        }>;
        collaborativeNotes: Array<{
            id: string;
            content: string;
            author: string;
            timestamp: number;
            tags: string[];
        }>;
    };
}
export interface CollaborationSession {
    id: string;
    workspaceId: string;
    participants: Array<{
        userId: string;
        username: string;
        role: 'owner' | 'editor' | 'viewer';
        joinedAt: number;
        lastActivity: number;
        isActive: boolean;
    }>;
    activeEditors: Set<string>;
    lockState: Map<string, {
        userId: string;
        timestamp: number;
        resource: string;
    }>;
    messageHistory: Array<{
        id: string;
        userId: string;
        message: string;
        timestamp: number;
        type: 'chat' | 'system' | 'notification';
    }>;
}
export interface SyncEvent {
    id: string;
    workspaceId: string;
    type: 'rule_update' | 'setting_change' | 'pattern_share' | 'note_add' | 'user_join' | 'user_leave';
    userId: string;
    timestamp: number;
    data: any;
    version: number;
}
export interface ConflictResolution {
    id: string;
    resourceType: string;
    resourceId: string;
    conflictType: 'edit_conflict' | 'version_mismatch' | 'permission_denied';
    participants: string[];
    proposedChanges: Array<{
        userId: string;
        changes: any;
        timestamp: number;
        rationale?: string;
    }>;
    resolution?: {
        method: 'merge' | 'override' | 'manual';
        finalState: any;
        resolvedBy: string;
        resolvedAt: number;
    };
}
export declare class CollaborationService extends EventEmitter {
    private workspaces;
    private activeSessions;
    private syncEvents;
    private pendingConflicts;
    private logger;
    private syncInterval?;
    private cleanupInterval?;
    constructor(logger: Logger);
    /**
     * Create a new workspace for collaboration
     */
    createWorkspace(config: {
        name: string;
        description?: string;
        owner: string;
        isPublic?: boolean;
        settings?: Partial<WorkspaceContext['settings']>;
    }): WorkspaceContext;
    /**
     * Join a workspace as a collaborator
     */
    joinWorkspace(workspaceId: string, userId: string, username: string, role?: 'editor' | 'viewer'): boolean;
    /**
     * Leave a workspace
     */
    leaveWorkspace(workspaceId: string, userId: string): boolean;
    /**
     * Share a rule with the workspace
     */
    shareRule(workspaceId: string, userId: string, rule: {
        name: string;
        content: string;
    }): boolean;
    /**
     * Update a shared rule
     */
    updateSharedRule(workspaceId: string, userId: string, ruleId: string, updates: {
        name?: string;
        content?: string;
    }): boolean;
    /**
     * Add a collaborative note
     */
    addNote(workspaceId: string, userId: string, note: {
        content: string;
        tags?: string[];
    }): boolean;
    /**
     * Share a learning pattern with the workspace
     */
    sharePattern(workspaceId: string, userId: string, pattern: {
        pattern: string;
        confidence: number;
    }): boolean;
    /**
     * Get workspace information
     */
    getWorkspace(workspaceId: string): WorkspaceContext | null;
    /**
     * Get active session for workspace
     */
    getSession(workspaceId: string): CollaborationSession | null;
    /**
     * Get workspaces for a user
     */
    getUserWorkspaces(userId: string): WorkspaceContext[];
    /**
     * Get recent sync events for a workspace
     */
    getRecentEvents(workspaceId: string, limit?: number): SyncEvent[];
    /**
     * Acquire edit lock for a resource
     */
    acquireLock(workspaceId: string, userId: string, resource: string): boolean;
    /**
     * Release edit lock
     */
    releaseLock(workspaceId: string, userId: string, resource: string): boolean;
    /**
     * Send message to workspace chat
     */
    sendMessage(workspaceId: string, userId: string, message: string, type?: 'chat' | 'system' | 'notification'): boolean;
    /**
     * Get workspace statistics
     */
    getWorkspaceStats(workspaceId: string): {
        collaborators: number;
        activeUsers: number;
        sharedRules: number;
        notes: number;
        patterns: number;
        totalActivity: number;
    } | null;
    /**
     * Export workspace data
     */
    exportWorkspace(workspaceId: string): WorkspaceContext | null;
    /**
     * Import workspace data
     */
    importWorkspace(workspaceData: WorkspaceContext): boolean;
    /**
     * Check if user can edit in workspace
     */
    private canUserEdit;
    /**
     * Check for edit conflicts
     */
    private hasEditConflict;
    /**
     * Handle edit conflict
     */
    private handleEditConflict;
    /**
     * Record sync event
     */
    private recordSyncEvent;
    /**
     * Start sync timer for real-time updates
     */
    private startSyncTimer;
    /**
     * Perform synchronization across active sessions
     */
    private performSync;
    /**
     * Start cleanup timer for old data
     */
    private startCleanupTimer;
    /**
     * Cleanup old data and inactive sessions
     */
    private performCleanup;
    /**
     * Cleanup resources
     */
    destroy(): void;
}
export declare const collaborationService: (logger: Logger) => CollaborationService;
//# sourceMappingURL=collaboration-service.d.ts.map