import {
  BaseListResult,
  BaseResult,
  DepartmentListData,
  ExportDepartmentListParams,
  GetDepartmentListParams,
} from '@models';
import {request} from './request';

const BASE_URL = '/department';

/** 获取部门列表 */
export function getDepartmentList(
  params: GetDepartmentListParams,
): BaseListResult<DepartmentListData> {
  return request({
    method: 'GET',
    data: params,
    url: `${BASE_URL}/getDepartment`,
  });
}

export function getDepartmentInfo(
  id: string,
): BaseListResult<DepartmentListData> {
  return request({
    method: 'GET',
    data: {id, page: '1', limit: '1'},
    url: `${BASE_URL}/getDepartment`,
  });
}

/** 新增部门 */
export function addDepartment(name: string): BaseResult {
  return request({
    method: 'POST',
    data: {departmentName: name},
    url: `${BASE_URL}/addDepartment`,
  });
}

/** 删除部门 */
export function deleteDepartment(id: string): BaseResult {
  return request({
    method: 'DELETE',
    url: `${BASE_URL}/delDepartment`,
    data: {id},
  });
}

/** 修改部门 */
export function editDepartment({id, name}: {id: string, name: string}): BaseResult {
  return request({
    method: 'PUT',
    data: {departmentName: name, id},
    url: `${BASE_URL}/updateDepartment`,
  });
}

/** 导出部门信息 */
export function exportDepartment(params: ExportDepartmentListParams): any {
  return request({
    method: 'GET',
    data: params,
    url: `${BASE_URL}/export`,
    skipError: true,
  });
}

/** 获取所有部门 */
export function getAllDepartment(): BaseResult<DepartmentListData[]> {
  return request({
    method: 'GET',
    skipError: true,
    url: `${BASE_URL}/getDepartBefor`,
  });
}
