import { createCrudApi } from './common';
import request from '@/axios';

const baseUrl = '/blade-transport/contract-manage';
const api = createCrudApi(baseUrl);

export const getList = api.getList;
export const getDetail = api.getDetail;
export const submit = api.submit;
export const remove = api.remove;
export const copy = api.copy;

export const saveDraft = row =>
  request({
    url: `${baseUrl}/save-draft`,
    method: 'post',
    data: row,
  });

export const toTemporary = id =>
  request({
    url: `${baseUrl}/to-temporary`,
    method: 'post',
    params: { id },
  });

export const submitFormal = id =>
  request({
    url: `${baseUrl}/submit-formal`,
    method: 'post',
    params: { id },
  });

export const approve = id =>
  request({
    url: `${baseUrl}/approve`,
    method: 'post',
    params: { id },
  });

export const reject = id =>
  request({
    url: `${baseUrl}/reject`,
    method: 'post',
    params: { id },
  });

export const updateAttachments = row =>
  request({
    url: `${baseUrl}/update-attachments`,
    method: 'post',
    data: row,
  });

export const withdraw = id =>
  request({
    url: `${baseUrl}/withdraw`,
    method: 'post',
    params: { id },
  });

export const startChange = (id, reason) =>
  request({
    url: `${baseUrl}/start-change`,
    method: 'post',
    params: {
      id,
      changeContent: reason,
      changeReason: reason,
    },
  });

export const terminate = (id, reason) =>
  request({
    url: `${baseUrl}/terminate`,
    method: 'post',
    params: { id, reason },
  });

export const expireStats = params =>
  request({
    url: `${baseUrl}/expire-stats`,
    method: 'get',
    params,
  });
