import type * as T from './type'
import http from '@/utils/http'

const BASE_URL = '/project/personnel-organization'

/** @desc 获取项目列表 */
export function getProjectList(query?: T.ProjectQuery) {
  return http.get<PageRes<T.ProjectResp[]>>('/project/list', query)
}

/** @desc 获取项目人员组织信息 */
export function getPersonnelOrganization(projectId: string | number) {
  return http.get<T.PersonnelOrganizationResp>(`${BASE_URL}/${projectId}`)
}

/** @desc 获取工种列表 */
export function getWorkTypeList() {
  return http.get<T.WorkTypeResp[]>('/work-type/list')
}

/** @desc 获取施工人员列表 */
export function getConstructorList(query: T.ConstructorQuery) {
  return http.get<PageRes<T.ConstructorResp[]>>('/constructor/list', query)
}

/** @desc 获取施工人员技能证书 */
export function getConstructorCertifications(constructorId: string | number) {
  return http.get<T.CertificationResp[]>(`/constructor/${constructorId}/certifications`)
}

/** @desc 分配施工人员到项目 */
export function assignConstructorToProject(data: T.AssignConstructorReq) {
  return http.post(`${BASE_URL}/assign`, data)
}

/** @desc 移除项目施工人员 */
export function removeConstructorFromProject(data: T.RemoveConstructorReq) {
  return http.delete(`${BASE_URL}/remove`, data)
}

/** @desc 更新施工人员分配信息 */
export function updateConstructorAssignment(data: T.UpdateAssignmentReq) {
  return http.put(`${BASE_URL}/update`, data)
}

/** @desc 获取项目人员统计 */
export function getPersonnelStats(projectId: string | number) {
  return http.get<T.PersonnelStatsResp>(`${BASE_URL}/${projectId}/stats`)
}

/** @desc 导出项目人员组织 */
export function exportPersonnelOrganization(projectId: string | number) {
  return http.download(`${BASE_URL}/${projectId}/export`)
}
