import { Injectable } from '@nestjs/common';
import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
import { PointTransaction } from '../entities/point-transaction.entity';

@Injectable()
export class PointTransactionRepository extends EntityRepository<PointTransaction> {
  constructor(readonly em: EntityManager) {
    super(em, PointTransaction);
  }
  async getcurrentPointBalance(userId: string, restaurantId: string): Promise<number> {
    const pointTransaction = await this.em.findOne(PointTransaction, {
      user: { id: userId },
      restaurant: { id: restaurantId },
    });
    return pointTransaction?.balance || 0;
  }
}
