// Task service for fetching task status import type { User } from 'oidc-client-ts'; import type { TaskStatusResponse } from '@/types'; import { apiRequest } from './apiClient'; import { API_ENDPOINTS } from '@/constants'; export interface CancelTaskResponse { success: boolean; message: string; } export interface ClearAllTasksResponse { success: boolean; count: number; message: string; } /** * Fetch all active tasks for the current user */ export async function fetchTasksForUser(user: User): Promise { return apiRequest(user, API_ENDPOINTS.TASKS_FOR_USER); } /** * Fetch the status of a specific task */ export async function fetchTaskStatus( user: User, taskId: string ): Promise { return apiRequest(user, API_ENDPOINTS.TASK_STATUS, { params: { task_id: taskId }, }); } /** * Cancel a running task */ export async function cancelTask( user: User, taskId: string ): Promise { return apiRequest(user, API_ENDPOINTS.CANCEL_TASK, { method: 'POST', params: { task_id: taskId }, }); } /** * Clear all tasks for the current user */ export async function clearAllTasks(user: User): Promise { return apiRequest(user, API_ENDPOINTS.CLEAR_ALL_TASKS, { method: 'POST', }); }