/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.edu.pwr.nlprestservice;

import java.util.Date;
import java.util.UUID;
import pl.edu.pwr.nlptools.NLPTool;
import pl.edu.pwr.nlptools.NLPToolException;
import pl.edu.pwr.nlptools.Status;

/**
 *
 * @author Tomasz Walkowiak
 * 
 *  Klasa reprezentuje zlozone zadanie
 */
class Task {
    
   final static String prefix="_$";
   private String taskID;
   
   private String nextTool;
   
   
   private Date startDate=null; 
   private Date finishDate=null;
    static boolean isTaskID(String taskID) {
        return taskID.startsWith(prefix);
    }

    Task(String taskID, String serviceName) {
       this.taskID=taskID;
       this.nextTool=serviceName;
       startDate=new Date();
    }

    String getID() {
        return prefix+UUID.randomUUID();
    }

    Status checkStatus() throws NLPToolException {
       
        NLPTool tool=new NLPTool(nextTool);
        Status st=tool.check(taskID);
        if (st.isReady() && nextTool!=null )
        { taskID=tool.startTask(st.getValue());
          nextTool=null;
          st=tool.check(taskID);
        }
        if (st.isReady()) finishDate=new Date();
       return st;
    }
}
