export const mergeHistory = (a: any, b: any) => b;

export interface MergeableOperation {
  type: string;
  data: any;
  timestamp: number;
  nodeId?: string;
  edgeId?: string;
  groupId?: string;
}

export interface SmartHistoryMergerOptions {
  mergeWindow?: number;
  mergeableTypes?: string[];
  onCommit?: () => void;
}

export class SmartHistoryMerger {
  private pendingOperation: MergeableOperation | null = null;
  private history: MergeableOperation[] = [];
  private options: SmartHistoryMergerOptions;

  constructor(options?: SmartHistoryMergerOptions) {
    this.options = options ?? {};
  }

  addOperation(operation: MergeableOperation) {
    this.pendingOperation = operation;
  }

  commitPendingOperation() {
    if (this.pendingOperation) {
      this.history.push(this.pendingOperation);
      this.pendingOperation = null;
      this.options.onCommit?.();
    }
  }

  getHistory() {
    return this.history;
  }
}
