<?php

declare(strict_types=1);

require __DIR__ . '/../vendor/autoload.php';
$app = require __DIR__ . '/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();

use App\Features\Agent\Models\Agent;
use App\Features\Agent\Services\DisconnectProtectionService;

$agentId = $argv[1] ?? '019f100e-bdfd-712c-9e1c-2f6d37461ced';
$agent = Agent::find($agentId);

if (!$agent) {
    fwrite(STDERR, "Agent not found: {$agentId}\n");
    exit(1);
}

$secret = app(DisconnectProtectionService::class)->generateSecretDisconnect($agent);
$outFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'amg_disconnect_secret.txt';
file_put_contents($outFile, $secret);

echo $outFile;
