<?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\Trust\TrustEngineService;
use Throwable;
final class PackageTrustController extends Controller
{
    public function index():void{Auth::requireLogin();Permission::require('updates.trust.view');$dashboard=(new TrustEngineService())->dashboard();$this->view('platform/package_trust_center',['pageTitle'=>'Package Trust Engine','trustReports'=>(array)($dashboard['reports']??[]),'trustGeneratedAt'=>(string)($dashboard['generated_at']??'')]);}
    public function evaluate():void{Auth::requireLogin();Permission::require('updates.trust.evaluate');Permission::requireSuperAdmin();Auth::requireRecentAuthentication();Csrf::verify($_POST['_csrf']??null);try{$r=(new TrustEngineService())->evaluatePackageId((int)($_POST['package_id']??0),(int)(Auth::user()['id']??0)?:null);$_SESSION[$r['decision']==='REJECTED'?'error':'success']='Trust Engine : '.$r['decision'].' — '.$r['score'].'/100.';}catch(Throwable $e){$_SESSION['error']='Évaluation impossible : '.$e->getMessage();}$this->redirect('/administration/plateforme/confiance-packages');}
}
