import { getUserCustomDomains, countActiveCustomDomains } from "../../db/domains";
import { getProfile } from "../../db/profile";
import { getPlanLimits } from "../../utils/plan-features";

export default defineEventHandler(async (event) => {
  const user = await requireUser(event);

  const [items, count, profile] = await Promise.all([
    getUserCustomDomains(user.id),
    countActiveCustomDomains(user.id),
    getProfile(user.id),
  ]);

  // Slot-Pool: web + mail gemeinsam (Pro 10 / Legend 20).
  const limit = getPlanLimits(profile?.plan ?? "pro").customDomains;

  return { items, count, limit };
});
