package pingis.entities;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.validation.constraints.NotNull;
import pingis.entities.sandbox.Submission;

@Entity
public class TaskInstance {

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private long id;

  @NotNull
  @Lob
  private String code;

  // TODO: Decide scaling of rating, then set @DecimalMin and @DecimalMax constraints here
  private float rating;

  @OneToOne
  private Submission submission;

  @NotNull
  private CodeStatus status;

  @NotNull
  private boolean isExample; // true if accepted as model solution

  @ManyToOne(fetch = FetchType.LAZY)
  private Task task;

  @NotNull
  @ManyToOne(fetch = FetchType.EAGER)
  private User user;

  @ManyToOne
  private TaskInstance testTaskInstance;

  @OneToMany
  private List<TaskInstance> implementationTaskInstances;

  protected TaskInstance() {
  }

  public TaskInstance(User user, String code, Task task) {
    this.user = user;
    this.code = code;
    this.task = task;
    this.status = CodeStatus.IN_PROGRESS;
    this.isExample = false; // by default
    this.rating = 0;
    this.implementationTaskInstances = new ArrayList();
  }

  public long getId() {
    return id;
  }

  public String getCode() {
    return code;
  }

  public void setCode(String code) {
    this.code = code;
  }

  public float getRating() {
    return rating;
  }

  public void setRating(float rating) {
    this.rating = rating;
  }

  public boolean isExample() {
    return isExample;
  }

  public void setIsExample(boolean isExample) {
    this.isExample = isExample;
  }

  public CodeStatus getStatus() {
    return status;
  }

  public void setStatus(CodeStatus status) {
    this.status = status;
  }

  public Task getTask() {
    return task;
  }

  public void setTask(Task task) {
    this.task = task;
  }

  public User getUser() {
    return user;
  }

  public void setUser(User user) {
    this.user = user;
  }

  public void setTestTaskInstance(TaskInstance testTaskInstance) {
    this.testTaskInstance = testTaskInstance;
  }

  public TaskInstance getTestTaskinstance() {
    return this.testTaskInstance;
  }

  public void addImplementationTaskInstance(TaskInstance implementationTaskInstance) {
    this.implementationTaskInstances.add(implementationTaskInstance);
  }

  public List<TaskInstance> getImplementationTaskInstances() {
    return this.implementationTaskInstances;
  }
  
  public Challenge getChallenge() {
    return this.task.getChallenge();
  }


}

@@ -646,87 +646,131 @@
 DO: 
-Decide scaling of rating, then set @DecimalMin and @DecimalMax constraints here
+Ratings range from 1 to 5, with 0 meaning %22hasn't been rated yet.%22%0A  // Need to decide on a better representation for this.
 %0A  p
@@ -776,20 +776,18 @@
 private 
-floa
+in
 t rating
@@ -1704,20 +1704,76 @@
  public 
-floa
+boolean isRated() %7B%0A    return rating != 0;%0A  %7D%0A%0A  public in
 t getRat
@@ -1832,12 +1832,10 @@
 ing(
-floa
+in
 t ra

Change type of TaskInstance::rating to int and add isRated()