import request, { saveFormDataUrl, getFormConfigDetailUrl } from '../../../../utils';

// 获取表单配置
export async function getFormConfigDetail(_, form) {
  try {
    const { uuid } = form;
    const data = { uuid };
    const [error, response] = await request({ data, method: 'get', url: getFormConfigDetailUrl });
    if (error) throw error;
    return [undefined, response];
  } catch (error) {
    return [error, undefined];
  }
}

// 表单提交
export async function saveFormData(_, form = {}) {
  try {
    const { formUuid, formValue } = form;
    const data = { formUuid, ...formValue };
    const [error, response] = await request({ data, url: saveFormDataUrl, headers: { 'content-type': 'application/json' } });
    if (error) throw error;
    return [undefined, response];
  } catch (error) {
    return [error, undefined];
  }
}
