import type { CachedResult } from '@wordle/shared';
import { computeReplays, computeReplaysFull } from '@wordle/shared';

interface SolverTask {
  target: string;
  allWords: string[];
  mode: 'fast' | 'full';
}

process.on('message', (task: SolverTask) => {
  try {
    const result: CachedResult = task.mode === 'full'
      ? computeReplaysFull(task.target, task.allWords)
      : computeReplays(task.target, task.allWords);
    process.send!({ ok: true, value: result });
  } catch (err) {
    process.send!({ ok: false, error: String(err) });
  }
});
