package cnp.ew.kdemo;

import java.util.*;
import java.awt.*;

import cnp.ew.properties.*;
import cnp.ew.diagram.*;
import cnp.ew.converter.*;
import cnp.ew.displayer.*;
import cnp.ew.util.*;
import cnp.ew.list.*;

public class CpEmployee implements CpListItem
{
    public final static int NAME_PROP = 0;
    public static final int TITLE_PROP = 1;
    public static final int WORK_PHONE_PROP = 2;
    public static final int HOME_PHONE_PROP = 3;
    public final static int AGE_PROP = 4;
    public final static int YEARS_WITH_PROP = 5;
    public final static int SOCIAL_SECURITY_NUMBER_PROP = 6;
    public final static int BIRTHDAY_PROP = 7;
    public final static int MARRIED_PROP = 8;
    public final static int SALARY_PROP = 9;
    public final static int RATING_PROP = 10;

    static Vector properties;

    String name;
    String title;
    String workPhone;
    String homePhone;
    int age;
    int yearsWithCompany;
    String socialSecurityNumber;
    Date birthday;
    boolean married;
    int salary;
    int rating;

    int imageId;
    Image image;

    public CpEmployee(String newName, int newAge, Date newBirth, boolean newMarried, int newSalary, int newRating)
    {
        super();
        name = newName;
        age = newAge;
        birthday = newBirth;
        married = newMarried;
        salary = newSalary;
        rating = newRating;
    }

    public CpEmployee(
        String newName, String newTitle, String newWorkPhone,
        String newHomePhone, int newAge, int newYearsWithCompany,
        String newSocialSecurityNumber, Date newBirth, boolean newMarried, int newImageId)
    {
        super();
        name = newName;
        title = newTitle;
        workPhone = newWorkPhone;
        homePhone = newHomePhone;
        age = newAge;
        yearsWithCompany = newYearsWithCompany;
        socialSecurityNumber = newSocialSecurityNumber;
        birthday = newBirth;
        married = newMarried;

        imageId = newImageId;
    }

	public boolean isLessThan(CpHasProperties item2, CpProperty prop)
	{
	    Object myProp = getProperty(prop);
	    if (myProp instanceof String) {
    	    return ((String)myProp).compareTo((String)item2.getProperty(prop)) < 0;
    	} else if (myProp instanceof Integer) {
    	    return ((Integer)myProp).intValue() < ((Integer)item2.getProperty(prop)).intValue();
    	} else if (myProp instanceof Boolean) {
    	    return !((Boolean)myProp).booleanValue();
    	} else if (myProp instanceof Date) {
    	    return ((Date)myProp).before((Date)item2.getProperty(prop));
    	}
    	return true;
    }

    public Object getProperty(CpProperty prop)
    {
        switch (prop.getId()) {
        case NAME_PROP:
            return name;
        case TITLE_PROP:
            return title;
        case WORK_PHONE_PROP:
            return workPhone;
        case HOME_PHONE_PROP:
            return homePhone;
        case AGE_PROP:
            return new Integer(age);
        case YEARS_WITH_PROP:
            return new Integer(yearsWithCompany);
        case SOCIAL_SECURITY_NUMBER_PROP:
            return socialSecurityNumber;
        case BIRTHDAY_PROP:
            return birthday;
        case SALARY_PROP:
            return new Integer(salary);
        case MARRIED_PROP:
            return new Boolean(married);
        case RATING_PROP:
            return new Integer(rating);
        }
        return null;
    }

    public void setProperty(CpProperty prop, Object o)
    {
        switch (prop.getId()) {
        case NAME_PROP :
            name = (String)o;
            break;
        case TITLE_PROP:
            title = (String)o;
            break;
        case WORK_PHONE_PROP:
            workPhone = (String)o;
            break;
        case HOME_PHONE_PROP:
            homePhone = (String)o;
            break;
        case AGE_PROP :
            age = ((Integer)o).intValue();
            break;
        case SALARY_PROP :
            salary = ((Integer)o).intValue();
            break;
        case YEARS_WITH_PROP:
            yearsWithCompany = ((Integer)o).intValue();
            break;
        case SOCIAL_SECURITY_NUMBER_PROP:
            socialSecurityNumber = (String)o;
            break;
        case BIRTHDAY_PROP :
            birthday = (Date)o;
            break;
        case MARRIED_PROP :
            married = ((Boolean)o).booleanValue();
            break;
        case RATING_PROP :
            rating = ((Integer)o).intValue();
            break;
        }
    }

    public Vector getProperties()
    {
        if (properties == null) {
            properties = new Vector(4);
            properties.addElement(new CpProperty("Name", CpBasicType.STRING, NAME_PROP));
            properties.addElement(new CpProperty("Title", CpBasicType.STRING, TITLE_PROP));
            properties.addElement(new CpProperty("Work Phone", CpBasicType.PHONE_NUMBER, WORK_PHONE_PROP));
            properties.addElement(new CpProperty("Home Phone", CpBasicType.PHONE_NUMBER, HOME_PHONE_PROP));
            properties.addElement(new CpProperty("Age", CpBasicType.NUMBER, AGE_PROP));
            properties.addElement(new CpProperty("Years With Us", CpBasicType.NUMBER, YEARS_WITH_PROP));
            properties.addElement(new CpProperty("SSN", CpBasicType.SOCIAL_SECURITY_NUMBER, SOCIAL_SECURITY_NUMBER_PROP));
            properties.addElement(new CpProperty("Date of Birth", CpBasicType.DATE, BIRTHDAY_PROP));
            properties.addElement(new CpProperty("Married", CpBasicType.BOOLEAN, MARRIED_PROP));
            properties.addElement(new CpProperty("Salary", CpBasicType.CURRENCY, SALARY_PROP));
            properties.addElement(new CpProperty("Rating", CpBasicType.NUMBER, RATING_PROP));
        }
        return properties;
    }

    public Image getImage()
    {
        if (image == null) {
            image = CpToolkit.getImage(imageId);
        }
        return image;
    }

    public String getName()
    {
        return name;
    }

    public String getTitle()
    {
        return title;
    }

    public int getYearsWithCompany()
    {
        return yearsWithCompany;
    }
}

