import { prisma } from "./prisma";
import type { PublicTruckRecurrence } from "./truck-schedule-shared";

export type { PublicTruckRecurrence } from "./truck-schedule-shared";
export {
  WEEKDAY_LABELS,
  dayOfWeekMonday0,
  mergeScheduleForDays,
  parseTruckRecurrencePayload,
} from "./truck-schedule-shared";

export async function getPublicTruckRecurrences(): Promise<PublicTruckRecurrence[]> {
  const rows = await prisma.truckEventRecurrence.findMany({
    where: { active: true },
    orderBy: [{ dayOfWeek: "asc" }, { createdAt: "asc" }],
  });
  return rows.map((r) => ({
    id: r.id,
    dayOfWeek: r.dayOfWeek,
    timeLabel: r.timeLabel,
    location: r.location,
    note: r.note,
    imageUrl: r.imageUrl,
    active: r.active,
  }));
}
