import { Column, Entity, ManyToOne, OneToMany } from 'typeorm'
import { SoftDeleteEntity } from '../entity'
import { MenuItemCategory } from './item-category.model'

@Entity()
export class Category extends SoftDeleteEntity<Category> {
	/**
	 * Name of the Category
	 */
	@Column({
		type: 'varchar',
		length: 60,
		nullable: false,
	})
	name: string

	/**
	 * The position at which category is displayed on Menu
	 */
	@Column({
		type: 'integer',
		nullable: false,
	})
	sortOrder: number

	/**
	 * True if the Category been archived by user
	 */
	@Column({
		type: 'boolean',
		nullable: false,
		default: false,
	})
	isArchived: boolean

	/**
	 * True if the Category is visible in menu
	 */
	@Column({
		type: 'boolean',
		nullable: false,
		default: true,
	})
	isVisible: boolean

	/**
	 * Parent category of this category
	 */
	@ManyToOne(() => Category, (category) => category.subcategories, {
		nullable: true,
	})
	parentCategory?: Category

	/**
	 * A list of subcategories of this category
	 */
	@OneToMany(() => Category, (category) => category.parentCategory)
	subcategories: Category[]

	/**
	 * List of Items in the category
	 */
	@OneToMany(() => MenuItemCategory, (category) => category.category)
	items: MenuItemCategory[]
}
