import { jsonSuccess } from "@/modules/core/server/api";
import { requirePermission } from "@/modules/core/server/auth";
import { listSettingsJoinRequests } from "@/modules/core/server/settings";

export async function GET(): Promise<Response> {
  const auth = await requirePermission("account:read", {
    action: "joinRequest.list",
    targetType: "joinRequest",
  });

  if (!auth.success) {
    return auth.response;
  }

  const organizationId = auth.context.account.platformRoleId ? undefined : auth.context.organization?.id;

  return jsonSuccess("加入申请已加载", {
    joinRequests: await listSettingsJoinRequests(organizationId ? { organizationId } : {}),
  });
}
