import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { TimesheetPreAllocVO, TimesheetPreAllocForm, TimesheetPreAllocQuery, PreAllocDetailVO } from '@/api/oa/erp/timesheetPreAlloc/types';

/**
 * 查询预投工时分配列表
 * @param query
 * @returns {*}
 */

export const listTimesheetPreAlloc = (query?: TimesheetPreAllocQuery): AxiosPromise<TimesheetPreAllocVO[]> => {
  return request({
    url: '/oa/erp/timesheetPreAlloc/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询预投工时分配详细
 * @param allocId
 */
export const getTimesheetPreAlloc = (allocId: string | number): AxiosPromise<PreAllocDetailVO> => {
  return request({
    url: '/oa/erp/timesheetPreAlloc/' + allocId,
    method: 'get'
  });
};

/**
 * 查询当前部门指定月份、来源预投项目的员工级可分配明细
 */
export const getAllocDetails = (query: { monthCode: string; projectId: string | number }): AxiosPromise<PreAllocDetailVO> => {
  return request({
    url: '/oa/erp/timesheetPreAlloc/getAllocDetails',
    method: 'get',
    params: query
  });
};

/**
 * 查询当前部门指定月份已填报工时的来源预投项目
 */
export const listAvailableSourceProjects = (query: { monthCode: string }): AxiosPromise<any[]> => {
  return request({
    url: '/oa/erp/timesheetPreAlloc/listAvailableSourceProjects',
    method: 'get',
    params: query
  });
};

/**
 * 新增预投工时分配
 * @param data
 */
export const addTimesheetPreAlloc = (data: TimesheetPreAllocForm) => {
  return request({
    url: '/oa/erp/timesheetPreAlloc',
    method: 'post',
    data: data
  });
};

/**
 * 修改预投工时分配
 * @param data
 */
export const updateTimesheetPreAlloc = (data: TimesheetPreAllocForm) => {
  return request({
    url: '/oa/erp/timesheetPreAlloc',
    method: 'put',
    data: data
  });
};

/**
 * 删除预投工时分配
 * @param allocId
 */
export const delTimesheetPreAlloc = (allocId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/erp/timesheetPreAlloc/' + allocId,
    method: 'delete'
  });
};

/**
 * 下拉框查询预投工时分配列表
 * @param query
 * @returns {*}
 */
export function getErpTimesheetPreAllocList(query) {
  return request({
    url: '/oa/erp/timesheetPreAlloc/getErpTimesheetPreAllocList',
    method: 'get',
    params: query
  });
}
