/*
 * Created on Jun 23, 2004
 *  
 */
package net.sourceforge.fenixedu.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class EntryPhase implements Serializable, Comparable<EntryPhase> {

    public static final int FIRST_PHASE = 1;

    public static final int SECOND_PHASE = 2;

    public static final int THIRD_PHASE = 3;

    public static final String FIRST_PHASE_STRING = "1ª Fase";

    public static final String SECOND_PHASE_STRING = "2ª Fase";

    public static final String THIRD_PHASE_STRING = "3ª Fase";

    public static final EntryPhase FIRST_PHASE_OBJ = new EntryPhase(EntryPhase.FIRST_PHASE);

    public static final EntryPhase SECOND_PHASE_OBJ = new EntryPhase(EntryPhase.SECOND_PHASE);

    public static final EntryPhase THIRD_PHASE_OBJ = new EntryPhase(EntryPhase.THIRD_PHASE);

    private Integer entryPhase;

    public EntryPhase() {
    }

    public EntryPhase(int entryPhase) {
	this.entryPhase = new Integer(entryPhase);
    }

    public EntryPhase(Integer entryPhase) {
	this.entryPhase = entryPhase;
    }

    public EntryPhase(String entryPhase) {
	if (entryPhase.equals(EntryPhase.FIRST_PHASE_STRING))
	    this.entryPhase = new Integer(EntryPhase.FIRST_PHASE);
	if (entryPhase.equals(EntryPhase.SECOND_PHASE_STRING))
	    this.entryPhase = new Integer(EntryPhase.SECOND_PHASE);
	if (entryPhase.equals(EntryPhase.THIRD_PHASE_STRING))
	    this.entryPhase = new Integer(EntryPhase.THIRD_PHASE);
    }

    public Integer getEntryPhase() {
	return entryPhase;
    }

    /**
         * @param entryPhase
         *                The entryPhase to set.
         */
    public void setEntryPhase(Integer entryPhase) {
	this.entryPhase = entryPhase;
    }

    public String toString() {
	switch (entryPhase.intValue()) {
	case FIRST_PHASE:
	    return "FIRST_PHASE";
	case SECOND_PHASE:
	    return "SECOND_PHASE";
	case THIRD_PHASE:
	    return "THIRD_PHASE";
	default:
	    throw new Error("Unknown entry phase value.");
	}
    }

    public static List<EntryPhase> getAll() {
	ArrayList<EntryPhase> result = new ArrayList<EntryPhase>();
	result.add(EntryPhase.FIRST_PHASE_OBJ);
	result.add(EntryPhase.SECOND_PHASE_OBJ);
	result.add(EntryPhase.THIRD_PHASE_OBJ);
	return result;
    }

    public String getName() {
	if (this.entryPhase.equals(1)) {
	    return EntryPhase.FIRST_PHASE_STRING;
	}
	if (this.entryPhase.equals(2)) {
	    return EntryPhase.SECOND_PHASE_STRING;
	}
	if (this.entryPhase.equals(3)) {
	    return EntryPhase.THIRD_PHASE_STRING;
	}
	return null;
    }

    @Override
    public boolean equals(Object obj) {
	if (obj instanceof EntryPhase) {
	    return ((EntryPhase) obj).getEntryPhase().equals(this.getEntryPhase());
	}
	return false;
    }

    public static EntryPhase valueOf(int phase) {
	switch (phase) {
	case 1:
	    return FIRST_PHASE_OBJ;
	case 2:
	    return SECOND_PHASE_OBJ;
	case 3:
	    return THIRD_PHASE_OBJ;
	default:
	    return null;
	}
    }

    public int compareTo(EntryPhase entryPhase) {
	return this.getEntryPhase().compareTo(entryPhase.getEntryPhase());
    }

}