/** 智能解析房间号，自动推导楼栋、楼层、宿舍类型 */
export function parseRoomNumber(roomNumber: string): {
  building?: string;
  floor?: number;
  roomType?: string;
  capacity?: number;
} {
  const cleaned = roomNumber.replace(/[（(].*?[）)]/g, '').trim();
  // 家庭房: X-Y-ZZZ 格式
  const familyMatch = cleaned.match(/^(\d+)-(\d+)-(\d+)$/);
  if (familyMatch) {
    const bldg = `${familyMatch[1]}-${familyMatch[2]}栋`;
    const roomPart = familyMatch[3];
    const rawFloor = parseInt(roomPart.charAt(0), 10);
    const floor = Number.isNaN(rawFloor) ? undefined : rawFloor;
    return { building: bldg, floor, roomType: '家庭房', capacity: 4 };
  }
  // 标准: X-YZZ 格式
  const stdMatch = cleaned.match(/^(\d+)-(\d+)$/);
  if (stdMatch) {
    const bldgNum = stdMatch[1];
    const roomPart = stdMatch[2];
    const rawFloor = parseInt(roomPart.charAt(0), 10);
    const floor = Number.isNaN(rawFloor) ? undefined : rawFloor;
    const building = `${bldgNum}号楼`;
    let roomType = '四人间';
    let capacity = 4;
    if (bldgNum === '2') {
      roomType = '单人间';
      capacity = 1;
    } else if (bldgNum === '8') {
      roomType = '爆改房';
      capacity = 2;
    }
    return { building, floor, roomType, capacity };
  }
  return { capacity: 4, roomType: '四人间' };
}
