package views.formdata;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import play.data.validation.ValidationError;
import models.Offer;
import models.Student;
import models.Textbook;

public class BuyOfferFormData {

  public Student student = null;
  public Textbook textbook = null;
  public int price = 0;
  public Date expiration = null;
  /** The id. */
  public int id;
  
  /**
   * Default constructor
   */
  public BuyOfferFormData() {
  }
  
  public BuyOfferFormData(Offer formData) {
    this.student = formData.getStudent();
    this.textbook = formData.getTextbook();
    this.price = formData.getPrice();
    this.expiration = formData.getExpiration();
    this.id = id;
  }
  
  public BuyOfferFormData(Student student, Textbook textbook, int price, Date date, int id) {
    this.student = student;
    this.textbook = textbook;
    this.price = price;
    this.expiration = date;
    this.id = id;
  }
  /**
   * Checks that form fields are valid. Called by bindFormRequest().
   * @return null if valid, a list of ValidationError if problem is found.
   */
  public List<ValidationError> validate()  {
    List<ValidationError> errors = new ArrayList<>();
    
    if (student == null) {
      errors.add(new ValidationError("student", "Student is required."));
    }
    
    if (textbook == null) {
      errors.add(new ValidationError("textbook", "Textbook is required."));
    }

    if (price == 0) {
      errors.add(new ValidationError("price", "Price is required."));
    } 
    

    if (expiration == null) {
      errors.add(new ValidationError("condition", "Expiration is required."));
    }
    
    return errors.isEmpty() ? null : errors;
  }
}

@@ -697,34 +697,48 @@
 ;%0A    this.id = 
-id
+formData.getId()
 ;%0A  %7D%0A  %0A  publi
@@ -956,16 +956,222 @@
 id;%0A  %7D%0A
+  %0A  public BuyOfferFormData(Student student, Textbook textbook, int price, Date date) %7B%0A    this.student = student;%0A    this.textbook = textbook;%0A    this.price = price;%0A    this.expiration = date;%0A  %7D%0A  %0A
   /**%0A  
@@ -1822,13 +1822,14 @@
 or(%22
-condi
+expira
 tion

edit BuyOfferFormData