<?php
// api/endpoints/system_status.php

// 1. Set required headers for a JSON API
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: GET");

// 2. Include the database configuration
include_once '../config/database.php';

// 3. Initialize the database connection
$database = new Database();
$db = $database->getConnection();

// 4. Return the response
if($db) {
    echo json_encode([
        "status" => "success",
        "message" => "RiMax Lab API Gateway is online.",
        "database" => "Connected successfully!",
        "timestamp" => date("Y-m-d H:i:s")
    ]);
} else {
    echo json_encode([
        "status" => "error",
        "message" => "API is online, but database connection failed."
    ]);
}
?>