import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";

export async function GET(req: NextRequest) {
  const slug = req.nextUrl.searchParams.get("slug");

  if (!slug || slug.length < 3) {
    return NextResponse.json({ available: false });
  }

  const existing = await prisma.user.findUnique({ where: { subdomain: slug } });

  return NextResponse.json(
    { available: !existing },
    { headers: { "Cache-Control": "no-store" } }
  );
}