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

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import jakarta.nosql.mapping.Column;
import jakarta.nosql.mapping.Entity;
import jakarta.nosql.mapping.Id;

@Entity
public class Order {
	@Id
    private int orderId;
	@Column
    private String customer;
	@Column
    private List<OrderLine> items;
	public Order() {
		this(0, "");
	}
    public Order(int orderId, String customer) {
        this(orderId, customer, new ArrayList<OrderLine>());
    }
    public Order(int orderId, String customer, List<OrderLine> items) {
        this.orderId = orderId;
        this.customer = customer;
        this.items = items;
    }
    public int getOrderId() {
        return orderId;
    }
    public String getCustomer() {
        return customer;
    }
    public List<OrderLine> getItems() {
        return items;
    }
    public void setOrderId(int orderId) {
		this.orderId = orderId;
	}
	public void setCustomer(String customer) {
		this.customer = customer;
	}
	public void setItems(List<OrderLine> items) {
		this.items = items;
	}
	public BigDecimal getPrice() {
        BigDecimal res = BigDecimal.ZERO;
        for(OrderLine ol : items) {
            res = res.add(ol.getPrice());
        }
        return res;
    }
}
