import { Client } from "@upstash/qstash";

const qstash = new Client({ token: process.env.QSTASH_TOKEN! });

function getBaseUrl(): string {
  if (process.env.VERCEL_URL) {
    return `https://${process.env.VERCEL_URL}`;
  }
  return process.env.AUTH_URL || "http://localhost:3000";
}

export async function enqueueProcessing(jobId: string): Promise<void> {
  const baseUrl = getBaseUrl();
  await qstash.publishJSON({
    url: `${baseUrl}/api/jobs/process`,
    body: { jobId },
    retries: 2,
  });
}
