import { DefaultRoles, PERMISSIONS } from '@/utills/constant';

/**
 * Who can raise a lead request: a user whose role has LEAD_REQUEST_CREATE, except the Super Admin and the City Head.
 * They approve, reject and stop requests, they do not raise them. Unlike hasPermission, the Super Admin is not let
 * through for being the Super Admin.
 */
export const canCreateLeadRequest = (user: any): boolean => {
  if (!user) return false;
  const roleId = Number(user?.role?.id);
  if (roleId === DefaultRoles.super_admin.id || roleId === DefaultRoles.city_head.id) return false;
  return !!user?.permissions?.includes(PERMISSIONS.LEAD_REQUEST_CREATE.name);
};
