import java.io.File;
import java.util.Date;

import javax.swing.DefaultListModel;

/**
 * Contain the result of the stamping of a job and all errors founds
 * @author 413
 *
 */
public class Result 
{
	static ServiceResult service = new ServiceResult();//to load and save results in XML files
	private String GeneralError;				//general job error (like PDF can't be opened)
	private Integer PageProcessCount;			//number of page processed
	private Integer PageErrorCount;				//Number of page errors detected
	private Date StartJobDateTime;		//starting process date and time
	private Date EndJobDateTime;		//ending process date and time
	private DefaultListModel<Error> errors;		//List of errors
	private File resultFile;					//Link to Result.xml file
	
	/**
	 * 
	 */
	public Result() 
	{
		GeneralError = "No Error";
		PageProcessCount = 0;
		PageErrorCount = 0;
		errors = new DefaultListModel<Error>();
	}

	/**
	 * load the file from job.xml file(return the job loaded)
	 * @param jobFile
	 * @return
	 */
	static public Result load(File ResultFile)
	{
		Result ret = service.load(ResultFile);
		return ret;
	}
	
	/**
	 * save the job into a job.xml file
	 */
	public void save()
	{	
		service.save(this);
	}


	/**
	 * return the general error of execution ("no error" if no error has closed the stamping)
	 * @return
	 */
	public String getGeneralError()
	{
		return GeneralError;
	}

	/**
	 * set the general error
	 * @param generalError
	 */
	public void setGeneralError(String generalError)
	{
		GeneralError = generalError;
	}

	/**
	 * return the number of pages processed
	 * @return
	 */
	public Integer getPageProcessCount()
	{
		return PageProcessCount;
	}

	/**
	 * set the number of pages processed
	 * @param pageProcessCount
	 */
	public void setPageProcessCount(Integer pageProcessCount)
	{
		PageProcessCount = pageProcessCount;
	}

	/**
	 * return the number of errors
	 * @return
	 */
	public Integer getPageErrorCount()
	{
		return PageErrorCount;
	}

	/**
	 * set the number of errors
	 * @param pageErrorCount
	 */
	public void setPageErrorCount(Integer pageErrorCount)
	{
		PageErrorCount = pageErrorCount;
	}

	/**
	 * get when the stamping began
	 * @return
	 */
	public Date getStartJobDateTime()
	{
		return StartJobDateTime;
	}

	/**
	 * set when the stamping began
	 * @param startJobDateTime
	 */
	public void setStartJobDateTime(Date startJobDateTime)
	{
		StartJobDateTime = startJobDateTime;
	}

	/**
	 * get when the stamping stopped
	 * @return
	 */
	public Date getEndJobDateTime()
	{
		return EndJobDateTime;
	}

	/**
	 * set when the stamping stopped
	 * @param endJobDateTime
	 */
	public void setEndJobDateTime(Date endJobDateTime)
	{
		EndJobDateTime = endJobDateTime;
	}
	
	/**
	 * add an error
	 * @param errorPageNumber the page of the error
	 * @param errorDescription the description of the error
	 * @param level the danger level of the error
	 */
	public void addError(Integer errorPageNumber, String errorDescription, Integer level)
	{
		errors.addElement(new Error(errorPageNumber, errorDescription, level));
	}
	
	/**
	 * add an error
	 * @param errorPageNumber the page of the error
	 * @param errorDescription the description of the error
	 * @param level the danger level of the error
	 */
	public void addError(Integer errorPageNumber, String errorDescription, Integer level, File screen)
	{
		errors.addElement(new Error(errorPageNumber, errorDescription, level, screen));
	}

	/**
	 * get the errors list
	 * @return
	 */
	public DefaultListModel<Error> getErrors()
	{
		return errors;
	}

	/**
	 * get the File containing the results
	 * @return
	 */
	public File getResultFile() 
	{
		return resultFile;
	}

	/**
	 * set the File containing the results
	 * @param resultFile
	 */
	public void setResultFile(File resultFile) 
	{
		this.resultFile = resultFile;
	}
}
