import { getUserCustomDomains, countActiveCustomDomainsSplit } 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, split, profile] = await Promise.all([
    getUserCustomDomains(user.id),
    countActiveCustomDomainsSplit(user.id),
    getProfile(user.id),
  ]);

  const limits = getPlanLimits(profile?.plan ?? "free");

  return {
    items,
    counts: split,
    limits: limits.customDomains,
  };
});
