import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ContractInfoForm, ContractInfoQuery, ContractInfoVO } from '@/api/oa/erp/contractInfo/types';

/**
 * 查询合同信息列表
 * @param query
 * @returns {*}
 */

export const listContractInfo = (query?: ContractInfoQuery): AxiosPromise<ContractInfoVO[]> => {
  return request({
    url: '/oa/erp/contractInfo/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询框架合同列表
 * @param query
 * @returns {*}
 */
export const listFrameworkContractInfo = (query?: ContractInfoQuery): AxiosPromise<ContractInfoVO[]> => {
  return request({
    url: '/oa/erp/contractInfo/framework/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询合同信息详细
 * @param contractId
 */
export const getContractInfo = (contractId: string | number): AxiosPromise<ContractInfoVO> => {
  return request({
    url: '/oa/erp/contractInfo/' + contractId,
    method: 'get'
  });
};

/**
 * 新增合同信息
 * @param data
 */
export const addContractInfo = (data: ContractInfoForm) => {
  return request({
    url: '/oa/erp/contractInfo',
    method: 'post',
    data: data
  });
};

/**
 * 修改合同信息
 * @param data
 */
export const updateContractInfo = (data: ContractInfoForm) => {
  return request({
    url: '/oa/erp/contractInfo',
    method: 'put',
    data: data
  });
};

/**
 * 删除合同信息
 * @param contractId
 */
export const delContractInfo = (contractId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/erp/contractInfo/' + contractId,
    method: 'delete'
  });
};

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

/**
 * 提交合同并发起流程
 * @param data
 */
export const contractSubmitAndFlowStart = (data: ContractInfoForm): AxiosPromise<ContractInfoVO> => {
  return request({
    url: '/oa/erp/contractInfo/contractSubmitAndFlowStart',
    method: 'post',
    data: data
  });
};

/**
 * 导出合同审批单Word文档
 * @param contractId 合同ID
 */
export const exportContractApprovalWord = (contractId: string | number) => {
  return request({
    url: '/oa/erp/contractInfo/exportApprovalWord/' + contractId,
    method: 'get',
    responseType: 'blob'
  });
};

/**
 * 复制合同信息（新合同暂存；与后端 ErpContractInfoBo 一致：contractId 为被复制合同ID，contractCode、contractName 为新合同编号与名称）
 */
export const copyContractInfo = (data: ContractInfoForm): AxiosPromise<ContractInfoVO> => {
  return request({
    url: '/oa/erp/contractInfo/copy',
    method: 'post',
    data
  });
};
