package Modelo;

import java.io.Serializable;
import java.util.ArrayList; 
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Transient;
//import javax.persistence.ManyToOne;

// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.2A15F100-83FC-3DFC-6E6A-28A3184BCF24]
// </editor-fold>
@Entity
public class Producto implements Serializable {

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.D6F7E5A5-1A97-8003-CD55-7763D356829D]
    // </editor-fold> 
    private String stNumPro;
    @Transient
    private List<Movimiento> mMovimiento;
    @Transient
    private List<Cliente> mTitulares;
    
    private double dSaldo;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @OneToOne(mappedBy = "miProducto")
    @ManyToOne
    private Cliente cliente;
    

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.A99E1702-B321-D6F3-80FE-AFC850F16388]
    // </editor-fold> 
    public Producto () {
        mMovimiento=new ArrayList();
        mTitulares= new ArrayList();
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.ACEBFF01-8683-B72D-5D9A-0FCCB2D58607]
    // </editor-fold> 
    public List<Movimiento> getMovimiento () {
        return mMovimiento;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.8A78B20B-1753-E4B4-AFFC-868DFF28AF77]
    // </editor-fold> 
    public void setMovimiento (ArrayList<Movimiento> val) {
        this.mMovimiento = val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.EDCA0E05-A2CF-0CE9-5962-148EB1AC93D4]
    // </editor-fold> 
    public String getStNumPro () {
        return stNumPro;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.4C264604-F870-C6AC-C278-94ACDDD852DF]
    // </editor-fold> 
    public void setNumeroProducto (String val) {
        this.stNumPro = val;
    }

    public void insertaMovimientoenCuenta(Movimiento mov){
        this.mMovimiento.add(mov);
        this.setDSaldo(this.getDSaldo() + mov.getDImporte());
    }

    public void insertaTitularenProducto(Cliente cli){
        this.mTitulares.add(cli);
    }

    /**
     * @return the mTitulares
     */
    public List<Cliente> getMTitulares() {
        return mTitulares;
    }

    /**
     * @param mTitulares the mTitulares to set
     */
    public void setMTitulares(List<Cliente> mTitulares) {
        this.mTitulares = mTitulares;
    }

    /**
     * @return the dSaldo
     */
    public double getDSaldo() {
        return dSaldo;
    }

    /**
     * @param dSaldo the dSaldo to set
     */
    public void setDSaldo(double dSaldo) {
        this.dSaldo = dSaldo;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long 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 Cliente)) {
            return false;
        }
        Producto other = (Producto) 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 "Nº Cuenta: "+this.stNumPro+"      Saldo: "+this.dSaldo;
    }

}

