/**
 * Shared date-window guard for Schedule routes per TZ §4.1.2 ¶3-4 / 4.1.2-R11.
 *
 * Out-of-window dates redirect to the Schedule start page instead of 404.
 * Parse failures (malformed URLs) continue to produce 404 via existing logic.
 */

import { isInScheduleWindow } from "@/shared/dateWindow.js";

/**
 * Returns the redirect target path when the given yyyymmdd date falls outside
 * the Schedule [-1, +330] day window. Returns null to allow normal render.
 *
 * Only called after a successful URL parse — malformed dates never reach here.
 */
export function scheduleDateRedirect(locale: string, yyyymmdd: string): string | null {
  if (!isInScheduleWindow(yyyymmdd)) return `/${locale}/schedule`;
  return null;
}
