/**
 * COMP2240 Assignment 1
 * Date: 28/08/21
 * Author: Zach S-B
 * Student Number: c3262201
 */

public class Process {
    
    private String id;
    private int arrive;
    private int execSize;
    private int tickets;

    
    private int remainingTime;

    //Post Run details
    private int turnAroundTime = -1;
    private int waitTime = -1;
    private int startTime = -1;
    private int endTime= -1;

    //For FBV
    private int inQueueTime = 0;
     

    //Constructors
    public Process(){
    }

    public Process(String idInput, int arriveInput, int execSizeInput, int ticketsInput) {
        id = idInput;
        arrive = arriveInput;
        execSize = execSizeInput;
        tickets = ticketsInput;
        remainingTime = execSizeInput;
    }

    //Setters
    public void setId(String idInput){
        id = idInput;
    }
    public void setArrive(int arriveInput){
        arrive = arriveInput;
    }
    public void setSize(int execSizeInput){
        execSize = execSizeInput;
        remainingTime = execSizeInput;
    }
    public void setTickets(int ticketsInput){
        tickets = ticketsInput;
    }
    public void setEndTime(int timeInput)
    {
        endTime=timeInput;
    }

    public void setTurnTime(){
        turnAroundTime = endTime-arrive;
    }

    //Getters
    public String getId(){
        return id;
    }
    public int getArrive(){
        return arrive;
    }    
    public int getExecSize(){
        return execSize;
    }  
    public int getTickets(){
        return tickets;
    }  
    public int getTurnTime(){
        return turnAroundTime;
    }
    public int getWaitTime(){
        return waitTime;
    }   
    public int getStartTime()
    {
        return startTime;
    }
    public int getEndTime()
    {
        return endTime;
    }
    public int getRemainingTime()
    {
        return remainingTime;
    }
    public int getQueueTime()
    {
       return inQueueTime;
    }        


    //Functions
    public void runForOneTick(boolean isRunning)
    {
        if(isRunning)
        {
            remainingTime--;
        }
        else
        {
            wait(1);
        }
        addQueueTime(1);
    }

    public void wait(int time)
    {
        if(waitTime==-1)
        {
            waitTime=time;
        }
        else
        {           
            waitTime+= time;
        }   
    }
    
    public boolean isDone()
    {
        if (remainingTime <= 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public void reset()
    {
        turnAroundTime = -1;
        waitTime = -1;
        remainingTime = execSize;
        startTime = -1;
        endTime = -1;
    }

    public void addQueueTime(int time)
    {
        inQueueTime+=time;
    }

    public void resetQueueTime()
    {
        inQueueTime=0;
    }    
}