import request from '@/utils/request';

// 获取记录规则 /mes/producetaskrulerecord/getLastRuleRecords
export async function getLastRuleRecords(data) {
  const res = await request.post(
    '/mes/producetaskrulerecord/getLastRuleRecords',
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 保存配置事项-事项规则执行记录表信息，并向EAM派单 /mes/producetaskrulerecord/saveRuleRecord
export async function saveRuleRecord(data) {
  const res = await request.post(
    '/mes/producetaskrulerecord/saveRuleRecord',
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 产前准备是否完成，工序配置事项的产前准备部分，事项里每一项都有已执行记录 /mes/producetaskrulerecord/isPreProductionResult
export async function isPreProductionResult(body) {
  const res = await request.post(
    '/mes/producetaskrulerecord/isPreProductionResult',
    body
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 分页，展示事项规则和记录规则的执行记录，无论是否临时记录 /mes/producetaskrulerecord/page
export async function producetaskrulerecordPage(body) {
  const res = await request.post('/mes/producetaskrulerecord/page', body);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 新增或编辑，临时配置事项，不派单
export async function tempSaveOrUpdate(body) {
  const res = await request.post(
    '/mes/producetaskrulerecord/tempSaveOrUpdate',
    body
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 新增执行，编辑执行，临时配置事项，并向EAM派单
export async function tempSaveOrUpdateAndSubmit(body) {
  const res = await request.post(
    '/mes/producetaskrulerecord/tempSaveOrUpdateAndSubmit',
    body
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 新增执行，编辑执行，临时配置事项，并向EAM派单
export async function logicDeleteById(id) {
  const res = await request.delete(
    `/mes/producetaskrulerecord/logicDeleteById/${id}`
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
