/**
 * Service for generic Task API communication used by Tools.
 */

import { requestApi } from '../lib/api';

const API_BASE = '/tasks';

// [DEF:runTask:Function]
/* @PURPOSE: Start a new task for a given plugin.
   @PRE: pluginId and params must be provided.
   @POST: Returns a promise resolving to the task instance.
*/
/**
 * Start a new task for a given plugin.
 * @param {string} pluginId - The ID of the plugin to run.
 * @param {Object} params - Parameters for the plugin.
 * @returns {Promise<Object>} The created task instance.
 */
export async function runTask(pluginId, params) {
    return requestApi(API_BASE, 'POST', { plugin_id: pluginId, params });
}
// [/DEF:runTask:Function]

// [DEF:getTaskStatus:Function]
/* @PURPOSE: Fetch details for a specific task (to poll status or get result).
   @PRE: taskId must be provided.
   @POST: Returns a promise resolving to task details.
*/
/**
 * Fetch details for a specific task (to poll status or get result).
 * @param {string} taskId - The ID of the task.
 * @returns {Promise<Object>} Task details.
 */
export async function getTaskStatus(taskId) {
    return requestApi(`${API_BASE}/${taskId}`);
}
// [/DEF:getTaskStatus:Function]