import { NextResponse } from 'next/server';
import { AuthError, requireSuperAdminOrganizationAccess } from '@/lib/auth/session';
import { getPermissionCatalog } from '@/features/permission-management/server/permission-template-data';

export async function GET() {
  try {
    await requireSuperAdminOrganizationAccess();
    return NextResponse.json(getPermissionCatalog());
  } catch (error) {
    if (error instanceof AuthError) {
      return NextResponse.json({ message: error.message }, { status: error.status });
    }

    return NextResponse.json({ message: 'Unable to load permission catalog' }, { status: 500 });
  }
}
