import type { BookingListRow } from "@/types/booking";
import { compareSchedulingPriority } from "./compareSchedulingPriority";
import {
  groupBookingsByThreeHourWindow,
  type ThreeHourBookingBucket,
} from "./groupBookingsByThreeHourWindow";

export interface OperationsQueueGroups {
  government: BookingListRow[];
  commercial: ThreeHourBookingBucket<BookingListRow>[];
}

export function groupBookingsForOperationsQueue(
  bookings: BookingListRow[],
): OperationsQueueGroups {
  const government = bookings
    .filter((b) => b.isGovernment)
    .sort(compareSchedulingPriority);
  const commercial = groupBookingsByThreeHourWindow(
    bookings.filter((b) => !b.isGovernment),
  );
  return { government, commercial };
}
