<?php
declare(strict_types=1);
namespace App\Controllers;
use App\Core\Auth;
use App\Core\Controller;
use App\Core\Csrf;
use App\Core\Permission;
use App\Services\Compatibility\PackageCompatibilityService;
use Throwable;
final class PackageCompatibilityController extends Controller
{
    public function index():void{Auth::requireLogin();Permission::require('updates.compatibility.view');$dashboard=(new PackageCompatibilityService())->dashboard();$this->view('platform/package_compatibility_center',['pageTitle'=>'Compatibility Engine','compatibilityReports'=>(array)($dashboard['reports']??[]),'compatibilityGeneratedAt'=>(string)($dashboard['generated_at']??'')]);}
    public function evaluate():void{Auth::requireLogin();Permission::require('updates.compatibility.evaluate');Permission::requireSuperAdmin();Auth::requireRecentAuthentication();Csrf::verify($_POST['_csrf']??null);try{$r=(new PackageCompatibilityService())->evaluatePackageId((int)($_POST['package_id']??0),(int)(Auth::user()['id']??0)?:null,true);$_SESSION[$r['decision']==='INCOMPATIBLE'?'error':'success']='Compatibility Engine : '.$r['decision'].' — '.$r['score'].'/100.';}catch(Throwable $e){$_SESSION['error']='Évaluation impossible : '.$e->getMessage();}$this->redirect('/administration/plateforme/compatibilite-packages');}
}
