export const JOB_DETAILS_TABS = {
  overview: 0,
  correspondence: 1,
  attachments: 2,
  tailoredCv: 3,
  followUp: 4,
  candidateFit: 5,
  focusPlan: 6,
  interviewPrep: 7,
  readiness: 8,
  history: 9,
} as const;

export type JobWorkspaceOpenOptions = {
  tab?: number;
  followMode?: string;
};

const WORKSPACE_SECTION_BY_TAB: Record<number, string> = {
  [JOB_DETAILS_TABS.overview]: "overview",
  [JOB_DETAILS_TABS.correspondence]: "communication",
  [JOB_DETAILS_TABS.attachments]: "documents",
  [JOB_DETAILS_TABS.tailoredCv]: "cv",
  [JOB_DETAILS_TABS.followUp]: "communication",
  [JOB_DETAILS_TABS.candidateFit]: "match",
  [JOB_DETAILS_TABS.focusPlan]: "analysis",
  [JOB_DETAILS_TABS.interviewPrep]: "interview",
  [JOB_DETAILS_TABS.readiness]: "checklist",
  [JOB_DETAILS_TABS.history]: "timeline",
};

export function buildJobWorkspacePath(jobId: number, options: JobWorkspaceOpenOptions = {}) {
  const params = new URLSearchParams();
  const section = typeof options.tab === "number" ? WORKSPACE_SECTION_BY_TAB[options.tab] : undefined;
  if (section && section !== "overview") params.set("section", section);
  if (options.followMode) params.set('followMode', options.followMode);
  return `/jobs/${jobId}${params.size ? `?${params.toString()}` : ""}`;
}
