// src/entities/category.entity.ts
import { Entity, PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, JoinColumn } from 'typeorm';
import { Product } from '../entity/product';

@Entity()
export class Category {
  @PrimaryGeneratedColumn()
  category_id?:number

  @Column()
  name?:string;

  @Column({ type: 'text', nullable: true })
  description?:string;

  // Self-referencing relation for parent category
  @ManyToOne(() => Category, category => category.children, { nullable: true })
  @JoinColumn({ name: 'parent_category_id' })
  parent?:Category;

  @OneToMany(() => Category, category => category.parent)
  children?:Category[];

  @OneToMany(() => Product, product => product.category)
  products?:Product[];
}