package entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
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.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author ryuuji
 */
@Entity
@Table(name = "cliente")
@XmlRootElement
@NamedQueries({
  @NamedQuery(name = "Cliente.findAll", query = "SELECT c FROM Cliente c")
  , @NamedQuery(name = "Cliente.findById", query = "SELECT c FROM Cliente c WHERE c.id = :id")
  , @NamedQuery(name = "Cliente.findByRut", query = "SELECT c FROM Cliente c WHERE c.rut = :rut")
  , @NamedQuery(name = "Cliente.findByNombre", query = "SELECT c FROM Cliente c WHERE c.nombre = :nombre")
  , @NamedQuery(name = "Cliente.findByCiudad", query = "SELECT c FROM Cliente c WHERE c.ciudad = :ciudad")
  , @NamedQuery(name = "Cliente.findByInsertedAt", query = "SELECT c FROM Cliente c WHERE c.insertedAt = :insertedAt")})
public class Cliente implements Serializable {

  private static final long serialVersionUID = 1L;
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Basic(optional = false)
  @Column(name = "id")
  private Integer id;
  @Basic(optional = false)
  @Column(name = "rut")
  private String rut;
  @Basic(optional = false)
  @Column(name = "nombre")
  private String nombre;
  @Basic(optional = false)
  @Column(name = "ciudad")
  private String ciudad;
  @Basic(optional = false)
  @Column(name = "inserted_at")
  @Temporal(TemporalType.TIMESTAMP)
  private Date insertedAt;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "cliente")
  private List<CuentaCorriente> cuentaCorrienteList;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "cliente")
  private List<TarjetaDebito> tarjetaDebitoList;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "cliente")
  private List<TarjetaCredito> tarjetaCreditoList;
  @JoinColumn(name = "linea_sobregiro", referencedColumnName = "id")
  @OneToOne(optional = true)
  private LineaSobregiro lineaSobregiro;
  @JoinColumn(name = "usuario", referencedColumnName = "id")
  @OneToOne(optional = false)
  private Usuario usuario;

  public Cliente() {
  }

  public Cliente(Integer id) {
    this.id = id;
  }

  public Cliente(Integer id, String rut, String nombre, String ciudad, Date insertedAt) {
    this.id = id;
    this.rut = rut;
    this.nombre = nombre;
    this.ciudad = ciudad;
    this.insertedAt = insertedAt;
  }

  public Integer getId() {
    return id;
  }

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

  public String getRut() {
    return rut;
  }

  public void setRut(String rut) {
    this.rut = rut;
  }

  public String getNombre() {
    return nombre;
  }

  public void setNombre(String nombre) {
    this.nombre = nombre;
  }

  public String getCiudad() {
    return ciudad;
  }

  public void setCiudad(String ciudad) {
    this.ciudad = ciudad;
  }

  public Date getInsertedAt() {
    return insertedAt;
  }

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

  @XmlTransient
  public List<CuentaCorriente> getCuentaCorrienteList() {
    if (cuentaCorrienteList == null)
      cuentaCorrienteList = new ArrayList<>();
    return cuentaCorrienteList;
  }

  public void setCuentaCorrienteList(List<CuentaCorriente> cuentaCorrienteList) {
    this.cuentaCorrienteList = cuentaCorrienteList;
  }

  @XmlTransient
  public List<TarjetaDebito> getTarjetaDebitoList() {
    return tarjetaDebitoList;
  }

  public void setTarjetaDebitoList(List<TarjetaDebito> tarjetaDebitoList) {
    if (tarjetaDebitoList == null)
      tarjetaDebitoList = new ArrayList<>();
    this.tarjetaDebitoList = tarjetaDebitoList;
  }

  @XmlTransient
  public List<TarjetaCredito> getTarjetaCreditoList() {
    return tarjetaCreditoList;
  }

  public void setTarjetaCreditoList(List<TarjetaCredito> tarjetaCreditoList) {
    if (tarjetaCreditoList == null)
      tarjetaCreditoList = new ArrayList<>();
    this.tarjetaCreditoList = tarjetaCreditoList;
  }

  public LineaSobregiro getLineaSobregiro() {
    return lineaSobregiro;
  }

  public void setLineaSobregiro(LineaSobregiro lineaSobregiro) {
    this.lineaSobregiro = lineaSobregiro;
  }

  public Usuario getUsuario() {
    return usuario;
  }

  public void setUsuario(Usuario usuario) {
    this.usuario = usuario;
  }

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

}
