package carrentaldatabase;

import java.io.Serializable;
import java.sql.Date;
import javax.persistence.*;

/**
 * @author Daniel "3ICE" Berezvai
 */
@Entity
public class Rental implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

public Integer getId() {
  return id;
}

public void setId(Integer id) {
  this.id = id;
}

@Override
public int hashCode() {
  int hash = 0;
  hash += (id != null ? id.hashCode() : 0);
  return hash;
}

@Override
public boolean equals(Object object) {
  // TODO: Warning - this method won't work in the case the id fields are not set
  if (!(object instanceof Rental)) {
    return false;
  }
  Rental other = (Rental) object;
  if ((this.id == null && other.id != null) || (this.id != null && !this.id.
                                                equals(other.id))) {
    return false;
  }
  return true;
}

@Override
public String toString() {
  return "carrentaldatabase.Rental[ id=" + id + " ]";
}
@OneToOne
private Partner partner;

public Partner getPartner() {
  return partner;
}

public void setPartner(Partner partner) {
  this.partner = partner;
}
@OneToOne
private Vehicle vehicle;

public Vehicle getVehicle() {
  return vehicle;
}

public void setVehicle(Vehicle vehicle) {
  this.vehicle = vehicle;
}
private Date startOfRental;

public Date getStartOfRental() {
  return startOfRental;
}

public void setStartOfRental(Date startOfRental) {
  this.startOfRental = startOfRental;
}
private Date endOfRental;

public Date getEndOfRental() {
  return endOfRental;
}

public void setEndOfRental(Date endOfRental) {
  this.endOfRental = endOfRental;
}
private Date returnDate;

public Date getReturnDate() {
  return returnDate;
}

public void setReturnDate(Date returnDate) {
  this.returnDate = returnDate;
}

public int getPriceOfRental() {
  int pricePerDay = vehicle.getPricePerDay();
  long daysOfEstimatedRental = (endOfRental.getTime() - startOfRental.getTime())
                               / (1000 * 60 * 60 * 24);
  long daysOfActualRental = (returnDate.getTime() - startOfRental.getTime())
                            / (1000 * 60 * 60 * 24);
  return 0;
}
}
