package sklep.model;

import java.io.Serializable;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.List;


/**
 * The persistent class for the orders database table.
 * 
 */
@Entity
@Table(name="orders")
@NamedQuery(name="Order.findAll", query="SELECT o FROM Order o")
public class Order extends AbstractEntity implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="order_id", updatable=false)
	private Integer orderId;

	@Column(name="order_date")
	private Timestamp orderDate;

	@Column(name="order_status")
	private String orderStatus;

	//bi-directional many-to-one association to OrderProduct
	@OneToMany(mappedBy="order", cascade={CascadeType.ALL})
	private List<OrderProduct> products;

	//bi-directional many-to-one association to Customer
	@ManyToOne
	private Customer customer;

	public Order() {
	}

	public Integer getOrderId() {
		return this.orderId;
	}

	public void setOrderId(Integer orderId) {
		this.orderId = orderId;
	}

	public Timestamp getOrderDate() {
		return this.orderDate;
	}

	public void setOrderDate(Timestamp orderDate) {
		this.orderDate = orderDate;
	}

	public String getOrderStatus() {
		return this.orderStatus;
	}

	public void setOrderStatus(String orderStatus) {
		this.orderStatus = orderStatus;
	}

	public List<OrderProduct> getProducts() {
		return this.products;
	}

	public void setProducts(List<OrderProduct> products) {
		this.products = products;
	}

	public OrderProduct addProduct(OrderProduct product) {
		getProducts().add(product);
		product.setOrder(this);

		return product;
	}

	public OrderProduct removeProduct(OrderProduct product) {
		getProducts().remove(product);
		product.setOrder(null);

		return product;
	}

	public Customer getCustomer() {
		return this.customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

}