import java.io.*;

/**
 * a Job contains all the information to perform a file Stamping
 * @author 413
 *
 */
public class Job
{
	static ServiceJob service = new ServiceJob(); //to save or load a job
	static int cpt = 0 ;
	
	private Result result;			//result from the stamping
	private File PDFSource;			//Source PDF file to process
	private File PDFStamp;			//Stamp PDF file to use
	private File PDFStampType;		//Stamp type to use
	private Integer StartPage;		//Start page number
	private Integer LastPage;		//Last page number
	private String Parameter1;		//Parameter1 replacement string
	private String Parameter2;		//Parameter2 replacement string
	private String Parameter3;		//Parameter3 replacement string
	private String Parameter4;		//Parameter4 replacement string
	private String Parameter5;		//Parameter5 replacement string
	
	private File jobFile;		//Link to job.xml file
	
	/**
	 * Constructor
	 */
	public Job()
	{
		cpt++;
		jobFile = new File(ServiceConfig.job+"\\Job"+cpt+".xml");
		result = new Result();
		result.setResultFile(new File(ServiceConfig.result+"\\Result"+cpt+".xml"));
	}

	/**
	 * load the file from job.xml file(return the job loaded)
	 * @param jobFile
	 * @return
	 */
	static public Job load(File jobFile)
	{
		cpt++;
		Job ret = service.load(jobFile);
		ret.setjobFile(jobFile);
		if(ret.getResultFile().exists())
		{
			ServiceResult servR = new ServiceResult();
			ret.setResult(servR.load(ret.getResultFile()));
		}
		return ret;
	}
	
	/**
	 * save the job into a job.xml file
	 */
	public void save()
	{
		service.save(this);
	}

	/**
	 * Used by JList
	 */
	public String toString()
	{
		return PDFSource.getName();
	}

	/**
	 * return the PDF file
	 * @return
	 */
	public File getPDFSource()
	{
		return PDFSource;
	}

	/**
	 * set the PDF file
	 */
	public void setPDFSource(File pDFSource)
	{
		PDFSource = pDFSource;
	}

	/**
	 * return stamp file
	 */
	public File getPDFStamp()
	{
		return PDFStamp;
	}

	/**
	 * set the stamp file
	 */
	public void setPDFStamp(File pDFStamp)
	{
		PDFStamp = pDFStamp;
	}

	/**
	 * return the folder containing stamps of select type
	 */
	public File getPDFStampType()
	{
		return PDFStampType;
	}

	/**
	 * set the folder containing stamps of select type
	 */
	public void setPDFStampType(File pDFStampType)
	{
		PDFStampType = pDFStampType;
	}

	/**
	 * return the page where the stamping begin
	 */
	public Integer getStartPage()
	{
		return StartPage;
	}

	/**
	 * set the page where the stamping begin
	 */
	public void setStartPage(Integer startPage)
	{
		StartPage = startPage;
	}

	/**
	 * return the page where the stamping end
	 */
	public Integer getLastPage()
	{
		return LastPage;
	}

	/**
	 * set the page where the stamping end
	 */
	public void setLastPage(Integer lastPage)
	{
		LastPage = lastPage;
	}

	/**
	 * return the parameter 1
	 */
	public String getParameter1()
	{
		return Parameter1;
	}

	/**
	 * set the parameter 1
	 */
	public void setParameter1(String parameter1)
	{
		Parameter1 = parameter1;
	}

	/**
	 * return the parameter 2
	 */
	public String getParameter2()
	{
		return Parameter2;
	}

	/**
	 * set the parameter 2
	 */
	public void setParameter2(String parameter2)
	{
		Parameter2 = parameter2;
	}

	/**
	 * return the parameter 3
	 */
	public String getParameter3()
	{
		return Parameter3;
	}

	/**
	 * set the parameter 3
	 */
	public void setParameter3(String parameter3)
	{
		Parameter3 = parameter3;
	}

	/**
	 * return the parameter 4
	 */
	public String getParameter4()
	{
		return Parameter4;
	}

	/**
	 * set the parameter 4
	 */
	public void setParameter4(String parameter4)
	{
		Parameter4 = parameter4;
	}

	/**
	 * return the parameter 5
	 */
	public String getParameter5()
	{
		return Parameter5;
	}

	/**
	 * set the parameter 5
	 */
	public void setParameter5(String parameter5)
	{
		Parameter5 = parameter5;
	}

	/**
	 * return the job.xml file
	 */
	public File getjobFile()
	{
		return jobFile;
	}

	/**
	 * set the job.sml file
	 */
	public void setjobFile(File jobFile)
	{
		this.jobFile = jobFile;
	}

	/**
	 * return the result.xml file
	 */
	public File getResultFile()
	{
		return result.getResultFile();
	}

	/**
	 * set the result.xml file
	 */
	public void setResultFile(File resultFile)
	{
		result.setResultFile(resultFile);
	}

	/**
	 * return the result of the stamping
	 * @return
	 */
	public Result getResult()
	{
		return result;
	}

	/**
	 * set the result from the stamping
	 * @param result
	 */
	public void setResult(Result result)
	{
		this.result = result;
	}
}