| import { parseBetInput } from './parser.js'; | |
| export function parseBulkAddInput(book, sport, rawInput) { | |
| const lines = String(rawInput ?? '') | |
| .split(/\r?\n/) | |
| .map((line) => line.trim()) | |
| .filter(Boolean); | |
| if (lines.length === 0) { | |
| return { | |
| ok: false, | |
| error: 'Add at least one line in the format `prop | odds | stake`.', | |
| }; | |
| } | |
| const accepted = []; | |
| const rejected = []; | |
| lines.forEach((line, index) => { | |
| const parts = line.split('|').map((part) => part.trim()); | |
| if (parts.length !== 3) { | |
| rejected.push({ | |
| lineNumber: index + 1, | |
| line, | |
| reason: 'Use `prop | odds | stake` on each line.', | |
| }); | |
| return; | |
| } | |
| const [prop, odds, stake] = parts; | |
| const parsed = parseBetInput({ book, sport, prop, odds, stake }); | |
| if (!parsed.ok) { | |
| rejected.push({ | |
| lineNumber: index + 1, | |
| line, | |
| reason: `Invalid ${parsed.missingFields.join(', ')}`, | |
| }); | |
| return; | |
| } | |
| accepted.push({ | |
| lineNumber: index + 1, | |
| bet: parsed.bet, | |
| }); | |
| }); | |
| return { | |
| ok: accepted.length > 0, | |
| accepted, | |
| rejected, | |
| error: accepted.length === 0 ? 'No valid bet lines were found.' : null, | |
| }; | |
| } | |