import type { RequestHandler } from 'express';
import { assertCanDeleteOrganization } from '@/services/shared/role-policy';

/**
 * Relational policy: only platform admins and the owner may delete an
 * organization. This cannot be represented as a flat DELETE_ORGANIZATIONS
 * permission because superintendent intentionally has broad org permissions
 * except company deletion.
 */
export const guardOrganizationDelete: RequestHandler = (req, _res, next) => {
  try {
    assertCanDeleteOrganization(req.currentUser);
    next();
  } catch (error) {
    next(error);
  }
};
