/**
 * Test Pattern 12 matching for strategy backtest
 */
import * as directQuery from '../src/lib/directSportsQuery';

async function main() {
  const message = 'Simulate NBA home underdogs 2026 season';
  const messageLower = message.toLowerCase();

  console.log('Testing Pattern 12 matching');
  console.log('Message:', message);
  console.log('');

  // Test the regex patterns from chat.ts Pattern 12
  const strategyMatch = messageLower.match(/(?:test|backtest|run|try|simulate)\s+(?:the\s+)?(.+?)\s+(?:strategy|system)/i) ||
                        messageLower.match(/(?:simulate|test|backtest)\s+(\w+)\s+(home\s+underdogs?|away\s+underdogs?|home\s+favorites?|underdogs?|favorites?|overs?|unders?)/i) ||
                        messageLower.match(/(?:simulate|test|backtest)\s+(home\s+underdogs?|away\s+underdogs?|home\s+favorites?|underdogs?|favorites?|overs?|unders?)\s+(?:for\s+)?(\w+)/i) ||
                        messageLower.match(/(?:strategy|backtest)\s+(?:for|on)?\s*(.+?)(?:\s+(?:in|for)\s+(\w+))?$/i) ||
                        messageLower.match(/(?:how\s+(?:does|would|did)\s+)?(.+?)\s+(?:strategy\s+)?perform/i);

  console.log('Pattern match result:', strategyMatch ? 'MATCHED' : 'NO MATCH');
  console.log('Match groups:', strategyMatch);
  console.log('');

  if (strategyMatch) {
    // Extract details
    let strategy = '';
    let league = '';
    let season = 2026;

    const leagueMatch = messageLower.match(/\b(nba|nfl|mlb|nhl|ncaab|ncaaf)\b/i);
    if (leagueMatch) league = leagueMatch[1].toLowerCase();

    if (messageLower.includes('home') && messageLower.includes('underdog')) {
      strategy = 'home underdogs';
    }

    console.log('Extracted: strategy=', strategy, ', league=', league, ', season=', season);
    console.log('');

    // Call backtest
    const result = await directQuery.runStrategyBacktest({ strategy, league, season });
    if (result) {
      console.log('SUCCESS - Backtest executed:');
      console.log(directQuery.formatStrategyResult(result));
    } else {
      console.log('FAILED - No backtest result returned');
    }
  } else {
    console.log('ERROR - Pattern 12 did not match this message!');
    console.log('The chat will not route to runStrategyBacktest');
  }
}

main().catch(e => {
  console.error('Error:', e);
  process.exit(1);
});
