File size: 11,335 Bytes
0134cb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import type {
  ChartIndexRow,
  EngineResponse,
  LeadersResponse,
  NflLine,
  NflInjury,
  OddsResponse,
  NflDepthChart,
  NflGame,
  NflStandingTeam,
  ParlaySlip,
  PlayerInfo,
  PlayerPropChart,
  PlayerSearchResult,
  RampGamedayResponse,
} from "./types";
import type { BacktestRow, CfbBigMoneyParlay, CfbCrazyHorse, CfbGame, CfbHotDog, CfbOver, HotDogBacktest, HotDogGame, MatchupGame, NewsArticle, PowSummary, SourceStatus } from "./types";

const BASE = import.meta.env.VITE_API_BASE ?? "http://localhost:8000";
export const API_BASE = BASE;

async function get<T>(path: string): Promise<T> {
  const res = await fetch(`${BASE}${path}`);
  if (!res.ok) throw new Error(`${path} -> ${res.status}`);
  return res.json();
}

export const api = {
  index: () => get<ChartIndexRow[]>("/api/index"),
  searchPlayers: (q: string) => get<PlayerSearchResult[]>(`/api/players/search?q=${encodeURIComponent(q)}`),
  playerProps: (playerId: string, market: string) =>
    get<PlayerPropChart>(`/api/chart/player_props?player_id=${encodeURIComponent(playerId)}&market=${market}`),
  odds: (league: string, refresh = false) => get<OddsResponse>(`/api/odds?league=${league}${refresh ? "&refresh=true" : ""}`),
  leaders: (category: string) => get<LeadersResponse>(`/api/chart/leaders?category=${encodeURIComponent(category)}`),
  parlay: (slip: string) => get<ParlaySlip>(`/api/chart/parlays?slip=${slip}`),
  throwdown: () => get<any>("/api/throwdown"),
  matchup: () => get<any>("/api/matchup"),
  parlaysAll: () => get<Record<string, ParlaySlip>>("/api/chart/parlays/all"),
  canvasNodes: () => get<{ nodes: { id: string; type: "lake" | "expert"; name: string; sub: string; chips?: string[]; store?: string }[] }>(
    "/api/canvas/nodes"
  ),
  teamAtsHeatmap: () =>
    get<{ sourceStatus: string; cells: { team: string; week: string; covered: boolean }[] }>(
      "/api/chart/team_ats_heatmap"
    ),
  dvp: () => get<{ sourceStatus: string; rows: { team: string; toxicity: number; category: string }[] }>("/api/chart/dvp"),
  parlaysEngine: () => get<EngineResponse>("/api/parlays/engine"),
  newsArticles: () => get<{ articles: NewsArticle[] }>("/api/news/articles"),
  pow: () => get<PowSummary>("/api/pow"),
  matchups: () => get<{ sourceStatus: SourceStatus; games: MatchupGame[] }>("/api/matchups"),
  hotdogs: () => get<{ sourceStatus: SourceStatus; games: HotDogGame[]; backtest: HotDogBacktest }>("/api/hotdogs"),
  matchupsBacktest: () => get<{ sourceStatus: SourceStatus; rows: BacktestRow[] }>("/api/matchups/backtest"),

  jimmyHunt: () => get<Record<string, unknown>>("/api/jimmy/hunt"),
  jimmyAiStatus: () => get<Record<string, unknown>>("/api/jimmy/ai-status"),
  jimmyNuggets: () => get<Record<string, unknown>>("/api/jimmy/nuggets"),
  jimmyNuggetsRefresh: () => fetch(`${BASE}/api/jimmy/nuggets/refresh`, { method: "POST" }).then(r => r.json()),
  jimmyDeepDive: (query: string) =>
    fetch(`${BASE}/api/jimmy/deep-dive`, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ query }),
    }).then(r => r.json()),
  teamLogos: () => get<Record<string, { team_abbr: string; team_name: string; team_nick: string; color1: string; color2: string; logo_espn: string; logo_espn_dark: string; wordmark: string }>>("/api/team-logos"),
  cfbStatus:     () => get<Record<string, unknown>>("/api/cfb/status"),
  cfbSlate:      () => get<{ games: CfbGame[] }>("/api/cfb/slate"),
  cfbHotDogs:    () => get<{ parlays: CfbHotDog[] }>("/api/cfb/hot-dogs"),
  cfbOvers:      (date?: string) => get<{ overs: CfbOver[] }>(`/api/cfb/overs${date ? `?date=${date}` : ""}`),
  cfbLocks:      (date?: string) => get<{ locks: CfbHotDog[] }>(`/api/cfb/locks${date ? `?date=${date}` : ""}`),
  cfbBigMoney:   (date?: string) => get<{ parlays: CfbBigMoneyParlay[] }>(`/api/cfb/big-money${date ? `?date=${date}` : ""}`),
  cfbCrazyHorse: (date?: string) => get<{ horses: CfbCrazyHorse[] }>(`/api/cfb/crazy-horse${date ? `?date=${date}` : ""}`),

  // ── Tank01 endpoints ──────────────────────────────────────────────────────
  nflStandings:   () => get<{ standings: Record<string, NflStandingTeam[]>; tank01Available: boolean }>("/api/nfl/standings"),
  nflGames:       (date?: string) => get<{ games: NflGame[]; tank01Available: boolean }>(`/api/nfl/games${date ? `?date=${date}` : ""}`),
  nflSchedule:    () => get<{ games: NflGame[]; tank01Available: boolean }>("/api/nfl/schedule"),
  nflInjuries:    () => get<{ injuries: NflInjury[]; count: number; tank01Available: boolean }>("/api/nfl/injuries"),
  nflInactives:   (week?: number) => get<{ inactives: NflInjury[]; count: number; tank01Available: boolean }>(`/api/nfl/inactives${week ? `?week=${week}` : ""}`),
  nflDepthCharts: (team?: string) => get<{ charts: NflDepthChart; tank01Available: boolean }>(`/api/nfl/depth-charts${team ? `?team=${team}` : ""}`),
  nflScoreboard:  (date?: string) => get<{ games: NflGame[]; tank01Available: boolean }>(`/api/nfl/scoreboard${date ? `?date=${date}` : ""}`),
  nflProjections: (week?: number) => get<{ projections: unknown[]; count: number; tank01Available: boolean }>(`/api/nfl/projections${week ? `?week=${week}` : ""}`),
  playerInfo:     (playerId: string) => get<{ info: PlayerInfo; tank01Available: boolean }>(`/api/player/${encodeURIComponent(playerId)}/info`),

  // ── Sportsbook / Odds API ─────────────────────────────────────────────────
  oddsNfl:         () => get<{ lines: NflLine[]; count: number; sbAvailable: boolean }>("/api/odds/nfl"),
  oddsCfb:         () => get<{ lines: NflLine[]; count: number; sbAvailable: boolean }>("/api/odds/cfb"),
  oddsNflProps:    (eventId: string) => get<{ props: unknown[]; count: number; sbAvailable: boolean }>(`/api/odds/nfl/props?event_id=${encodeURIComponent(eventId)}`),
  oddsNflMovement: () => get<{ movement: Record<string, unknown>; sbAvailable: boolean }>("/api/odds/nfl/movement"),
  oddsBestLine:    (team: string, market?: string) => get<{ result: { bookmaker: string; price: number; eventID: string } | null; sbAvailable: boolean }>(`/api/odds/best-line?team=${encodeURIComponent(team)}${market ? `&market=${market}` : ""}`),

  // ── RAMP gameday (all-in-one) ─────────────────────────────────────────────
  rampGameday: (date?: string) => get<RampGamedayResponse>(`/api/ramp/gameday${date ? `?date=${date}` : ""}`),

  // ── #14 Target share + #15/#25 Grader ────────────────────────────────────
  targetShare: (team?: string) => get<{ teams: Record<string, unknown[]>; season: number }>(`/api/target-share${team ? `?team=${encodeURIComponent(team)}` : ""}`),
  graderSeasonStats: () => get<{ crazyHorse: unknown; hotDog: unknown }>("/api/grader/season-stats"),

  // ── MY BOO ticket engine ──────────────────────────────────────────────────
  myBooTickets: (orderType?: string) =>
    get<{ tickets: MyBooTicket[] }>(`/api/myboo/tickets${orderType ? `?order_type=${orderType}` : ""}`),
  myBooCreateTicket: (payload: Record<string, unknown>) =>
    fetch(`${BASE}/api/myboo/tickets`, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(payload),
    }).then(r => r.json()),
  myBooLedger: () => get<{ ledger: MyBooWeek[] }>("/api/myboo/ledger"),
  myBooTrainingLog: () => get<MyBooTrainingLog>("/api/myboo/training-log"),
  myBooPostMortem: () => get<MyBooPostMortem>("/api/myboo/post-mortem"),
  myBooReports: (limit?: number) => get<{ reports: MyBooReport[] }>(`/api/myboo/reports${limit ? `?limit=${limit}` : ""}`),
};

