import { request } from '../../lib/api' import type { RApplication, RApplicationDetail, RApplicationList, RDispositionCatalog, RPipelineBoard, } from '../../lib/types' const NS = '/recruiting' const body = (v: unknown) => ({ body: JSON.stringify(v) }) export const pipelineApi = { board: (reqId: string) => request(`${NS}/requisitions/${encodeURIComponent(reqId)}/pipeline`), submit: (reqId: string, v: { candidate_id: string; stage?: string; source_touch?: string; reason?: string }) => request(`${NS}/requisitions/${encodeURIComponent(reqId)}/applications`, { method: 'POST', ...body(v) }), get: (id: string) => request(`${NS}/applications/${encodeURIComponent(id)}`), list: (p: { candidate_id?: string; stage?: string }) => { const s = new URLSearchParams() if (p.candidate_id) s.set('candidate_id', p.candidate_id) if (p.stage) s.set('stage', p.stage) const qs = s.toString() return request(`${NS}/applications${qs ? `?${qs}` : ''}`) }, // expected_stage is required. It is the concurrency token, and the database refuses the move unless the // application is still where this screen last saw it. move: (id: string, v: { expected_stage: string; to_stage: string; reason?: string; disposition_code?: string }) => request(`${NS}/applications/${encodeURIComponent(id)}/stage`, { method: 'POST', ...body(v) }), dispositions: () => request(`${NS}/dispositions`), }