package com.demo.demo.model.obj.demo;
import com.demo.demo.model.obj.demo.iface.ILine;
import com.demo.demo.services.data.DataLayerDemoImpl;
import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.proxy.HibernateProxy;


/** 
 * Object mapping for hibernate-handled table: line.
 * @author autogenerated
 */

@Entity
@Table(name = "line", catalog = "demo")
public  class Line implements Cloneable, Serializable, ILine {

    /** Serial Version UID. */
    private static final long serialVersionUID = -559029079L;


    /** Field mapping. */
    private String comment;
    /** Field mapping. */
    private Long id = 0L; // init for hibernate bug workaround
    /** Field mapping. */
    private Order order;
    /** Field mapping. */
    private Long quantity;
    /** Field mapping. */
    private Stock stock;
    /**
     * Default constructor, mainly for hibernate use.
     */
    public Line() {
        // Default constructor
    } 

    /** Constructor taking a given ID.
     * @param id to set
     */
    public Line(Long id) {
        this.id = id;
    }
    
    /** Constructor taking a given ID.
     * @param comment String object;
     * @param id Long object;
     * @param order Order object;
     * @param quantity Long object;
     * @param stock Stock object;
     */
    public Line(String comment, Long id, Order order,                   
            Long quantity, Stock stock) {

        this.comment = comment;
        this.id = id;
        this.order = order;
        this.quantity = quantity;
        this.stock = stock;
    }
    
 


    /**
     * Return the value associated with the column: comment.
     * @return A String object (this.comment)
     */
    @Column( nullable = false, length = 45  )
    public String getComment() {
        return this.comment;
    }
    

  
    /**  
     * Set the value related to the column: comment.
     * @param comment the comment value you wish to set
     */
    public void setComment(final String comment) {
        this.comment = comment;
    }


    /**
     * Return the value associated with the column: id.
     * @return A Long object (this.id)
     */
    @Id 
    @Column( name = "item_id", nullable = false  )
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return this.id;
    }
    

  
    /**  
     * Set the value related to the column: id.
     * @param id the id value you wish to set
     */
    public void setId(final Long id) {
        this.id = id;
    }


    /**
     * Return the value associated with the column: order.
     * @return A Order object (this.order)
     */
    @ManyToOne( cascade = CascadeType.ALL, fetch = FetchType.LAZY )
    @JoinColumn(name = "order_id" )
    public Order getOrder() {
        return this.order;
    }
    

  
    /**  
     * Set the value related to the column: order.
     * @param order the order value you wish to set
     */
    public void setOrder(final Order order) {
        this.order = order;
    }


    /**
     * Return the value associated with the column: quantity.
     * @return A Long object (this.quantity)
     */
    @Column( nullable = false  )
    public Long getQuantity() {
        return this.quantity;
    }
    

  
    /**  
     * Set the value related to the column: quantity.
     * @param quantity the quantity value you wish to set
     */
    public void setQuantity(final Long quantity) {
        this.quantity = quantity;
    }


    /**
     * Return the value associated with the column: stock.
     * @return A Stock object (this.stock)
     */
    @ManyToOne( cascade = CascadeType.ALL, fetch = FetchType.LAZY )
    @JoinColumn(name = "stock_id" )
    public Stock getStock() {
        return this.stock;
    }
    

  
    /**  
     * Set the value related to the column: stock.
     * @param stock the stock value you wish to set
     */
    public void setStock(final Stock stock) {
        this.stock = stock;
    }


   /**
    * Deep copy.
    * @return cloned object
    * @throws CloneNotSupportedException on error
    */
    @Override
    public Line clone() throws CloneNotSupportedException {
        super.clone();  // keep hierarchy
        final Line copy = new Line();

        copy.setComment(this.getComment());
        copy.setId(this.getId());
        copy.setOrder(this.getOrder());
        copy.setQuantity(this.getQuantity());
        copy.setStock(this.getStock());
        return copy;
    }


    /** Provides toString implementation.
     * @see java.lang.Object#toString()
     * @return String representation of this class.
     */
    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        
        sb.append("comment: " + this.getComment() + ", ");
        sb.append("id: " + this.getId() + ", ");
        sb.append("quantity: " + this.getQuantity() + ", ");
        return sb.toString();       
    }

    
    /** Equals implementation. 
     * @see java.lang.Object#equals(java.lang.Object)
     * @param aThat Object to compare with
     * @return true/false
     */
    @Override
    public boolean equals(final Object aThat) {
        Object unproxyThat = aThat;
        
        if ( this == aThat ) {
             return true;
        }
        
        if (aThat instanceof HibernateProxy) {
            // narrow down the proxy to the class we are dealing with.
            try {
                unproxyThat = DataLayerDemoImpl.getInstance().loadLine(((Line)aThat).getId());
            } catch (ClassCastException e) {
                return false;
            }
        }
        if ((aThat == null) || ( !(unproxyThat.getClass().equals(this.getClass())))) {
             return false;
        }
        
        final Line that = (Line) unproxyThat;
        boolean result = true;
        result = result & (((this.getComment() == null) && (that.getComment() == null)) || (this.getComment() != null  && this.getComment().equals(that.getComment())));
        result = result & (((this.getQuantity() == null) && (that.getQuantity() == null)) || (this.getQuantity() != null  && this.getQuantity().equals(that.getQuantity())));

        return result;
    }


    
    /** Calculate the hashcode.
     * @see java.lang.Object#hashCode()
     * @return a calculated number
     */
    @Override
    public int hashCode() {
        int result = 0;
        result = 26 * result + (this.getComment() == null ? 0 : this.getComment().hashCode());
        result = 26 * result + (this.getOrder() == null || this.getOrder().getId() == null ? 0 : this.getOrder().getId().hashCode());
        result = 26 * result + (this.getQuantity() == null ? 0 : this.getQuantity().hashCode());
        result = 26 * result + (this.getStock() == null || this.getStock().getId() == null ? 0 : this.getStock().getId().hashCode());

        return result;  
    }
}