import { apiFetch } from "@/lib/api/server";
import type { KolaboraEvent, PaginatedResponse } from "@/types/event";
import type { CheckinResult } from "@/types/checkin";

/** GET /petugas/events — events this Petugas has been assigned to. */
export async function getAssignedEvents() {
  return apiFetch<{ data: KolaboraEvent[] }>("/petugas/events", { auth: true });
}

/** GET /petugas/events/{id} — reuses the assigned-events list to find one event (no single-event endpoint exists). */
export async function getAssignedEvent(eventId: number | string) {
  const { data } = await getAssignedEvents();
  return data.find((event) => String(event.id) === String(eventId)) ?? null;
}

/** GET /petugas/checkin/history — FR-083. */
export async function getCheckinHistory(eventId: number | string, page = 1) {
  return apiFetch<PaginatedResponse<CheckinResult>>(
    `/petugas/checkin/history?event_id=${eventId}&page=${page}`,
    { auth: true },
  );
}
