/**
 * Static permission definitions — single source of truth.
 * No server-side imports: safe to use in both client and server code.
 */

export const PERMISSIONS = {
  ADMIN_ACCESS:     'admin.access',
  CONTENT_VIEW:     'content.view',
  CONTENT_CREATE:   'content.create',
  CONTENT_EDIT:     'content.edit',
  CONTENT_DELETE:   'content.delete',
  CONTENT_PUBLISH:  'content.publish',
  MEDIA_VIEW:       'media.view',
  MEDIA_UPLOAD:     'media.upload',
  MEDIA_DELETE:     'media.delete',
  USERS_VIEW:       'users.view',
  USERS_EDIT:       'users.edit',
  USERS_DELETE:     'users.delete',
  ROLES_VIEW:       'roles.view',
  ROLES_MANAGE:     'roles.manage',
  SETTINGS_VIEW:    'settings.view',
  SETTINGS_MANAGE:  'settings.manage',
};

export const PERMISSION_DEFINITIONS = [
  { key: 'admin.access',    name: 'Accès au panneau admin',      group_name: 'Administration' },
  { key: 'content.view',    name: 'Voir le contenu',             group_name: 'Contenu' },
  { key: 'content.create',  name: 'Créer du contenu',            group_name: 'Contenu' },
  { key: 'content.edit',    name: 'Modifier le contenu',         group_name: 'Contenu' },
  { key: 'content.delete',  name: 'Supprimer le contenu',        group_name: 'Contenu' },
  { key: 'content.publish', name: 'Publier le contenu',          group_name: 'Contenu' },
  { key: 'media.view',      name: 'Voir les médias',             group_name: 'Médias' },
  { key: 'media.upload',    name: 'Téléverser des médias',       group_name: 'Médias' },
  { key: 'media.delete',    name: 'Supprimer des médias',        group_name: 'Médias' },
  { key: 'users.view',      name: 'Voir les utilisateurs',       group_name: 'Utilisateurs' },
  { key: 'users.edit',      name: 'Modifier les utilisateurs',   group_name: 'Utilisateurs' },
  { key: 'users.delete',    name: 'Supprimer les utilisateurs',  group_name: 'Utilisateurs' },
  { key: 'roles.view',      name: 'Voir les rôles',              group_name: 'Rôles' },
  { key: 'roles.manage',    name: 'Gérer les rôles',             group_name: 'Rôles' },
  { key: 'settings.view',   name: 'Voir les paramètres',         group_name: 'Paramètres' },
  { key: 'settings.manage', name: 'Gérer les paramètres',        group_name: 'Paramètres' },
];

/**
 * Returns permissions grouped by group_name.
 * @returns {Object.<string, Array>}
 */
export function getPermissionGroups() {
  return PERMISSION_DEFINITIONS.reduce((acc, perm) => {
    if (!acc[perm.group_name]) acc[perm.group_name] = [];
    acc[perm.group_name].push(perm);
    return acc;
  }, {});
}
