package de.thomasjacob.improve.logic.issue;

import de.thomasjacob.improve.logic.project.Project;
import de.thomasjacob.improve.logic.user.User;
import de.thomasjacob.webcore.logic.Model;

import java.util.ArrayList;
import java.util.List;


public class Issue extends Model
{
	/**
	 * Closed.
	 */
	public static final int STATUS_CLOSED = 4;

	/**
	 * Freshly reported.
	 */
	public static final int STATUS_NEW = 1;

	/**
	 * To be done.
	 */
	public static final int STATUS_OPEN = 2;

	/**
	 * Done, but not yet tested by the manager.
	 */
	public static final int STATUS_PROCESSED = 3;

	/**
	 * Tested, but not yet closed.
	 */
	public static final int STATUS_TESTED = 6;

	/**
	 * Rejected.
	 */
	public static final int STATUS_REJECTED = 5;

	/**
	 * The issue is a bug report.
	 */
	public static final int TYPE_BUG = 1;

	/**
	 * The issue is a feature request.
	 */
	public static final int TYPE_REQUEST = 2;

	private User reporter = null;

	private String description = "";

	private User developer = null;

	private List historyEntries = new ArrayList();

	private String name = "";

	private int priority = 0;

	private Project project;

	private int status = 0;

	private int type = 0;

	public User getReporter()
	{
		return this.reporter;
	}

	public String getDescription()
	{
		return this.description;
	}

	public User getDeveloper()
	{
		return this.developer;
	}

	public List getHistoryEntries()
	{
		return this.historyEntries;
	}

	public String getName()
	{
		return this.name;
	}

	public int getPriority()
	{
		return this.priority;
	}

	public Project getProject()
	{
		return this.project;
	}

	public int getStatus()
	{
		return this.status;
	}

	public static String getStatusName(int status)
	{
		switch (status)
		{
			case Issue.STATUS_NEW:
				return "New";

			case Issue.STATUS_OPEN:
				return "Open";

			case Issue.STATUS_PROCESSED:
				return "Processed";

			case Issue.STATUS_TESTED:
				return "Tested";

			case Issue.STATUS_CLOSED:
				return "Closed";

			case Issue.STATUS_REJECTED:
				return "Rejected";

			default:
				throw new IllegalArgumentException("Unknown status " + status);
		}
	}

	public String getStatusName()
	{
		return getStatusName(status);
	}

	public int getType()
	{
		return this.type;
	}

	public String getTypeName()
	{
		switch (type)
		{
			case Issue.TYPE_BUG:
				return "Bug";

			case Issue.TYPE_REQUEST:
				return "Request";

			default:
				throw new IllegalArgumentException("Unknown type " + type);
		}
	}

	public void setReporter(User reporter)
	{
		this.reporter = reporter;
	}

	public void setDescription(String description)
	{
		if (description == null)
		{
			description = "";
		}

		this.description = description;
	}

	public void setDeveloper(User developer)
	{
		this.developer = developer;
	}

	public void setHistoryEntries(List historyEntries)
	{
		this.historyEntries = historyEntries;
	}

	public void setName(String name)
	{
		if (name == null)
		{
			name = "";
		}

		this.name = name;
	}

	public void setPriority(int priority)
	{
		this.priority = priority;
	}

	public void setProject(Project project)
	{
		this.project = project;
	}

	public void setStatus(int status)
	{
		this.status = status;
	}

	public void setType(int type)
	{
		this.type = type;
	}
}
