/**
 * Parse ServChan WO room titles: "ServChan WO-{n} | Store {id} | {location}"
 */
const SERVCHAN_ROOM_TITLE_RE = /^ServChan WO-(\d+)\s*\|\s*Store\s*([^|]+)\|\s*(.+)$/i;

export function parseServChanRoomTitle(title) {
  if (!title || typeof title !== 'string') return null;

  const m = title.trim().match(SERVCHAN_ROOM_TITLE_RE);
  if (!m) return null;

  const woNumber = m[1];
  const storeId = m[2].trim();
  const locationName = m[3].trim();
  const headerLine = `ServChan WO-${woNumber} | Store ${storeId} | ${locationName}`;

  return { woNumber, storeId, locationName, headerLine };
}

export function getCompletedOperationsRoomId() {
  return (process.env.COMPLETED_OPERATIONS_ROOM_ID || '').trim() || null;
}
