package fireTester.communicator.server;

import fireTester.interfaces.SubmissionTest;


/**
 * Holds information necessary for the server to track timeouts
 * and resend data when needed to ensure every test is completed
 * at least once.
 */
public class CachedSubmission {
	/**
	 * The submission test.
	 */
	public SubmissionTest submission;
	
	/**
	 * The time of the last message from the executing client in ms.
	 */
	public long lastUpdateTime;
	
	/**
	 * The currently processing unit (0 based index)
	 * -1 if test is in the queue.
	 */
	public int currentUnit;
	
	/**
	 * Constructor.  Cache a submission test.
	 * @param t the submission test to cache
	 */
	public CachedSubmission(SubmissionTest t) {
		assert t != null;

		this.submission = t;
		this.lastUpdateTime = System.currentTimeMillis();
		this.currentUnit = -1;
	}
	
	/**
	 * Call when the client picks up this submission for testing.
	 *
	 */
	public void onReceivePacket() {
		this.lastUpdateTime = System.currentTimeMillis();
	}
	
	/**
	 * Update the time and sets the current unit.
	 * @param nextUnitID -1 if complete
	 */
	public void onCompleteUnit(int nextUnitID) {
		this.lastUpdateTime = System.currentTimeMillis();
		this.currentUnit = nextUnitID;
	}

}
