<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Services\LicenseService;

class LicenseController extends Controller
{
    public function __construct(private LicenseService $license) {}

    public function index()
    {
        $status = $this->license->status();
        return view('admin.license.index', compact('status'));
    }

    public function refresh()
    {
        $this->license->clearCache();
        $valid = $this->license->isValid();

        return back()->with(
            $valid ? 'success' : 'error',
            $valid ? 'License verified successfully.' : 'License validation failed. Domain not authorized.'
        );
    }
}
