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

export type { PublicTruckEvent } from "./truck-schedule-shared";
export {
  isValidEventDate,
  parseTruckEventPayload,
} from "./truck-schedule-shared";

export async function getPublicTruckEvents(): Promise<PublicTruckEvent[]> {
  const rows = await prisma.truckEvent.findMany({
    orderBy: [{ eventDate: "asc" }, { createdAt: "asc" }],
  });
  return rows.map((r) => ({
    id: r.id,
    eventDate: r.eventDate,
    timeLabel: r.timeLabel,
    location: r.location,
    note: r.note,
    imageUrl: r.imageUrl,
  }));
}
