import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ErpProjectChangeVO, ErpProjectChangeForm, ErpProjectChangeQuery } from '@/api/oa/erp/erpProjectChange/types';

/**
 * 查询项目变更申请列表
 * @param query
 * @returns {*}
 */

export const listErpProjectChange = (query?: ErpProjectChangeQuery): AxiosPromise<ErpProjectChangeVO[]> => {
  return request({
    url: '/oa/erp/erpProjectChange/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询项目变更申请详细
 * @param projectChangeId
 */
export const getErpProjectChange = (projectChangeId: string | number): AxiosPromise<ErpProjectChangeVO> => {
  return request({
    url: '/oa/erp/erpProjectChange/' + projectChangeId,
    method: 'get'
  });
};

/**
 * 新增项目变更申请
 * @param data
 */
export const addErpProjectChange = (data: ErpProjectChangeForm) => {
  return request({
    url: '/oa/erp/erpProjectChange',
    method: 'post',
    data: data
  });
};

/**
 * 修改项目变更申请
 * @param data
 */
export const updateErpProjectChange = (data: ErpProjectChangeForm) => {
  return request({
    url: '/oa/erp/erpProjectChange',
    method: 'put',
    data: data
  });
};

/**
 * 删除项目变更申请
 * @param projectChangeId
 */
export const delErpProjectChange = (projectChangeId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/erp/erpProjectChange/' + projectChangeId,
    method: 'delete'
  });
};

/**
 * 下拉框查询项目变更申请列表
 * @param query
 * @returns {*}
 */
export function getErpProjectChangeList (query) {
    return request({
        url: '/oa/erp/erpProjectChange/getErpProjectChangeList',
        method: 'get',
        params: query
    });
};

/**
 * 根据项目ID准备项目变更信息（带出项目信息和项目计划阶段）
 * @param projectId
 */
export const prepareProjectChangeWithInfo = (projectId: string | number): AxiosPromise<ErpProjectChangeVO> => {
  return request({
    url: '/oa/erp/erpProjectChange/prepareWithInfo/' + projectId,
    method: 'get'
  });
};

/**
 * 提交项目变更并发起审批流
 * @param data
 */
export const submitProjectChangeAndFlowStart = (data: ErpProjectChangeForm) => {
  return request({
    url: '/oa/erp/erpProjectChange/submitAndFlowStart',
    method: 'post',
    data: data
  });
};

/**
 * 查询指定项目计划的所有变更记录
 * @param projectPlanId
 */
export const queryProjectChangeByProjectPlanId = (projectPlanId: string | number): AxiosPromise<ErpProjectChangeVO[]> => {
  return request({
    url: '/oa/erp/erpProjectChange/queryByProjectPlanId/' + projectPlanId,
    method: 'get'
  });
};

/**
 * 查询指定项目的所有历史变更记录
 * @param projectId
 */
export const getProjectChangeHistory = (projectId: string | number): AxiosPromise<ErpProjectChangeVO[]> => {
  return request({
    url: '/oa/erp/erpProjectChange/queryHistoryByProjectId/' + projectId,
    method: 'get'
  });
};
