
import { promises as fs } from 'fs';
import path from 'path';
import { Register } from '@/utils/register_parser';
import { parseNextReg } from '@/utils/register_parser';

let registers: Register[] = [];

/**
 * Gets the registers from the in-memory cache, or loads them from the file if not already loaded.
 * @returns A promise that resolves to an array of Register objects.
 */
export async function getRegisters(): Promise<Register[]> {
  // if (registers.length === 0) {
    const filePath = path.join(process.cwd(), 'data', 'nextreg.txt');
    const fileContent = await fs.readFile(filePath, 'utf8');
    registers = await parseNextReg(fileContent);
  // }
  return registers;
}
