/**
 * Central Screen Registry
 * Merge all feature screen definitions here
 */

import type { KbxScreenDefinition } from '@shared/contracts/kbx-types'
import { homeScreens } from '@features/home/registry'
import { shadowRunScreens } from '@features/shadow-run/registry'
import { modelScreens } from '@features/models/registry'

// Temporary: define a few example screens
export const exampleScreens: KbxScreenDefinition[] = [
  {
    screenId: 'model-ops.shadow-run.list',
    title: 'Shadow Run Validation',
    module: 'ModelOps',
    type: 'list',
    path: '/model-ops/shadow-runs',
    component: () => import('@features/shadow-run/pages/ShadowRunList.vue'),
    permissions: ['model.read'],
    description: 'View and manage shadow run validations',
    help: {
      title: 'Shadow Run Validation',
      sections: [
        {
          title: 'What is a Shadow Run?',
          content: 'A shadow run validates model performance on historical data without executing trades.',
        },
        {
          title: 'How to Use',
          content: 'Click the search button to run a new shadow run. View results in the list below.',
        },
      ],
      relatedScreens: ['model-ops.models.list'],
    },
    shortcuts: [
      { key: 'F3', label: 'Search', action: 'search' },
      { key: 'Ctrl+N', label: 'New', action: 'new' },
    ],
    telemetry: { enabled: true },
  },
  {
    screenId: 'model-ops.models.list',
    title: 'Model Management',
    module: 'ModelOps',
    type: 'list',
    path: '/model-ops/models',
    component: () => import('@features/models/pages/ModelsList.vue'),
    permissions: ['model.read'],
    description: 'Manage trading models and their lifecycle',
    shortcuts: [{ key: 'F3', label: 'Search', action: 'search' }],
    telemetry: { enabled: true },
  },
]

/**
 * Merged screen registry (all features)
 */
export function getAllScreens(): KbxScreenDefinition[] {
  const screens: KbxScreenDefinition[] = []

  // Add screens from all modules
  screens.push(...homeScreens)
  screens.push(...shadowRunScreens)
  screens.push(...modelScreens)

  return screens
}

/**
 * Screen index by ID for fast lookup
 */
export function buildScreenIndex(): Map<string, KbxScreenDefinition> {
  const index = new Map<string, KbxScreenDefinition>()
  getAllScreens().forEach(screen => {
    index.set(screen.screenId, screen)
  })
  return index
}

// Export registry
export const screens = getAllScreens()
export const screenIndex = buildScreenIndex()
