import { Entity, Index, Property, Collection, OneToMany, ManyToOne } from '@mikro-orm/core';
import { Food } from './food.entity';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';

@Entity({ tableName: 'categories' })
@Index({ properties: ['restaurant', 'isActive'] })
@Index({ properties: ['restaurant', 'id'] })
@Index({ properties: ['isActive'] })
export class Category extends BaseEntity {
  @Property()
  title!: string;

  @OneToMany(() => Food, food => food.category)
  foods = new Collection<Food>(this);

  @Property({ default: true })
  isActive: boolean = true;

  @ManyToOne(() => Restaurant)
  restaurant!: Restaurant;

  @Property({ nullable: true })
  avatarUrl?: string;

  @Property({ type: 'int', nullable: true })
  order?: number;
}
