import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ManagementVO, ManagementForm, ManagementQuery, ProjectMemberVO, ProjectMemberQuery, UserNotInProjectQuery, UserVO, InviteMemberForm } from '@/api/project/management/types';

/**
 * 查询项目管理列表
 * @param query
 * @returns {*}
 */

export const listManagement = (query?: ManagementQuery): AxiosPromise<ManagementVO[]> => {
  return request({
    url: '/project/management/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询项目管理详细
 * @param id
 */
export const getManagement = (id: string | number): AxiosPromise<ManagementVO> => {
  return request({
    url: '/project/management/' + id,
    method: 'get'
  });
};

/**
 * 新增项目管理
 * @param data
 */
export const addManagement = (data: ManagementForm) => {
  return request({
    url: '/project/management',
    method: 'post',
    data: data
  });
};

/**
 * 修改项目管理
 * @param data
 */
export const updateManagement = (data: ManagementForm) => {
  return request({
    url: '/project/management',
    method: 'put',
    data: data
  });
};

/**
 * 删除项目管理
 * @param id
 */
export const delManagement = (id: string | number | Array<string | number>) => {
  return request({
    url: '/project/management/' + id,
    method: 'delete'
  });
};

/**
 * 更新项目状态
 * @param id 项目ID
 * @param status 状态值
 */
export const updateStatus = (id: string | number, status: number) => {
  return request({
    url: '/project/management/updateStatus',
    method: 'put',
    data: { id, status }
  });
};

/**
 * 查询项目成员列表
 * @param query
 * @returns {*}
 */
export const queryProjectMember = (query: ProjectMemberQuery): AxiosPromise<ProjectMemberVO[]> => {
  return request({
    url: '/project/management/queryProjectMember',
    method: 'get',
    params: query
  });
};

/**
 * 查询未加入项目的用户列表
 * @param query
 * @returns {*}
 */
export const listOnNameNotJoinProject = (query: UserNotInProjectQuery): AxiosPromise<UserVO[]> => {
  return request({
    url: '/system/user/listOnNameNotJoinProject',
    method: 'get',
    params: query
  });
};

/**
 * 邀请成员加入项目
 * @param data
 */
export const inviteProjectMember = (data: InviteMemberForm) => {
  return request({
    url: '/project/management/queryProjectMemberInviteMember',
    method: 'post',
    data: data
  });
};

/**
 * 移除项目成员
 * @param projectId 项目ID
 * @param userId 用户ID
 */
export const removeProjectMember = (projectId: string | number, userId: string | number) => {
  return request({
    url: '/project/management/queryProjectMemberRemove',
    method: 'delete',
    params: { projectId, userId }
  });
};
