<?php
namespace Peak;

class WorkflowManager {
    public static function handleRequest(string $method, ?string $id): void {
        Auth::requireAuth();
        if ($method === 'GET') {
            Response::json(Database::fetchAll('SELECT id, name, status FROM workflows ORDER BY name'));
        }
        if ($method === 'POST') {
            $data = Request::json();
            $id2 = Database::insert('INSERT INTO workflows (name, status) VALUES (?, ?)', [$data['name'], $data['status'] ?? 'active']);
            Response::json(['id' => (int)$id2, 'success' => true]);
        }
        if ($method === 'DELETE' && $id) {
            Database::query('DELETE FROM workflows WHERE id = ?', [$id]);
            Response::json(['success' => true]);
        }
        Response::error('Not found', 404);
    }
}
