import { parseKuwaitInstant } from "@/features/shared/clientReviewPolicy";
import type { MyAttendanceScanRecord } from "./services/selfCheckIn";

/** Use the API's window; printing a QR never grants a scan outside it. */
export function isLiveScanWindow(row: Pick<MyAttendanceScanRecord, "opportunity_type" | "scan_opens_at" | "scan_closes_at">, now: number): boolean {
  const opens = parseKuwaitInstant(row.scan_opens_at)?.valueOf();
  const closes = parseKuwaitInstant(row.scan_closes_at)?.valueOf();
  if (opens == null || closes == null || closes <= opens) return false;
  return now >= opens && (row.opportunity_type === "learn_serve_opportunity" ? now < closes : now <= closes);
}
