import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ProjectRelevancyForm, ProjectRelevancyQuery, ProjectRelevancyVO } from '@/api/project/projectRelevancy/types';

/**
 * 查询系统用户与项目关联列表
 * @param query
 * @returns {*}
 */

export const listProjectRelevancy = (query?: ProjectRelevancyQuery): AxiosPromise<ProjectRelevancyVO[]> => {
  return request({
    url: '/project/projectRelevancy/login/page',
    method: 'get',
    params: query
  });
};

/**
 * 查询系统用户与项目关联详细
 * @param id
 */
export const getProjectRelevancy = (id: string | number): AxiosPromise<ProjectRelevancyVO> => {
  return request({
    url: '/project/projectRelevancy/' + id,
    method: 'get'
  });
};

/**
 * 新增系统用户与项目关联
 * @param data
 */
export const addProjectRelevancy = (data: ProjectRelevancyForm): AxiosPromise<string | number> => {
  return request({
    url: '/project/projectRelevancy',
    method: 'post',
    data: data
  });
};

/**
 * 修改系统用户与项目关联
 * @param data
 */
export const updateProjectRelevancy = (data: ProjectRelevancyForm) => {
  return request({
    url: '/project/projectRelevancy',
    method: 'put',
    data: data
  });
};

/**
 * 删除系统用户与项目关联
 * @param id
 */
export const delProjectRelevancy = (id: string | number | Array<string | number>) => {
  return request({
    url: '/project/projectRelevancy/' + id,
    method: 'delete'
  });
};

/**
 * 穿梭框接口
 */

/**
 * 获取用户已关联的项目列表
 * @param params { userId: number }
 */
export function listUserProjects(params: { userId: number | string }) {
  return request({
    url: '/project/projectRelevancy/list',
    method: 'get',
    params
  });
}

/**
 * 添加项目关联
 * @param data { userId: number; projectIds: number[] }
 */
export function addNewProjectRelevancy(data: { userId: number | string; projectIdList: number[] }) {
  return request({
    url: '/project/projectRelevancy/add/project/list',
    method: 'post',
    data
  });
}

/**
 * 移除项目关联
 * @param data { userId: number; projectIds: number[] }
 */
export function removeNewProjectRelevancy(data: { userId: number | string; projectIdList: number[] }) {
  return request({
    url: '/project/projectRelevancy/remove/project/list',
    method: 'delete',
    data
  });
}
