<?php
// Required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

// Include database and object files
include_once '../config/database.php'; // Include the database connection
include_once '../objects/investor.php'; // Include the investor object

// Instantiate database
$database = new Database();
$db = $database->getConnection();

// Initialize investor object
$investor = new Investor($db);

// Get the incoming data
$data = json_decode(file_get_contents("php://input"));

// Check if ID is set
if (isset($data->id)) {
    // Set the investor ID to fetch
    $investor->id = $data->id;

    // Call the method to get investor details
    $investor->getOneRow();

    // Prepare the investor data array
    $investor_data = array(
        "id" => $investor->id,
        "name" => $investor->name, // Ensure these properties exist in your investor class
        "position" => $investor->position,
        "phone" => $investor->phone,
        "email" => $investor->email,
        "nrc" => $investor->nrc,
        "address" => $investor->address,
        // Add any additional fields you have for investors
    );

    // Return the investor data as JSON
    echo json_encode($investor_data);
} else {
    // Return error if ID is not provided
    echo json_encode(array("message" => "investor ID is missing."));
}
?>
