import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, JoinColumn } from 'typeorm';
import { FurnitureModelEntity } from './furniture-model.entity';

@Entity('furniture_categories')
export class FurnitureCategoryEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'varchar', length: 64 }) name: string;
    @Column({ nullable: true, type: 'int' }) parent_category_id: number;
    @Column({ type: 'varchar', length: 32 }) catalogue: string;

    @OneToMany(() => FurnitureCategoryEntity, (category) => category.parent)
    categories: FurnitureCategoryEntity[];

    @ManyToOne(() => FurnitureCategoryEntity, (category) => category.categories)
    @JoinColumn({ name: 'parent_category_id' })
    parent: FurnitureCategoryEntity;

    @OneToMany(() => FurnitureModelEntity, (model) => model.category)
    models: FurnitureModelEntity[];
}
