<?php

namespace App\Console\Commands;

use App\Support\License\LicenseManager;
use Illuminate\Console\Command;

class VerifyLicense extends Command
{
    protected $signature = 'license:verify';

    protected $description = 'Verify license with the server (respects verification period; run via schedule or manually)';

    public function handle(): int
    {
        if (! LicenseManager::shouldRunVerification()) {
            $this->info('License verification skipped (within verification period).');
            return 0;
        }

        $manager = app(LicenseManager::class);
        $result = $manager->verifyAndStoreResult();

        if ($result['status']) {
            $this->info('License verified: ' . ($result['message'] ?? 'OK'));
            return 0;
        }

        $this->warn('License verification failed: ' . ($result['message'] ?? 'Unknown error'));
        return 1;
    }
}
