import { usePermissionContext } from '../contexts/PermissionContext';
import { AusruestungKategorie } from '../types/equipment.types';

export function usePermissions() {
  const { hasPermission, hasAnyPermission, isAdmin, isFeatureEnabled, isLoading, permissions, maintenance, refetch } = usePermissionContext();

  return {
    // Core API
    hasPermission,
    hasAnyPermission,
    isFeatureEnabled,
    isAdmin,
    isLoading,
    permissions,
    maintenance,
    refetch,

    // Backward-compatible convenience flags
    isFahrmeister: false, // No longer needed — use hasPermission() instead
    isZeugmeister: false, // No longer needed — use hasPermission() instead
    canChangeStatus: hasPermission('fahrzeuge:change_status'),
    canManageMaintenance: hasPermission('fahrzeuge:manage_maintenance'),
    canManageEquipmentMaintenance: hasPermission('ausruestung:manage_maintenance'),
    canManageEquipment: hasPermission('ausruestung:create'),
    canManageMotorizedEquipment: hasPermission('ausruestung:create'),
    canManageNonMotorizedEquipment: hasPermission('ausruestung:create'),
    canManageCategory: (_kategorie: AusruestungKategorie | null | undefined): boolean => {
      return hasPermission('ausruestung:create');
    },
    groups: [] as string[], // Deprecated — use hasPermission() instead
  };
}
