<?php
// Savit API: Fetch projects for selection in Research module
// Adapted from api-fetch-user-projects.php

header('Content-Type: application/json');

use CAE\Lib\Database;

try {
    $db = Database::getInstance();
    $projects = $db->fetchAll("SELECT id, business_name, website_url, created_at FROM projects ORDER BY business_name ASC");

    echo json_encode([
        'success' => true,
        'projects' => $projects
    ]);

} catch (Exception $e) {
    echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
