<?php
// Required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

// Include required files
include_once '../config/database.php';
include_once '../objects/investor.php'; // Include the investor class instead of investorType

// Create a database connection
$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"));

// Set the ID for deletion
$investor->id = $data->id;

// Attempt to delete the investor
if ($investor->delete()) {
    echo json_encode(array("message" => "deleted")); // Return a success message in JSON format
} else {
    echo json_encode(array("message" => "error")); // Return an error message in JSON format
}
?>
