/**
 * Re-enqueue Guru post-call processing for conversations whose ElevenLabs
 * webhook never arrived (e.g. tunnel URL rotated, dashboard webhook off).
 *
 * Usage:
 *   pnpm --filter @karma/core exec tsx src/cmd/guru-reprocess.ts <conversation_id> [...]
 *
 * Idempotent: processing skips conversations already marked
 * ticket.postcall_processed. NOTE: a run creates the ClickUp task and writes
 * a Viewpoint member log — review the conversation ids before running.
 */
import "dotenv/config";
import { getGuruPostCallQueue } from "@/internal/queue/guru-postcall.queue";

const ids = process.argv.slice(2);
if (!ids.length) {
  console.error("Usage: guru-reprocess.ts <conversation_id> [...]");
  process.exit(1);
}

const main = async () => {
  const queue = getGuruPostCallQueue();
  for (const conversationId of ids) {
    // Fresh jobId suffix so a previously completed/failed job doesn't block it.
    await queue.add(
      "post-call",
      { conversationId },
      { jobId: `guru-postcall-${conversationId}-manual-${Date.now()}` },
    );
    console.log(`enqueued ${conversationId}`);
  }
  await queue.close();
};

main().then(() => process.exit(0));
