<?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\Models\EnrollmentRenewal;
final class FamilyEnrollmentRenewalController extends Controller
{
 public function index():void{Auth::requireLogin();$this->view('family_enrollments/renewal',['pageTitle'=>'Réinscription annuelle','renewal'=>EnrollmentRenewal::context($this->org(),$this->client())]);}
 public function store():void{Auth::requireLogin();Csrf::verify($_POST['_csrf']??null);try{$r=EnrollmentRenewal::submit($this->org(),$this->client(),(array)($_POST['inscriptions']??[]),trim((string)($_POST['disponibilites']??'')),trim((string)($_POST['commentaire']??''))?:null,(int)Auth::id());$_SESSION['success']=$r['created'].' demande(s) de réinscription créée(s) pour '.$r['year'].($r['skipped']?' — '.$r['skipped'].' élément(s) ignoré(s).':'');$this->redirect('/mon-espace/inscriptions');}catch(\Throwable $e){$_SESSION['error']=$e->getMessage();$this->redirect('/mon-espace/inscriptions/reinscription');}}
 private function client():int{if(!Permission::isFamilyPortalIdentity())$this->deny();$id=(int)(Permission::familyPortalClientId()??0);if($id<1)$this->deny();return $id;}
 private function org():int{return (int)(Auth::user()['organisation_id']??1);}private function deny():never{http_response_code(403);exit('Accès refusé.');}
}
