import type { Approval, Issue, IssueAttachment, IssueComment, IssueLabel } from "@paperclip/shared"; import { api } from "./client"; export const issuesApi = { list: (companyId: string, filters?: { projectId?: string }) => { const params = new URLSearchParams(); if (filters?.projectId) params.set("projectId", filters.projectId); const qs = params.toString(); return api.get(`/companies/${companyId}/issues${qs ? `?${qs}` : ""}`); }, listLabels: (companyId: string) => api.get(`/companies/${companyId}/labels`), createLabel: (companyId: string, data: { name: string; color: string }) => api.post(`/companies/${companyId}/labels`, data), deleteLabel: (id: string) => api.delete(`/labels/${id}`), get: (id: string) => api.get(`/issues/${id}`), create: (companyId: string, data: Record) => api.post(`/companies/${companyId}/issues`, data), update: (id: string, data: Record) => api.patch(`/issues/${id}`, data), remove: (id: string) => api.delete(`/issues/${id}`), checkout: (id: string, agentId: string) => api.post(`/issues/${id}/checkout`, { agentId, expectedStatuses: ["todo", "backlog", "blocked"], }), release: (id: string) => api.post(`/issues/${id}/release`, {}), listComments: (id: string) => api.get(`/issues/${id}/comments`), addComment: (id: string, body: string, reopen?: boolean) => api.post(`/issues/${id}/comments`, reopen === undefined ? { body } : { body, reopen }), listAttachments: (id: string) => api.get(`/issues/${id}/attachments`), uploadAttachment: ( companyId: string, issueId: string, file: File, issueCommentId?: string | null, ) => { const form = new FormData(); form.append("file", file); if (issueCommentId) { form.append("issueCommentId", issueCommentId); } return api.postForm(`/companies/${companyId}/issues/${issueId}/attachments`, form); }, deleteAttachment: (id: string) => api.delete<{ ok: true }>(`/attachments/${id}`), listApprovals: (id: string) => api.get(`/issues/${id}/approvals`), linkApproval: (id: string, approvalId: string) => api.post(`/issues/${id}/approvals`, { approvalId }), unlinkApproval: (id: string, approvalId: string) => api.delete<{ ok: true }>(`/issues/${id}/approvals/${approvalId}`), };