import { describe, expect, it } from 'vitest';
import { buildSportsWeatherMapPrompt } from '../sports-weather-map-prompt';
import type { PublicTopPicksResponseV1 } from '../../contracts/forecast-public-contract';

const sample: PublicTopPicksResponseV1 = {
  contractVersion: 'forecast-public-v1',
  league: 'nba',
  generatedAt: '2026-04-15T19:14:15.146Z',
  count: 3,
  entries: [
    {
      kind: 'prop',
      rankPosition: 1,
      boardScore: 72.1,
      clvMetric: 77,
      edgeMetric: 12,
      confidenceMetric: 69.6,
      signalMetric: 8,
      prop: {
        assetId: 'asset-1',
        eventId: 'evt-1',
        league: 'nba',
        startsAt: '2026-04-16T02:10:00.000Z',
        playerName: 'Kris Dunn',
        team: 'LAC',
        opponent: 'Golden State Warriors',
        propType: 'Pts + Reb',
        marketLine: 9.5,
        odds: -136,
        marketImpliedProbability: 57.6,
        forecastDirection: 'OVER',
        projectedProbability: 69.6,
        projectedOutcome: 12.5,
        edgePct: 12,
        signal: 'FAIR',
        agreementLabel: 'LOW',
        marketQualityLabel: 'GOOD',
        clvFitLabel: 'TRACKED',
        clvFitScore: 77,
        clvTracked: true,
        closingLineValue: null,
        verificationLabel: 'Double-verified odds',
        verificationType: 'sportsbook',
        rankScore: 100,
        rankPosition: 1,
      },
    },
    {
      kind: 'prop',
      rankPosition: 2,
      boardScore: 69.8,
      clvMetric: 76,
      edgeMetric: 12,
      confidenceMetric: 68.1,
      signalMetric: 8,
      prop: {
        assetId: 'asset-2',
        eventId: 'evt-2',
        league: 'nba',
        startsAt: '2026-04-15T23:40:00.000Z',
        playerName: 'Paul George',
        team: 'PHI',
        opponent: 'Orlando Magic',
        propType: 'Pts + Reb + Ast',
        marketLine: 31.5,
        odds: -128,
        marketImpliedProbability: 56.1,
        forecastDirection: 'UNDER',
        projectedProbability: 68.1,
        projectedOutcome: 28,
        edgePct: 12,
        signal: 'FAIR',
        agreementLabel: 'LOW',
        marketQualityLabel: 'GOOD',
        clvFitLabel: 'TRACKED',
        clvFitScore: 76,
        clvTracked: true,
        closingLineValue: null,
        verificationLabel: 'Double-verified odds',
        verificationType: 'sportsbook',
        rankScore: 89.2,
        rankPosition: 2,
      },
    },
    {
      kind: 'game',
      rankPosition: 3,
      boardScore: 66.4,
      clvMetric: 0,
      edgeMetric: 3.2,
      confidenceMetric: 67,
      signalMetric: 20,
      game: {
        eventId: 'evt-3',
        league: 'nba',
        startsAt: '2026-04-16T01:30:00.000Z',
        homeTeam: 'Los Angeles Lakers',
        awayTeam: 'Phoenix Suns',
        homeShort: 'LAL',
        awayShort: 'PHX',
        forecastSide: 'Lakers -4.5',
        confidencePct: 67,
        edge: 3.2,
        valueRating: 78,
        hasSharpSignal: true,
        hasSteamSignal: false,
        verificationLabel: 'Double-verified odds',
        verificationType: 'sportsbook',
      },
    },
  ],
  filters: {
    propTypes: ['Points', 'Pts + Reb', 'Pts + Reb + Ast'],
    teams: ['LAC', 'PHI', 'LAL', 'PHX'],
    players: ['Kris Dunn', 'Paul George'],
    kinds: ['game', 'prop'],
  },
  emptyMessage: 'No pregame picks available in this window',
};

describe('buildSportsWeatherMapPrompt', () => {
  it('builds stitched clip prompts capped at eight seconds', () => {
    const result = buildSportsWeatherMapPrompt(sample, { clipSeconds: 12, clipCount: 4 });

    expect(result.sport).toBe('basketball');
    expect(result.clips).toHaveLength(4);
    expect(result.clips.every((clip) => clip.durationSeconds <= 8)).toBe(true);
    expect(result.prompt).toContain('stitched clips');
    expect(result.prompt).toContain('Kris Dunn OVER 9.5 Pts + Reb');
    expect(result.prompt).toContain('Paul George UNDER 31.5 Pts + Reb + Ast');
    expect(result.prompt).toContain('Lakers -4.5 game edge');
  });
});
