// The module-catalog contract shared across blenaxis-super-admin (which
// grants modules to a tenant), blenaxis-frontend (which gates routes on
// them) and this backend (which stores/validates them). Keys and their
// order mirror the BlenAxis Real Estate OS phase numbering — see
// blenaxis-super-admin's src/config/modules.ts, the source of truth this
// was copied from. Change these only together with both frontends.
export const MODULE_KEYS = [
  'tenant_admin',
  'project_core',
  'tasks',
  'planning',
  'documents',
  'boq',
  'contracts',
  'procurement',
  'execution',
  'quality',
  'contractor_billing',
  'finance',
  'reports',
  'ai_insights',
  'presales_crm',
  'postsales_crm',
] as const;

export type ModuleKey = (typeof MODULE_KEYS)[number];

// Always included on every organization, regardless of plan/selection —
// Administration and Project Core are required for the platform to function.
export const CORE_MODULE_KEYS: ModuleKey[] = ['tenant_admin', 'project_core'];

export interface ModuleCatalogEntry {
  key: ModuleKey;
  name: string;
  description: string;
  category: 'core' | 'construction' | 'finance' | 'sales' | 'intelligence';
  phase: number;
  isCore: boolean;
  status: 'available' | 'beta' | 'coming_soon';
}

// Seed data for the `platform_modules` table — see prisma/seed.ts.
export const MODULE_CATALOG: ModuleCatalogEntry[] = [
  { key: 'tenant_admin', name: 'Administration', description: 'Organization profile, departments, teams, users, roles and permissions.', category: 'core', phase: 2, isCore: true, status: 'available' },
  { key: 'project_core', name: 'Project Core', description: 'Common project structure (WBS, masters) shared by every other module.', category: 'core', phase: 3, isCore: true, status: 'available' },
  { key: 'tasks', name: 'Task Management', description: 'General collaborative work management across the organization.', category: 'construction', phase: 4, isCore: false, status: 'available' },
  { key: 'planning', name: 'Planning & Scheduling', description: 'WBS, baseline schedule, milestones, look-ahead, delay tracking.', category: 'construction', phase: 5, isCore: false, status: 'beta' },
  { key: 'documents', name: 'Drawings & Documents', description: 'Central controlled repository for construction drawings and documents.', category: 'construction', phase: 6, isCore: false, status: 'coming_soon' },
  { key: 'boq', name: 'BOQ & Estimation', description: 'Quantities, rate analysis and project budget.', category: 'construction', phase: 7, isCore: false, status: 'coming_soon' },
  { key: 'contracts', name: 'Contractor & Contracts', description: 'Contractor engagement from selection through work order.', category: 'construction', phase: 8, isCore: false, status: 'coming_soon' },
  { key: 'procurement', name: 'Procurement & Materials', description: 'The complete material lifecycle, from requirement to consumption.', category: 'construction', phase: 9, isCore: false, status: 'coming_soon' },
  { key: 'execution', name: 'Execution & Site', description: 'Connects the approved plan with what is actually happening on site.', category: 'construction', phase: 10, isCore: false, status: 'coming_soon' },
  { key: 'quality', name: 'Quality Management', description: 'Digital control of construction quality — ITPs, inspections, NCRs.', category: 'construction', phase: 11, isCore: false, status: 'coming_soon' },
  { key: 'contractor_billing', name: 'Contractor Billing', description: 'Bill only verified, measured and certified work.', category: 'finance', phase: 12, isCore: false, status: 'coming_soon' },
  { key: 'finance', name: 'Project Cost & Finance', description: 'Real-time financial picture of every project.', category: 'finance', phase: 13, isCore: false, status: 'coming_soon' },
  { key: 'reports', name: 'Reports & Executive BI', description: 'Management dashboards from project up to portfolio and organization.', category: 'intelligence', phase: 14, isCore: false, status: 'coming_soon' },
  { key: 'ai_insights', name: 'AI Intelligence', description: 'Predictive risk and recommended recovery actions.', category: 'intelligence', phase: 15, isCore: false, status: 'coming_soon' },
  { key: 'presales_crm', name: 'Pre-Sales CRM', description: 'Manage customer acquisition through booking.', category: 'sales', phase: 16, isCore: false, status: 'coming_soon' },
  { key: 'postsales_crm', name: 'Post-Sales CRM', description: 'Manage the buyer after booking until handover and beyond.', category: 'sales', phase: 17, isCore: false, status: 'coming_soon' },
];
