import type { Handler } from './http.js';
import { routeKey } from './http.js';
import { aiRoutes } from '../features/ai/index.js';
import { authRoutes } from '../features/auth/index.js';
import { catalogRoutes } from '../features/catalog/index.js';
import { commerceRoutes } from '../features/commerce/index.js';
import { healthRoutes } from '../features/health/index.js';
import { learningRoutes } from '../features/learning/index.js';
import { platformAdminRoutes } from '../features/platform-admin/index.js';
import { profileRoutes } from '../features/profile/index.js';
import { referralRoutes } from '../features/referral/index.js';
import { scorelineRoutes } from '../features/scoreline/index.js';
import { tenantAdminRoutes } from '../features/tenant-admin/index.js';
import { tenantContentRoutes } from '../features/tenant-content/index.js';
import { tenantRoutes } from '../features/tenant/index.js';
import { videoRoutes } from '../features/video/index.js';

export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
export type RouteDefinition = [method: HttpMethod, path: string, handler: Handler];

export function createRouter(definitions: RouteDefinition[] = allRoutes) {
  const routes = new Map<string, Handler>();

  for (const [method, path, handler] of definitions) {
    routes.set(routeKey(method, path), handler);
  }

  return routes;
}

const allRoutes: RouteDefinition[] = [
  ...healthRoutes,
  ...authRoutes,
  ...tenantRoutes,
  ...aiRoutes,
  ...catalogRoutes,
  ...learningRoutes,
  ...profileRoutes,
  ...scorelineRoutes,
  ...videoRoutes,
  ...commerceRoutes,
  ...referralRoutes,
  ...platformAdminRoutes,
  ...tenantAdminRoutes,
  ...tenantContentRoutes,
];
