package pert;
import java.awt.Color;

public class PertNode {
	private final int id;	// Identifiant unique
	private int x;
	private int y;
	private int radius;
	private String label;
	private Color color;
	private int start;		// Date de début au plus tôt
	private int end;		// Date de fin au plus tard

	public PertNode(int id) {
		this(id, 0, 0, 20, Integer.toString(id), Color.WHITE, 0, 0);
	}

	public PertNode(int id, int x, int y, int radius, String label,
			Color color, int start, int end) {
		this.id = id;
		this.x = Math.max(0, x);
		this.y = Math.max(0, y);
		this.radius = Math.max(20, radius);
		this.label = "".equals(label) ? Integer.toString(id) : label;
		this.color = color;
		this.start = Math.max(0, start);
		this.end = Math.max(0, end);
	}
	
	public int getId() {
		return this.id;
	}
	
	public int getX() {
		return this.x;
	}
	
	public void setX(int x) {
		this.x = Math.max(0, x);
	}
	
	public int getY() {
		return this.y;
	}
	
	public void setY(int y) {
		this.y = Math.max(0, y);
	}

	public int getRadius() {
		return this.radius;
	}
	
	public void setRadius(int radius) {
		this.radius = Math.max(20, radius);
	}
	
	public String getLabel() {
		return this.label;
	}

	public void setLabel(String label){
		if(label != null) {
			this.label = label;
		}
	}
	
	public Color getColor() {
		return color;
	}
	
	public void setColor(Color color) {
		if(color == null)
			this.color = Color.WHITE;
		else
			this.color = color;
	}
	
	public int getStart() {
		return this.start;
	}

	public void setStart(int start){
		this.start = Math.max(0, start);
	}
	
	public int getEnd() {
		return this.end;
	}

	public void setEnd(int end){
		this.end = Math.max(0, end);
	}

	@Override
	public String toString() {
		String colorHex = "#" + Integer.toHexString(color.getRGB()).substring(2).toUpperCase();
		return String.format("id=%d, l='%s', x=%d, y=%d, r=%d, c=%s, start=%d, end=%d", id, label, x, y, radius, colorHex, start, end);
	}
	
	@Override
	public int hashCode() {
		return id;
	}

	@Override
	public boolean equals(Object o) {
		return (o instanceof PertNode) && (id == ((PertNode)o).getId());
	}
}