import { Command } from './Command';
import { Edge } from '@xyflow/react';

/**
 * Command to add an edge to the canvas
 */
export class AddEdgeCommand implements Command {
    private edge: Edge;
    private setEdges: (updater: (edges: Edge[]) => Edge[]) => void;

    constructor(
        edge: Edge,
        setEdges: (updater: (edges: Edge[]) => Edge[]) => void
    ) {
        this.edge = edge;
        this.setEdges = setEdges;
    }

    execute(): void {
        this.setEdges((edges) => [...edges, this.edge]);
    }

    undo(): void {
        this.setEdges((edges) => edges.filter(e => e.id !== this.edge.id));
    }

    getDescription(): string {
        return `Add edge: ${this.edge.id}`;
    }
}
