<?php
require_once 'WorkflowEngine.php';

session_start();

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

$response = ['success' => false, 'message' => 'Invalid request'];

$personId = $_GET['person_id'] ?? null;
$bniGroupId = $_GET['bni_group_id'] ?? null;
$meetingDatetime = $_GET['meeting_datetime'] ?? null;
$userId = $_SESSION['user_id'] ?? 0; // Ensure you have a user ID in the session

if ($personId && $bniGroupId && $meetingDatetime && $userId) {
    try {
        $workflowEngine = new WorkflowEngine();
        $details = $workflowEngine->getMeetingDetails((int)$personId, (int)$bniGroupId, $meetingDatetime);
        $response = ['success' => true, 'details' => $details];
    } catch (Exception $e) {
        $response['message'] = $e->getMessage();
    }
} else {
    $response['message'] = 'Missing required parameters.';
}

echo json_encode($response);
