import { Entity, Index, ManyToOne, Property } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Order } from './order.entity';
import { Food } from '../../foods/entities/food.entity';

@Entity({ tableName: 'order_items' })
@Index({ properties: ['order'] })
export class OrderItem extends BaseEntity {
  @ManyToOne(() => Order)
  order!: Order;

  @ManyToOne(() => Food)
  food!: Food;

  @Property({ type: 'int' })
  quantity!: number;

  @Property({ type: 'decimal', precision: 10, scale: 0 })
  unitPrice!: number;

  @Property({ type: 'decimal', precision: 10, scale: 0, default: 0 })
  discount: number = 0;

  @Property({ type: 'decimal', precision: 10, scale: 0 })
  totalPrice!: number;
}
