import { Position } from '../../global/database/schema'; const POSITION_ALIASES: Record = { // TOP top: 'TOP', 탑: 'TOP', top레인: 'TOP', // JUNGLE jgl: 'JGL', jungle: 'JGL', jng: 'JGL', jg: 'JGL', 정글: 'JGL', 정글러: 'JGL', // MID mid: 'MID', middle: 'MID', 미드: 'MID', // ADC (BOTTOM) adc: 'ADC', ad: 'ADC', bot: 'ADC', bottom: 'ADC', 원딜: 'ADC', 바텀: 'ADC', // SUP sup: 'SUP', supp: 'SUP', spt: 'SUP', sp: 'SUP', support: 'SUP', 서폿: 'SUP', 서포터: 'SUP', }; export interface ParsedPositions { positions: Position[]; } export class PositionParseError extends Error { constructor( public readonly reason: | 'too_few' | 'too_many' | 'duplicate' | 'unknown' | 'empty', public readonly token?: string, ) { super(`Position parse error: ${reason}${token ? ` (${token})` : ''}`); } } export function parsePositionList(input: string): ParsedPositions { const trimmed = input.trim(); if (trimmed.length === 0) { throw new PositionParseError('empty'); } const tokens = trimmed .split(',') .map((t) => t.trim()) .filter((t) => t.length > 0); if (tokens.length < 2) { throw new PositionParseError('too_few'); } if (tokens.length > 5) { throw new PositionParseError('too_many'); } const positions: Position[] = []; const seen = new Set(); for (const token of tokens) { const key = normalizePositionAlias(token); const mapped = POSITION_ALIASES[key]; if (!mapped) { throw new PositionParseError('unknown', token); } if (seen.has(mapped)) { throw new PositionParseError('duplicate', token); } seen.add(mapped); positions.push(mapped); } return { positions }; } export function isPositionAlias(input: string): boolean { return Boolean(POSITION_ALIASES[normalizePositionAlias(input)]); } function normalizePositionAlias(input: string): string { return input.toLowerCase().replace(/\s+/g, ''); }