<?php
require_once __DIR__ . '/../app/Core/bootstrap.php';
require_once __DIR__ . '/../app/Services/LegacyBotService.php';

$task = $argv[1] ?? '';
$service = new LegacyBotService();

try {
    switch ($task) {
        case 'export-all':
            $result = $service->runAllExports();
            echo $result['message'] . PHP_EOL;
            break;
        case 'unmapped':
            $result = $service->runUnmappedExport();
            echo $result['message'] . PHP_EOL;
            break;
        case 'smart-map-template':
            $result = $service->generateSmartMapTemplate();
            echo $result['message'] . PHP_EOL;
            break;
        case 'smart-review':
            $result = $service->generateSmartReview('cli');
            echo $result['message'] . PHP_EOL;
            break;
        case 'text-list':
            $result = $service->buildTextList();
            echo $result['message'] . PHP_EOL;
            break;
        default:
            echo "Usage: php scripts/run_task.php [export-all|unmapped|smart-map-template|smart-review|text-list]" . PHP_EOL;
            exit(1);
    }
} catch (Throwable $e) {
    fwrite(STDERR, 'ERROR: ' . $e->getMessage() . PHP_EOL);
    exit(2);
}