export interface MyBooLeg {
  leg_id: string;
  ticket_id: string;
  player_name: string;
  team: string;
  market: string;
  direction: string;
  line: string;
  odds: string;
  probability: string;
  game_date: string;
  actual_value: string;
  pct_complete: number;
  status: "PENDING" | "WON" | "LOST" | "PUSH";
}

export interface MyBooTicket {
  ticket_id: string;
  order_type: "POW" | "SIM";
  name: string;
  created_at: string;
  season: string;
  week: string;
  status: "OPEN" | "IN_PROGRESS" | "SETTLED_WIN" | "SETTLED_LOSS" | "PUSH_VOID";
  payout_odds: string;
  stake_units: string;
  result_units: string;
  settled_at: string;
  note: string;
  legs: MyBooLeg[];
}

export interface MyBooWeek {
  season: number;
  week: number;
  pow_tickets: number;
  wins: number;
  losses: number;
  pending: number;
  units_staked: number;
  units_won: number;
  hit_rate: number | null;
  roi: number | null;
}

export interface MyBooTrainingLog {
  summary: string;
  hit_patterns: Array<{ market: string; direction: string; total: number; hits: number; misses: number; hit_rate: number; avg_margin: number }>;
  failure_modes: Array<{ market: string; direction: string; total: number; hits: number; misses: number; hit_rate: number; avg_margin: number; failure_type: string }>;
  scale_recommendations: Array<{ market: string; direction: string; recommendation: string; confidence: string; hit_rate: number; total: number }>;
  training_payload: Record<string, { weight_adjustment: number; sample_size: number }>;
}

