import { z } from "zod";

const hexSchema = z.string().regex(/^[0-9a-fA-F]{24}$/, "Invalid customer ID");

export default defineNuxtRouteMiddleware(async (to, from) => {
  if (import.meta.server) return;

  const site = to.params.site as string;

  if (!hexSchema.safeParse(site).success) {
    return navigateTo({ name: "require-customer" }, { replace: true });
  }
});
