package org.codiki.core.entities.persistence;

import com.fasterxml.jackson.annotation.JsonView;
import org.hibernate.annotations.Proxy;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "sub_category")
@Proxy(lazy = false)
public class SubCategory extends Category {
	private static final long serialVersionUID = 1L;

	/* ******************* */
	/* Relations */
	/* ******************* */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "main_category")
	private Category mainCategory;

	/* ******************* */
	/* Getters & Setters */
	/* ******************* */
	public Category getMainCategory() {
		return mainCategory;
	}

	public void setMainCategory(Category mainCategory) {
		this.mainCategory = mainCategory;
	}
	
	public List<Post> getListPosts() {
		return listPosts;
	}

	/**
	 * {@inheritDoc Category#getListSubCategories}.
	 *
	 * This getter is overrided to set {@link JsonView} annotation to avoid Lazy initialization for subcategories.
	 */
	@JsonView()
	@Override
	public List<SubCategory> getListSubCategories() {
		return super.getListSubCategories();
	}
}
