/**
 * Permission Types
 */

// All available permissions in the system
export enum Permission {
  // User permissions
  READ_USERS = 'READ_USERS',
  CREATE_USERS = 'CREATE_USERS',
  UPDATE_USERS = 'UPDATE_USERS',
  DELETE_USERS = 'DELETE_USERS',

  // Role permissions
  READ_ROLES = 'READ_ROLES',
  CREATE_ROLES = 'CREATE_ROLES',
  UPDATE_ROLES = 'UPDATE_ROLES',
  DELETE_ROLES = 'DELETE_ROLES',

  // Permission permissions
  READ_PERMISSIONS = 'READ_PERMISSIONS',
  CREATE_PERMISSIONS = 'CREATE_PERMISSIONS',
  UPDATE_PERMISSIONS = 'UPDATE_PERMISSIONS',
  DELETE_PERMISSIONS = 'DELETE_PERMISSIONS',

  // Project permissions
  READ_PROJECTS = 'READ_PROJECTS',
  CREATE_PROJECTS = 'CREATE_PROJECTS',
  UPDATE_PROJECTS = 'UPDATE_PROJECTS',
  DELETE_PROJECTS = 'DELETE_PROJECTS',

  // Project membership permissions
  READ_PROJECT_MEMBERSHIPS = 'READ_PROJECT_MEMBERSHIPS',
  CREATE_PROJECT_MEMBERSHIPS = 'CREATE_PROJECT_MEMBERSHIPS',
  UPDATE_PROJECT_MEMBERSHIPS = 'UPDATE_PROJECT_MEMBERSHIPS',
  DELETE_PROJECT_MEMBERSHIPS = 'DELETE_PROJECT_MEMBERSHIPS',

  // Asset permissions
  READ_ASSETS = 'READ_ASSETS',
  CREATE_ASSETS = 'CREATE_ASSETS',
  UPDATE_ASSETS = 'UPDATE_ASSETS',
  DELETE_ASSETS = 'DELETE_ASSETS',

  // Asset variant permissions
  READ_ASSET_VARIANTS = 'READ_ASSET_VARIANTS',
  CREATE_ASSET_VARIANTS = 'CREATE_ASSET_VARIANTS',
  UPDATE_ASSET_VARIANTS = 'UPDATE_ASSET_VARIANTS',
  DELETE_ASSET_VARIANTS = 'DELETE_ASSET_VARIANTS',

  // Tour page permissions
  READ_TOUR_PAGES = 'READ_TOUR_PAGES',
  CREATE_TOUR_PAGES = 'CREATE_TOUR_PAGES',
  UPDATE_TOUR_PAGES = 'UPDATE_TOUR_PAGES',
  DELETE_TOUR_PAGES = 'DELETE_TOUR_PAGES',

  // Page element permissions
  READ_PAGE_ELEMENTS = 'READ_PAGE_ELEMENTS',
  CREATE_PAGE_ELEMENTS = 'CREATE_PAGE_ELEMENTS',
  UPDATE_PAGE_ELEMENTS = 'UPDATE_PAGE_ELEMENTS',
  DELETE_PAGE_ELEMENTS = 'DELETE_PAGE_ELEMENTS',

  // Page link permissions
  READ_PAGE_LINKS = 'READ_PAGE_LINKS',
  CREATE_PAGE_LINKS = 'CREATE_PAGE_LINKS',
  UPDATE_PAGE_LINKS = 'UPDATE_PAGE_LINKS',
  DELETE_PAGE_LINKS = 'DELETE_PAGE_LINKS',

  // Transition permissions
  READ_TRANSITIONS = 'READ_TRANSITIONS',
  CREATE_TRANSITIONS = 'CREATE_TRANSITIONS',
  UPDATE_TRANSITIONS = 'UPDATE_TRANSITIONS',
  DELETE_TRANSITIONS = 'DELETE_TRANSITIONS',

  // Project audio track permissions
  READ_PROJECT_AUDIO_TRACKS = 'READ_PROJECT_AUDIO_TRACKS',
  CREATE_PROJECT_AUDIO_TRACKS = 'CREATE_PROJECT_AUDIO_TRACKS',
  UPDATE_PROJECT_AUDIO_TRACKS = 'UPDATE_PROJECT_AUDIO_TRACKS',
  DELETE_PROJECT_AUDIO_TRACKS = 'DELETE_PROJECT_AUDIO_TRACKS',

  // Publish event permissions
  READ_PUBLISH_EVENTS = 'READ_PUBLISH_EVENTS',
  CREATE_PUBLISH_EVENTS = 'CREATE_PUBLISH_EVENTS',
  UPDATE_PUBLISH_EVENTS = 'UPDATE_PUBLISH_EVENTS',
  DELETE_PUBLISH_EVENTS = 'DELETE_PUBLISH_EVENTS',

  // PWA cache permissions
  READ_PWA_CACHES = 'READ_PWA_CACHES',
  CREATE_PWA_CACHES = 'CREATE_PWA_CACHES',
  UPDATE_PWA_CACHES = 'UPDATE_PWA_CACHES',
  DELETE_PWA_CACHES = 'DELETE_PWA_CACHES',

  // Presigned URL request permissions
  READ_PRESIGNED_URL_REQUESTS = 'READ_PRESIGNED_URL_REQUESTS',
  CREATE_PRESIGNED_URL_REQUESTS = 'CREATE_PRESIGNED_URL_REQUESTS',
  UPDATE_PRESIGNED_URL_REQUESTS = 'UPDATE_PRESIGNED_URL_REQUESTS',
  DELETE_PRESIGNED_URL_REQUESTS = 'DELETE_PRESIGNED_URL_REQUESTS',

  // Access log permissions
  READ_ACCESS_LOGS = 'READ_ACCESS_LOGS',
  CREATE_ACCESS_LOGS = 'CREATE_ACCESS_LOGS',
  UPDATE_ACCESS_LOGS = 'UPDATE_ACCESS_LOGS',
  DELETE_ACCESS_LOGS = 'DELETE_ACCESS_LOGS',

  // UI element permissions
  READ_UI_ELEMENTS = 'READ_UI_ELEMENTS',
  CREATE_UI_ELEMENTS = 'CREATE_UI_ELEMENTS',
  UPDATE_UI_ELEMENTS = 'UPDATE_UI_ELEMENTS',
  DELETE_UI_ELEMENTS = 'DELETE_UI_ELEMENTS',
}

// Permission type for use in components
export type PermissionString = `${Permission}` | string;

// Helper to get CRUD permissions for an entity
export const getEntityPermissions = (entityName: string) => {
  const uppercased = entityName.toUpperCase();
  return {
    read: `READ_${uppercased}` as PermissionString,
    create: `CREATE_${uppercased}` as PermissionString,
    update: `UPDATE_${uppercased}` as PermissionString,
    delete: `DELETE_${uppercased}` as PermissionString,
  };
};
