export interface SchedulingPriorityBooking {
  isGovernment?: boolean;
  priorityScore?: number | null;
  // One-time bookings always carry a date; general contracts (never scheduled)
  // may be null — treated as epoch 0 so they sort last.
  scheduledDate?: Date | string | null;
}

/** Government first, then priority score, then earliest scheduled date. */
export function compareSchedulingPriority(
  a: SchedulingPriorityBooking,
  b: SchedulingPriorityBooking,
): number {
  const govDiff = Number(Boolean(b.isGovernment)) - Number(Boolean(a.isGovernment));
  if (govDiff !== 0) return govDiff;

  const priorityDiff = (b.priorityScore ?? 0) - (a.priorityScore ?? 0);
  if (priorityDiff !== 0) return priorityDiff;

  const aTime = a.scheduledDate ? new Date(a.scheduledDate).getTime() : 0;
  const bTime = b.scheduledDate ? new Date(b.scheduledDate).getTime() : 0;
  return aTime - bTime;
}
