import { notFound } from "next/navigation";

const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;

/** Mã trong đường dẫn (/khach-hang/<id>...) không phải uuid thì coi như không tồn tại (404) — đưa thẳng vào truy vấn, Postgres báo lỗi cú pháp → trang 500. */
export function idOr404(value: string): string {
  if (!UUID.test(value)) notFound();
  return value;
}

export function isUuid(value: string | null | undefined): value is string {
  return !!value && UUID.test(value);
}
