import { Entity, Property, ManyToOne, Index, Enum } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
import { User } from './user.entity';
import { PointTransactionReason } from '../interface/point';
import { PointTransactionType } from '../interface/point';

@Entity({ tableName: 'point_transactions' })
@Index({ properties: ['user', 'restaurant'] }) // Composite index for most common query: find wallet by user and restaurant
export class PointTransaction extends BaseEntity {
  @ManyToOne(() => User)
  user!: User;

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

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

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

  @Enum(() => PointTransaction)
  type!: PointTransactionType;

  @Enum(() => PointTransactionReason)
  reason!: PointTransactionReason;
}
