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

@Entity({ tableName: 'wallet_transactions' })
@Index({ properties: ['user', 'restaurant'] })
export class WalletTransaction extends BaseEntity {
  @ManyToOne(() => User)
  user!: User;

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

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

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

  @Enum(() => WalletTransactionType)
  type!: WalletTransactionType;

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