import request from '@/utils/http'
import type { 
  WorkGroup, 
  WorkTypeGroup, 
  WorkGroupPageQuery, 
  CreateWorkGroupReq, 
  UpdateWorkGroupReq,
  AssignWorkerReq,
  RemoveWorkerReq,
  PageRes
} from './type'

/**
 * 获取工作组列表
 */
export function getWorkGroupList(params: WorkGroupPageQuery) {
  return request.get<PageRes<WorkGroup>>('/api/work-groups', params)
}

/**
 * 根据项目ID获取工作组列表
 */
export function getWorkGroupsByProject(projectId: string) {
  return request.get<WorkGroup[]>(`/api/projects/${projectId}/work-groups`)
}

/**
 * 获取工作组详情
 */
export function getWorkGroupDetail(id: string) {
  return request.get<WorkGroup>(`/api/work-groups/${id}`)
}

/**
 * 创建工作组
 */
export function createWorkGroup(data: CreateWorkGroupReq) {
  return request.post<WorkGroup>('/api/work-groups', data)
}

/**
 * 更新工作组
 */
export function updateWorkGroup(id: string, data: UpdateWorkGroupReq) {
  return request.put<WorkGroup>(`/api/work-groups/${id}`, data)
}

/**
 * 删除工作组
 */
export function deleteWorkGroup(id: string) {
  return request.del(`/api/work-groups/${id}`)
}

/**
 * 分配工人到工作组
 */
export function assignWorkerToGroup(data: AssignWorkerReq) {
  return request.post('/api/work-groups/assign-worker', data)
}

/**
 * 从工作组移除工人
 */
export function removeWorkerFromGroup(data: RemoveWorkerReq) {
  return request.post('/api/work-groups/remove-worker', data)
}

/**
 * 更新工作组状态
 */
export function updateWorkGroupStatus(id: string, status: string) {
  return request.patch<WorkGroup>(`/api/work-groups/${id}/status`, { status })
}

/**
 * 获取工作组统计信息
 */
export function getWorkGroupStats(projectId?: string) {
  return request.get('/api/work-groups/stats', { projectId })
}
