import apiClient from './index';
import type { UserAccount } from './types';

export const getAvailableGridWorkers = (): Promise<UserAccount[]> => {
  // 根据TaskAssignmentController的路径应为/tasks/grid-workers
  return apiClient.get<UserAccount[]>('/tasks/grid-workers')
    .catch((error: any) => {
      console.error('获取可用网格员API错误:', error);
      // 如果API调用失败，返回空数组而不是模拟数据
      return [];
    });
};

export const assignTask = (feedbackId: number, assigneeId: number): Promise<any> => {
    return apiClient.post('/tasks/assign', { feedbackId, assigneeId });
};

/**
 * Approves a submitted task.
 * @param taskId The ID of the task to approve.
 * @returns A promise that resolves with the updated task details.
 */
export const approveTask = (taskId: number): Promise<any> => {
    return apiClient.post(`/management/tasks/${taskId}/approve`);
};

/**
 * Rejects a submitted task.
 * @param taskId The ID of the task to reject.
 * @param reason The reason for rejection.
 * @returns A promise that resolves with the updated task details.
 */
export const rejectTask = (taskId: number, reason: string): Promise<any> => {
    return apiClient.post(`/management/tasks/${taskId}/reject`, { reason });
}; 
