package mtsar.resources;

import mtsar.api.*;
import mtsar.api.Process;

import javax.inject.Singleton;
import javax.validation.constraints.NotNull;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Collections;
import java.util.List;
import java.util.Set;

@Produces(MediaType.APPLICATION_JSON)
public class AnswerResource {
    final protected Process process;

    public AnswerResource(Process process) {
        this.process = process;
    }

    @GET
    public List<Answer> getAnswers() {
        return process.getAnswerDAO().listForProcess(process.getId());
    }

    @POST
    public Answer postAnswer(@FormParam("worker") String worker, @FormParam("task") String task, @FormParam("processors") String answer, @FormParam("timestamp") String timestamp) {
//        final Timestamp
        final Answer a = Answer.builder().
                setProcess(process.getId()).
                setDateTime(Timestamp.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant())).
                build();
        int answerId = process.getAnswerDAO().insert(a);
        return process.getAnswerDAO().find(answerId, process.getId());
    }
}

@@ -854,16 +854,21 @@
 g answer
+Param
 , @FormP
@@ -905,14 +905,17 @@
 tamp
+Param
 ) %7B%0A
-//
     
@@ -933,16 +933,203 @@
 imestamp
+ timestamp = (timestampParam == null) ?%0A                Timestamp.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant()) :%0A                Timestamp.valueOf(timestampParam);
 %0A       
@@ -1143,16 +1143,21 @@
 Answer a
+nswer
  = Answe
@@ -1237,95 +1237,66 @@
  set
-DateTime(Timestamp.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant())
+Answer(answerParam).%0A                setDateTime(timestamp
 ).%0A 
@@ -1373,16 +1373,21 @@
 insert(a
+nswer
 );%0A     

Make it possible to specify timestamp in postAnswer