// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package nosql.mongodb.object;

import java.math.BigDecimal;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

@Entity
public class OrderLine {
    private int itemNo;
    private String itemName;
    private BigDecimal itemPrice;
    private int quantity;
    private Order order;
    public OrderLine() {
        this(0, "", new BigDecimal("0.00"), 0);
    }
    public OrderLine(int itemsNo, String itemName, BigDecimal itemPrice, int quantity) {
        this.itemNo = itemsNo;
        this.itemName = itemName;
        this.itemPrice = itemPrice;
        this.quantity = quantity;
    }
    @Id
    public int getItemNo() {
        return itemNo;
    }
    public void setItemNo(int itemNo) {
        this.itemNo = itemNo;
    }
    public String getItemName() {
        return itemName;
    }
    public void setItemName(String itemName) {
        this.itemName = itemName;
    }
    public BigDecimal getItemPrice() {
        return itemPrice;
    }
    public void setItemPrice(BigDecimal itemPrice) {
        this.itemPrice = itemPrice;
    }
    public int getQuantity() {
        return quantity;
    }
    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }
    @ManyToOne
    public Order getOrder() {
        return order;
    }
    public void setOrder(Order order) {
        this.order = order;
    }
    @Transient
    public BigDecimal getPrice() {
        return itemPrice.multiply(new BigDecimal(quantity));
    }
    @Override
    public String toString() {
        return String.format("(%d,%s,%s,%d)",  itemNo, itemName, itemPrice, quantity);
    }
}
