import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ManagementVO, ManagementForm, ManagementQuery, ProjectMemberVO, ProjectMemberQuery, UserNotInProjectQuery, UserVO, InviteMemberForm, CenterInfoVO, CenterInfoQuery, MemberNotInCenterVO, MemberNotInCenterQuery, InviteCenterMemberForm, CenterMemberVO, CenterMemberQuery, AddProjectMemberForm, AssignFoldersForm, GetFoldersResponse } 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 }
  });
};

/**
 * 查询中心信息列表
 * @param query
 * @returns {*}
 */
export const queryCenterInfo = (query: CenterInfoQuery): AxiosPromise<CenterInfoVO[]> => {
  return request({
    url: '/project/management/queryCenterInfo',
    method: 'get',
    params: query
  });
};

/**
 * 查询未加入中心的成员列表
 * @param query
 * @returns {*}
 */
export const queryMemberNotInCenter = (query: MemberNotInCenterQuery): AxiosPromise<MemberNotInCenterVO[]> => {
  return request({
    url: '/project/management/queryMemberNotInCenter',
    method: 'get',
    params: query
  });
};

/**
 * 邀请成员加入中心
 * @param data
 */
export const inviteCenterMember = (data: InviteCenterMemberForm) => {
  return request({
    url: '/project/management/queryCenterInfoInviteMember',
    method: 'post',
    data: data
  });
};

/**
 * 查询中心成员列表
 * @param query
 * @returns {*}
 */
export const queryCenterMember = (query: CenterMemberQuery): AxiosPromise<CenterMemberVO[]> => {
  return request({
    url: '/project/management/queryCenterMember',
    method: 'get',
    params: query
  });
};

/**
 * 添加项目成员
 * @param data
 */
export const addProjectMember = (data: AddProjectMemberForm) => {
  return request({
    url: '/project/management/queryProjectMemberAddMember',
    method: 'post',
    data: data
  });
};

/**
 * 获取用户文件夹权限
 * @param userId 用户ID
 * @param projectId 项目ID
 */
export const getFolders = (userId: string | number, projectId: string | number): AxiosPromise<GetFoldersResponse> => {
  return request({
    url: '/project/management/getFolders',
    method: 'get',
    params: { userId, projectId }
  });
};

/**
 * 分配文件夹权限
 * @param data
 */
export const assignFolders = (data: AssignFoldersForm) => {
  return request({
    url: '/project/management/queryProjectMemberAssignFolders',
    method: 'put',
    data: data
  });
};
