import api from './client';

export const FormsApi = {
  createForm(payload) {
    return api.put('/forms/', payload).then((r) => r.data);
  },
  updateForm(formId, payload) {
    return api.patch(`/forms/${formId}`, payload).then((r) => r.data);
  },
  createFormFromOther(payload) {
    return api.put(`/forms/create-by-form`, payload).then((r) => r.data);
  },
  getForm(formId) {
    return api.get(`/form/${formId}`).then((r) => r.data);
  },
  formsList() {
    return api.get('/form/').then((r) => r.data.result);
  },
  formTablesList(formId, isTemplate) {
    return api
      .get(`/forms/${formId}/tables`, {
        params: { is_template: isTemplate },
      })
      .then((r) => r.data);
  },

  getProjects(formId) {
    return api.get(`/forms/${formId}/projects`).then((r) => r.data);
  },

  createProjects(formId, projectData) {
    return api
      .put(`/forms/${formId}/projects`, projectData)
      .then((r) => r.data);
  },

  createProjectTable(formId, projectId, payload) {
    return api
      .put(`/forms/${formId}/projects/${projectId}/create-table`, payload)
      .then((r) => r.data);
  },
};
