import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ProjectInfoVO, ProjectInfoForm, ProjectInfoQuery } from '@/api/oa/erp/projectInfo/types';
import { ContractOrderPurchaseMaterialVO, PartyACustomerValidateVO } from '@/api/oa/erp/contractOrder/types';

/**
 * 查询合同订单列表
 * @param query
 * @returns {*}
 */
export const listContractOrder = (query?: ProjectInfoQuery): AxiosPromise<ProjectInfoVO[]> => {
  return request({
    url: '/oa/erp/contractOrder/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询合同订单待办列表（项目经理或合同激活创建人）
 * @param query
 * @returns {*}
 */
export const listContractOrderTodo = (query?: Partial<ProjectInfoQuery>): AxiosPromise<ProjectInfoVO[]> => {
  return request({
    url: '/oa/erp/contractOrder/todoList',
    method: 'get',
    params: query
  });
};

/**
 * 暂存合同订单（项目信息）
 * @param data
 */
export const saveContractOrder = (data: ProjectInfoForm): AxiosPromise<ProjectInfoVO> => {
  return request({
    url: '/oa/erp/contractOrder/save',
    method: 'post',
    data: data
  });
};

/**
 * 提交合同订单并提交流程
 * @param data
 */
export const submitContractOrderAndFlowStart = (data: ProjectInfoForm): AxiosPromise<ProjectInfoVO> => {
  return request({
    url: '/oa/erp/contractOrder/submitAndFlowStart',
    method: 'post',
    data: data
  });
};

/**
 * 修改合同订单（项目信息）
 * @param data
 */
export const updateContractOrder = (data: ProjectInfoForm): AxiosPromise<ProjectInfoVO> => {
  return request({
    url: '/oa/erp/contractOrder',
    method: 'put',
    data: data
  });
};

/**
 * 查询合同订单详细信息
 * @param projectId
 */
export const getContractOrder = (projectId: string | number): AxiosPromise<ProjectInfoVO> => {
  return request({
    url: '/oa/erp/contractOrder/' + projectId,
    method: 'get'
  });
};

/**
 * 查询合同订单采购物料清单
 * @param contractId 合同ID
 */
export const getContractOrderPurchaseMaterialList = (contractId: string | number): AxiosPromise<ContractOrderPurchaseMaterialVO[]> => {
  return request({
    url: '/oa/erp/contractOrder/purchaseMaterialList/' + contractId,
    method: 'get'
  });
};

/**
 * 订单激活时校验甲方客户基础信息
 * @param contractId 合同ID
 */
export const validPartyACustomerForOrderActivate = (contractId: string | number): AxiosPromise<PartyACustomerValidateVO> => {
  return request({
    url: '/oa/erp/contractOrder/validPartyACustomer/' + contractId,
    method: 'get'
  });
};

