<?php

declare(strict_types=1);

require dirname(__DIR__) . '/app/bootstrap.php';

$config = require APP_PATH . '/config.php';
$console = new \App\Services\License\OfflineLicenseConsole($config);
$console->generateKeypair(false);
$result = $console->issue([
    'action' => 'issue',
    'license_id' => 'LIC-DEMO-' . date('YmdHis'),
    'customer' => 'Demo Customer',
    'product' => 'Store ERP',
    'issued_at' => date(DATE_ATOM),
    'expires_at' => date(DATE_ATOM, strtotime('+1 year')),
    'fingerprint' => \App\Services\License\ServerFingerprint::value($config),
    'status' => 'active',
    'features' => [
        'sales' => true,
        'inventory' => true,
        'reports' => true,
        'pos' => true,
    ],
    'notes' => 'Auto-generated demo offline license',
]);
copy($result['file_path'], APP_BASE_PATH . '/storage/license/license.json');
echo json_encode([
    'message' => 'Demo offline license generated and copied to storage/license/license.json',
    'file' => $result['file_path'],
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL;
