package org.sistema.hibernate.hql.models;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Represents a ProductType
 * 
 * @author Eugenia Pérez
 * @email eugenia_perez@cuatrovientos.org
 */
@Entity
@Table(name = "producttype")
public class ProductType {

	@Id
	@GeneratedValue
	@Column(name = "id")
	private Long id;

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

	@OneToMany(mappedBy = "productType", fetch = FetchType.EAGER)
	private Set<Product> products = new HashSet<Product>();

	/**
	 * Default constructor
	 */
	public ProductType() {

	}

	/**
	 * Constructor with parameters
	 * @param name
	 */
	public ProductType(String name) {
		this.name = name;
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the products
	 */
	public Set<Product> getProducts() {
		return products;
	}

	/**
	 * @param products
	 *            the products to set
	 */
	public void setProducts(Set<Product> products) {
		this.products = products;
	}

	/**
	 * Añade un producto a la lista de productos
	 * 
	 * @param product
	 */
	public void addProduct(Product product) {
		this.products.add(product);
	}
}
