/**
 * ShadowRun Feature Screen Registry
 * Define all screens in the shadow-run feature module
 */

import type { KbxScreenDefinition } from '@shared/contracts/kbx-types'

export const shadowRunListScreen: KbxScreenDefinition = {
  screenId: 'model-ops.shadow-run.list',
  title: 'Shadow Run Validation',
  module: 'ModelOps',
  type: 'list',
  path: '/model-ops/shadow-runs',
  component: () => import('./pages/ShadowRunList.vue'),
  permissions: ['model.read'],
  description: 'View and manage shadow run validations (252+ trading day backtests)',

  help: {
    title: 'Shadow Run Validation',
    sections: [
      {
        title: 'Overview',
        content:
          'Shadow runs validate model performance on historical data without executing trades. Each run includes PBO, DSR, and OOS metrics.',
      },
      {
        title: 'How to Start',
        content:
          '1. Click "Search" (F3) to view existing runs\n2. Click "New" to initiate a new shadow run\n3. Select date range and model\n4. Monitor progress in the dashboard',
      },
      {
        title: 'Interpreting Results',
        content:
          'PBO ≤ 20%, DSR ≥ 95%, OOS ≤ 2.5% indicates model validity. Check phase breakdown (Bull/Bear/Sideways) for regime-specific performance.',
      },
    ],
    relatedScreens: ['model-ops.models.list'],
  },

  grid: {
    columnDefs: [
      { field: 'runId', header: 'Run ID', type: 'link', width: 120, pinned: 'left' },
      { field: 'modelName', header: 'Model', width: 150 },
      { field: 'windowStart', header: 'Start Date', type: 'date', width: 120 },
      { field: 'windowEnd', header: 'End Date', type: 'date', width: 120 },
      { field: 'tradingDays', header: 'Days', type: 'number', width: 80 },
      { field: 'totalReturn', header: 'Return', type: 'money', width: 100 },
      { field: 'sharpeRatio', header: 'Sharpe', type: 'number', width: 80 },
      { field: 'pbo', header: 'PBO', type: 'percentage', width: 80 },
      { field: 'dsr', header: 'DSR', type: 'percentage', width: 80 },
      { field: 'oos', header: 'OOS', type: 'percentage', width: 80 },
      { field: 'status', header: 'Status', type: 'status', width: 100 },
      { field: 'createdAt', header: 'Created', type: 'datetime', width: 150 },
    ],
    pageSize: 50,
    serverSideDatasource: true,
  },

  shortcuts: [
    { key: 'F3', label: 'Search', action: 'search' },
    { key: 'Ctrl+N', label: 'New Shadow Run', action: 'new' },
  ],

  telemetry: { enabled: true },
}

export const shadowRunDetailScreen: KbxScreenDefinition = {
  screenId: 'model-ops.shadow-run.detail',
  title: 'Shadow Run Details',
  module: 'ModelOps',
  type: 'detail',
  path: '/model-ops/shadow-runs/:runId',
  component: () => import('./pages/ShadowRunDetail.vue'),
  permissions: ['model.read'],
  description: 'Detailed analysis of a shadow run with metrics breakdown',

  help: {
    title: 'Shadow Run Analysis',
    sections: [
      {
        title: 'Metrics Explained',
        content:
          'PBO: Probability of Backtest Overfit. DSR: Daily Sharpe Ratio. OOS: Out-of-Sample performance. Lower PBO and OOS, higher DSR is better.',
      },
    ],
    relatedScreens: ['model-ops.shadow-run.list', 'model-ops.models.detail'],
  },

  shortcuts: [
    { key: 'Escape', label: 'Back to List', action: 'back' },
    { key: 'Ctrl+E', label: 'Export', action: 'export' },
  ],

  telemetry: { enabled: true },
}

/**
 * All screens in shadow-run module
 */
export const shadowRunScreens: KbxScreenDefinition[] = [
  shadowRunListScreen,
  shadowRunDetailScreen,
]
