import { BaseRepository } from "@edr/api-common";
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";

import { Booking } from "./entities/booking.entity";

@Injectable()
export class BookingsRepository extends BaseRepository<Booking> {
  constructor(
    @InjectRepository(Booking)
    repository: Repository<Booking>,
  ) {
    super(repository);
  }

  /** Find a booking by its human-readable reference number. */
  findByReference(reference: string): Promise<Booking | null> {
    return this.repository.findOne({ where: { reference } });
  }
}
