/**
 * Fine-grained permissions for role-based access control
 * Format: entity:action
 */
export enum Permission {
  // Dashboard
  DASHBOARD_VIEW = 'dashboard:view',
  DASHBOARD_CUSTOMIZE = 'dashboard:customize',

  // Users
  USERS_VIEW = 'users:view',
  USERS_VIEW_ALL = 'users:view_all',
  USERS_CREATE = 'users:create',
  USERS_UPDATE = 'users:update',
  USERS_UPDATE_SELF = 'users:update_self',
  USERS_DELETE = 'users:delete',
  USERS_MANAGE_ROLES = 'users:manage_roles',

  // Departments
  DEPARTMENTS_VIEW = 'departments:view',
  DEPARTMENTS_CREATE = 'departments:create',
  DEPARTMENTS_UPDATE = 'departments:update',
  DEPARTMENTS_DELETE = 'departments:delete',
  DEPARTMENTS_MANAGE = 'departments:manage',

  // Employees
  EMPLOYEES_VIEW = 'employees:view',
  EMPLOYEES_VIEW_ALL = 'employees:view_all',
  EMPLOYEES_CREATE = 'employees:create',
  EMPLOYEES_UPDATE = 'employees:update',
  EMPLOYEES_DELETE = 'employees:delete',

  // Time Entries
  TIME_ENTRIES_VIEW = 'time_entries:view',
  TIME_ENTRIES_VIEW_ALL = 'time_entries:view_all',
  TIME_ENTRIES_CREATE = 'time_entries:create',
  TIME_ENTRIES_UPDATE = 'time_entries:update',
  TIME_ENTRIES_CORRECT = 'time_entries:correct',
  TIME_ENTRIES_LOCK = 'time_entries:lock',

  // Absences
  ABSENCES_VIEW = 'absences:view',
  ABSENCES_VIEW_OWN = 'absences:view:own',
  ABSENCES_VIEW_DEPARTMENT = 'absences:view:department',
  ABSENCES_VIEW_ALL = 'absences:view_all',
  ABSENCES_CREATE = 'absences:create',
  ABSENCES_APPROVE = 'absences:approve',
  ABSENCES_CANCEL = 'absences:cancel',

  // Reviews
  REVIEWS_VIEW = 'reviews:view',
  REVIEWS_VIEW_ALL = 'reviews:view_all',
  REVIEWS_CREATE = 'reviews:create',
  REVIEWS_UPDATE = 'reviews:update',

  // Skills
  SKILLS_VIEW = 'skills:view',
  SKILLS_MANAGE = 'skills:manage',
  SKILLS_ASSESS = 'skills:assess',

  // Audit Logs
  AUDIT_VIEW = 'audit:view',
  AUDIT_VIEW_ALL = 'audit:view_all',

  // Settings
  SETTINGS_VIEW = 'settings:view',
  SETTINGS_MANAGE = 'settings:manage',

  // Integrations
  INTEGRATIONS_VIEW = 'integrations:view',
  INTEGRATIONS_MANAGE = 'integrations:manage',
  INTEGRATIONS_SYNC = 'integrations:sync',
  INTEGRATIONS_DELETE = 'integrations:delete',

  // LEAN 3S Planning
  S3_VIEW = 's3:view',
  S3_CREATE = 's3:create',
  S3_UPDATE = 's3:update',
  S3_DELETE = 's3:delete',
  S3_MANAGE = 's3:manage',

  // LEAN Morning Meetings
  MEETING_VIEW = 'meeting:view',
  MEETING_CREATE = 'meeting:create',
  MEETING_UPDATE = 'meeting:update',
  MEETING_DELETE = 'meeting:delete',

  // System Settings
  SYSTEM_SETTINGS_VIEW = 'system_settings:view',
  SYSTEM_SETTINGS_MANAGE = 'system_settings:manage',
}

/**
 * Default permission sets for standard roles
 */
export const DEFAULT_ROLE_PERMISSIONS: Record<string, Permission[]> = {
  admin: Object.values(Permission),

  'hr-manager': [
    Permission.DASHBOARD_VIEW,
    Permission.DASHBOARD_CUSTOMIZE,
    Permission.USERS_VIEW,
    Permission.USERS_VIEW_ALL,
    Permission.USERS_CREATE,
    Permission.USERS_UPDATE,
    Permission.USERS_UPDATE_SELF,
    Permission.DEPARTMENTS_VIEW,
    Permission.EMPLOYEES_VIEW,
    Permission.EMPLOYEES_VIEW_ALL,
    Permission.EMPLOYEES_CREATE,
    Permission.EMPLOYEES_UPDATE,
    Permission.TIME_ENTRIES_VIEW,
    Permission.TIME_ENTRIES_VIEW_ALL,
    Permission.TIME_ENTRIES_CORRECT,
    Permission.ABSENCES_VIEW,
    Permission.ABSENCES_VIEW_OWN,
    Permission.ABSENCES_VIEW_DEPARTMENT,
    Permission.ABSENCES_VIEW_ALL,
    Permission.ABSENCES_CREATE,
    Permission.ABSENCES_APPROVE,
    Permission.ABSENCES_CANCEL,
    Permission.REVIEWS_VIEW,
    Permission.REVIEWS_VIEW_ALL,
    Permission.REVIEWS_CREATE,
    Permission.REVIEWS_UPDATE,
    Permission.SKILLS_VIEW,
    Permission.SKILLS_MANAGE,
    Permission.SKILLS_ASSESS,
    Permission.AUDIT_VIEW,
    Permission.MEETING_VIEW,
    Permission.MEETING_CREATE,
    Permission.MEETING_UPDATE,
    Permission.MEETING_DELETE,
  ],

  'team-lead': [
    Permission.DASHBOARD_VIEW,
    Permission.DASHBOARD_CUSTOMIZE,
    Permission.USERS_VIEW,
    Permission.USERS_UPDATE_SELF,
    Permission.DEPARTMENTS_VIEW,
    Permission.EMPLOYEES_VIEW,
    Permission.TIME_ENTRIES_VIEW,
    Permission.TIME_ENTRIES_CREATE,
    Permission.TIME_ENTRIES_UPDATE,
    Permission.ABSENCES_VIEW,
    Permission.ABSENCES_VIEW_OWN,
    Permission.ABSENCES_VIEW_DEPARTMENT,
    Permission.ABSENCES_CREATE,
    Permission.ABSENCES_APPROVE,
    Permission.ABSENCES_CANCEL,
    Permission.REVIEWS_VIEW,
    Permission.REVIEWS_CREATE,
    Permission.SKILLS_VIEW,
    Permission.SKILLS_ASSESS,
    Permission.S3_VIEW,
    Permission.S3_CREATE,
    Permission.S3_UPDATE,
    Permission.MEETING_VIEW,
    Permission.MEETING_CREATE,
    Permission.MEETING_UPDATE,
  ],

  employee: [
    Permission.DASHBOARD_VIEW,
    Permission.USERS_UPDATE_SELF,
    Permission.DEPARTMENTS_VIEW,
    Permission.TIME_ENTRIES_VIEW,
    Permission.TIME_ENTRIES_CREATE,
    Permission.ABSENCES_VIEW,
    Permission.ABSENCES_VIEW_OWN,
    Permission.ABSENCES_CREATE,
    Permission.ABSENCES_CANCEL,
    Permission.SKILLS_VIEW,
    Permission.S3_VIEW,
    Permission.S3_UPDATE,
    Permission.MEETING_VIEW,
  ],
};
