package pert;
import java.awt.Color;

import org.jgrapht.graph.DefaultEdge;

public class PertEdge extends DefaultEdge {

	private static final long serialVersionUID = 1L;
	private final String task; // Nom de la tâche
	private int duration;      // Durée de la tâche
	private boolean critical;  // Indique si la tâche est critique (true)
	
	public PertEdge(String task) {
		this(task, 0, false);
	}

	public PertEdge(String task, int duration, boolean critical) {
		this.task = "".equals(task) ? "?" : task;
		this.duration = Math.max(0, duration);
		this.critical = critical;
	}
	
	public Color getColor() {
		return critical ? Color.BLUE : (duration == 0) ? Color.red : Color.black;
	}

	public int getDuration() {
		return duration;
	}

	public void setDuration(int duration) {
		this.duration = Math.max(0, duration);
	}

	public boolean getCritical() {
		return this.critical;
	}

	public void setCritical(boolean critical) {
		this.critical = critical;
	}

	public int getStroke() {
		return critical ? 2 : 1;
	}

	public String getTask() {
		return task;
	}

	@Override
    public String toString()
    {
        return "(" + getSource() + " : " + getTarget() + " : " + getTask() + "/" + getDuration() + ")";
    }

	@Override
	public boolean equals(Object o) {
		return (o instanceof PertEdge) && task.equals(((PertEdge)o).getTask());
	}

}
