import { FindOptionsWhere, IsNull, LessThanOrEqual, MoreThan } from 'typeorm';
import { Occupancy } from '../entities/occupancy.entity';

export function occupancyWhereOnDate(
  date: string,
  roomId?: number,
): FindOptionsWhere<Occupancy>[] {
  const scope = roomId === undefined ? {} : { roomId };
  return [
    { ...scope, checkInDate: LessThanOrEqual(date), checkOutDate: IsNull() },
    { ...scope, checkInDate: LessThanOrEqual(date), checkOutDate: MoreThan(date) },
  ];
}
