import api from "./client";

export const TasksApi = {
  getById(taskId) {
    return api.get(`/form/${taskId}`).then((r) => r.data);
  },
  list(params = {}) {
    return api.get("/form/", { params }).then((r) => r.data);
  },
  getSheets(taskId) {
    return api.get(`/form/${taskId}/sheets`).then((r) => r.data);
  },
  getById(formId) {
    return api.get(`/form/${formId}`).then((r) => r.data);
  },
  create(payload) {
    return api.post("/form/", payload).then((r) => r.data);
  },
  editTask(taskId, payload = {}) {
    return api.patch(`/tasks/${taskId}`, payload).then((r) => r.data);
  },
  editTaskStages(taskId, stageId, payload = {}) {
    return api
      .patch(`/tasks/${taskId}/stages/${stageId}`, payload)
      .then((r) => r.data);
  },
  getProjects(taskId) {
    return api.get(`/tasks/${taskId}/projects`).then((r) => r.data);
  },
  createProjectTable(taskId, payload) {
    return api.post(`/tasks/${taskId}/projects`, payload).then((r) => r.data);
  },
  exportTask(taskId, params = {}) {
    return api.get(`export/form/${taskId}`, {
      params,
      responseType: "blob",
    });
  },
  exportTasks(payload, params = {}) {
    return api.post(`export/bulk`, payload, {
      params,
      responseType: "blob",
    });
  },
};
