<?php

/**
 * MVC License Validation — daily phone-home cron command.
 *
 * USAGE:
 *     php artisan mvc:validate
 *
 * CRON SCHEDULE:
 *     0 4 * * * cd /var/www/pterodactyl && php artisan mvc:validate >> /dev/null 2>&1
 *
 * Calls Arbiter /api/mvc/validate to confirm license is still active.
 * On failure, enters 7-day grace period. After grace expires, marks expired.
 */

namespace Pterodactyl\Console\Commands;

use Illuminate\Console\Command;
use Pterodactyl\Services\LicenseService;

class ValidateLicense extends Command
{
    protected $signature = 'mvc:validate';
    protected $description = 'Validate ModpackChecker license (daily phone-home)';

    public function __construct(private LicenseService $licenseService)
    {
        parent::__construct();
    }

    public function handle(): int
    {
        $this->info('Validating ModpackChecker license...');

        $result = $this->licenseService->validate();

        match ($result['status']) {
            'active' => $this->info("✅ License active — tier: {$result['tier']}"),
            'grace' => $this->warn("⚠️ Grace period — expires: {$result['expires']}"),
            'expired' => $this->error("❌ License expired"),
            'inactive' => $this->line("No license configured"),
            default => $this->line("Status: {$result['status']}"),
        };

        return 0;
    }
}
