#!/usr/bin/env php
<?php

declare(strict_types=1);

// Find autoloader
$autoloadPaths = [
    __DIR__ . '/../vendor/autoload.php',
    __DIR__ . '/../../../autoload.php',
    __DIR__ . '/../../../../autoload.php',
];

$autoloaderFound = false;
foreach ($autoloadPaths as $autoloadPath) {
    if (file_exists($autoloadPath)) {
        require_once $autoloadPath;
        $autoloaderFound = true;
        break;
    }
}

if (!$autoloaderFound) {
    fwrite(STDERR, "Error: Could not find Composer autoloader.\n");
    fwrite(STDERR, "Please run 'composer install' first.\n");
    exit(1);
}

use NeuronAI\Console\NeuronCli;

try {
    $command = new NeuronCli();
    $exitCode = $command->run($argv);
    exit($exitCode);
} catch (Throwable $e) {
    fwrite(STDERR, "Fatal Error: " . $e->getMessage() . "\n");
    exit(1);
}
