import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ClsService } from 'nestjs-cls';
import { TenantAwareRepository } from '../../../common/repositories/tenant-aware.repository';
import { MdCashCollectionEntity } from '../../../entities/md-cash-collection.entity';

@Injectable()
export class MdCashCollectionRepository extends TenantAwareRepository<MdCashCollectionEntity> {
  constructor(
    @InjectRepository(MdCashCollectionEntity)
    repo: Repository<MdCashCollectionEntity>,
    cls: ClsService,
  ) {
    super(repo, cls);
  }

  async findPendingByBooking(bookingId: string): Promise<MdCashCollectionEntity[]> {
    return this.find({
      where: { booking_id: bookingId, status: 'PENDING', is_deleted: false } as never,
    });
  }
}
