import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  ContractChangeVO,
  ContractChangeForm,
  ContractChangeQuery,
  ContractChangeSaveForm,
  ContractChangeDetailVO
} from '@/api/oa/erp/contractChange/types';

/**
 * 查询合同变更列表
 * @param query
 * @returns {*}
 */

export const listContractChange = (query?: ContractChangeQuery): AxiosPromise<ContractChangeVO[]> => {
  return request({
    url: '/oa/erp/contractChange/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询合同变更详细
 * @param contractChangeId
 */
export const getContractChange = (contractChangeId: string | number): AxiosPromise<ContractChangeVO> => {
  return request({
    url: '/oa/erp/contractChange/' + contractChangeId,
    method: 'get'
  });
};

/**
 * 新增合同变更
 * @param data
 */
export const addContractChange = (data: ContractChangeForm) => {
  return request({
    url: '/oa/erp/contractChange',
    method: 'post',
    data: data
  });
};

/**
 * 修改合同变更
 * @param data
 */
export const updateContractChange = (data: ContractChangeForm) => {
  return request({
    url: '/oa/erp/contractChange',
    method: 'put',
    data: data
  });
};

/**
 * 删除合同变更
 * @param contractChangeId
 */
export const delContractChange = (contractChangeId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/erp/contractChange/' + contractChangeId,
    method: 'delete'
  });
};

/**
 * 下拉框查询合同变更列表
 * @param query
 * @returns {*}
 */
export function getErpContractChangeList(query) {
  return request({
    url: '/oa/erp/contractChange/getErpContractChangeList',
    method: 'get',
    params: query
  });
}

/**
 * 保存合同变更（主表+信息+物料+付款方式 一个接口）
 * @param data
 */
export const saveContractChange = (data: ContractChangeSaveForm): AxiosPromise<number> => {
  return request({
    url: '/oa/erp/contractChange/save',
    method: 'post',
    data
  });
};

/**
 * 提交合同变更并提交流程（解除合同时使用，走 HTBG）
 * @param data 保存数据
 */
export const contractChangeSubmitAndFlowStart = (
  data: ContractChangeSaveForm
): AxiosPromise<ContractChangeVO> => {
  return request({
    url: '/oa/erp/contractChange/contractChangeSubmitAndFlowStart',
    method: 'post',
    data
  });
};

/**
 * 合同内容变更提交：不走 HTBG，保存变更单并新增合同，新合同走正常合同流程（OAC）
 * @param data 保存数据（主表 + changeInfo + changeMaterialList + changePaymentMethodList）
 */
export const contractChangeContentSubmit = (
  data: ContractChangeSaveForm
): AxiosPromise<ContractChangeVO> => {
  return request({
    url: '/oa/erp/contractChange/submitContentChange',
    method: 'post',
    data
  });
};

/**
 * 查询合同变更详情（主表+信息+物料+付款方式）
 * @param contractChangeId
 */
export const getContractChangeDetail = (
  contractChangeId: string | number
): AxiosPromise<ContractChangeDetailVO> => {
  return request({
    url: '/oa/erp/contractChange/detail/' + contractChangeId,
    method: 'get'
  });
};
