// src/routes/api/crop-progress/list/+server.ts
import { type RequestHandler } from '@sveltejs/kit';
import { processInfo } from '$lib/server/processes';

export const GET: RequestHandler = () => {
    const list = Array.from(processInfo.values()).map((info) => ({
        id: info.id,
        status: info.status,
        progress: info.progress,
        started: new Date(info.startTime).toISOString(),
        message: info.message ?? null
    }));

    return new Response(JSON.stringify({ count: list.length, items: list }), {
        headers: { 'Content-Type': 'application/json' }
    });
};