export interface MyBooPickBar {
  line: number; actual: number; avg_l4: number; max: number;
  line_raw: number | null; actual_raw: number | null; avg_l4_raw: number | null;
}

export interface MyBooFactor {
  type: string; severity: "positive" | "negative" | "warning" | "info" | "neutral";
  label: string; detail: string;
}

export interface MyBooPickDetail {
  pick_id: string; player: string; team: string; market: string; direction: string;
  line: number | null; odds: string; probability: number | null;
  actual: number | null; avg_last4: number | null;
  result: string; horse_type: string; week: string; game_date: string;
  bar: MyBooPickBar; factors: MyBooFactor[];
}

export interface MyBooGap {
  player_id: string; market: string; week: string;
  actual: number; avg_last4: number; gap_pct: number; note: string;
}

export interface MyBooReport {
  date: string; week: string;
  total_picks: number; graded: number; hits: number; misses: number; pending: number;
  hit_rate: number | null;
  pow_tickets: number; sim_tickets: number;
  pick_details: MyBooPickDetail[];
  gaps: MyBooGap[];
  adjustment_note: string;
  headline: string;
}

export interface MyBooPostMortem {
  summary: { total_graded: number; near_misses: number; left_on_table: number; aggressive_recs_ready: number };
  near_misses: Array<{ player: string; market: string; direction: string; line: number; actual: number; margin: number; pct_off: number; week: string; note: string }>;
  left_on_table: Array<{ player: string; market: string; line: number; actual: number; over_by: number; pct_over: number; week: string; note: string }>;
  aggressive_scale_recs: Array<{ player: string; market: string; games_analyzed: number; avg_pct_over_line: number; recommendation: string; confidence: string }>;
  conservatism_note: string;
}