import request from '@/axios';

export const createCrudApi = baseUrl => ({
  getList(current, size, params) {
    return request({
      url: `${baseUrl}/list`,
      method: 'get',
      params: {
        ...params,
        current,
        size,
      },
    });
  },
  getDetail(id) {
    return request({
      url: `${baseUrl}/detail`,
      method: 'get',
      params: {
        id,
      },
    });
  },
  submit(row) {
    return request({
      url: `${baseUrl}/submit`,
      method: 'post',
      data: row,
    });
  },
  remove(ids) {
    return request({
      url: `${baseUrl}/remove`,
      method: 'post',
      params: {
        ids,
      },
    });
  },
  copy(id) {
    return request({
      url: `${baseUrl}/copy`,
      method: 'post',
      params: {
        id,
      },
    });
  },
  enable(id) {
    return request({
      url: `${baseUrl}/enable`,
      method: 'post',
      params: {
        id,
      },
    });
  },
  disable(id) {
    return request({
      url: `${baseUrl}/disable`,
      method: 'post',
      params: {
        id,
      },
    });
  },
  cancel(id) {
    return request({
      url: `${baseUrl}/cancel`,
      method: 'post',
      params: {
        id,
      },
    });
  },
  complete(id) {
    return request({
      url: `${baseUrl}/complete`,
      method: 'post',
      params: {
        id,
      },
    });
  },
  dispatch(payload) {
    const data = payload && typeof payload === 'object' ? payload : { id: payload };
    const id = data.id || payload;
    return request({
      url: `${baseUrl}/dispatch`,
      method: 'post',
      params: id ? { id } : undefined,
      data,
    });
  },
  reassign(id) {
    return request({
      url: `${baseUrl}/reassign`,
      method: 'post',
      params: {
        id,
      },
    });
  },
  batchComplete(ids) {
    return request({
      url: `${baseUrl}/batch-complete`,
      method: 'post',
      params: {
        ids,
      },
    });
  },
});
