import readline from 'readline';
import Parser from './parser.ts';

// mutate fetch to be local

// @ts-expect-error Global override
// eslint-disable-next-line no-global-assign
fetch = async (path: string) => {
  const fs = await import('fs');
  return {
    json: () => JSON.parse(fs.readFileSync(`public/${path}`) as unknown as string),
  };
};

const parser = await Parser.instance();

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
rl.question(`Terminal ID? `, async (id) => {
  console.log(JSON.stringify(await parser.parse(Number.parseInt(id))));
  rl.close();
});
