package entities;

import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

@Entity
@Table(name = "deposito_tarjeta_debito")
@XmlRootElement
public class DepositoTarjetaDebito implements Serializable {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "id")
  private Integer id;

  @Column(name = "monto")
  private int monto;

  @Column(name = "comentario")
  private String comentario;

  @Column(name = "inserted_at")
  private LocalDateTime insertedAt;

  @ManyToOne
  @JoinColumn(name = "metodo")
  private Metodo metodo;
  
  @ManyToOne
  @JoinColumn(name = "tarjeta_debito")
  private TarjetaDebito tarjetaDebito;

  @PrePersist
  public void onPersist() {
    this.insertedAt = LocalDateTime.now();
  }
  
  public Integer getId() {
    return id;
  }

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

  public int getMonto() {
    return monto;
  }

  public void setMonto(int monto) {
    this.monto = monto;
  }

  public String getComentario() {
    return comentario;
  }

  public void setComentario(String comentario) {
    this.comentario = comentario;
  }

  public LocalDateTime getInsertedAt() {
    return insertedAt;
  }

  public void setInsertedAt(LocalDateTime insertedAt) {
    this.insertedAt = insertedAt;
  }

  public Metodo getMetodo() {
    return metodo;
  }

  public void setMetodo(Metodo metodo) {
    this.metodo = metodo;
    if(!this.metodo.getDepositoTarjetaDebitoList().contains(this))
      this.metodo.getDepositoTarjetaDebitoList().add(this);
  }

  public TarjetaDebito getTarjetaDebito() {
    return tarjetaDebito;
  }

  public void setTarjetaDebito(TarjetaDebito tarjetaDebito) {
    this.tarjetaDebito = tarjetaDebito;
    if(!this.tarjetaDebito.getDepositoList().contains(this))
      this.tarjetaDebito.getDepositoList().add(this);
  }

  @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 DepositoTarjetaDebito)) {
      return false;
    }
    DepositoTarjetaDebito other = (DepositoTarjetaDebito) 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 "entities.DepositoTarjetaDebito[ id=" + id + " ]";
  }

}
