<?php
namespace App\Models;
use App\Core\Database;
final class DisciplineIcon {
 public static function allActive(): array { return Database::connection()->query("SELECT * FROM discipline_icons WHERE actif=1 AND deleted_at IS NULL ORDER BY categorie,ordre_affichage,libelle")->fetchAll(); }
 public static function grouped(): array { $g=[]; foreach(self::allActive() as $i){$g[$i['categorie']][]=$i;} return $g; }
 public static function create(array $d): int { $s=Database::connection()->prepare("INSERT INTO discipline_icons(organisation_id,code,libelle,categorie,type_icone,valeur_icone,couleur_defaut,actif,ordre_affichage) VALUES(:organisation_id,:code,:libelle,:categorie,:type_icone,:valeur_icone,:couleur_defaut,1,:ordre_affichage)"); $s->execute($d); return (int)Database::connection()->lastInsertId(); }
 public static function archive(int $id): void { Database::connection()->prepare("UPDATE discipline_icons SET actif=0,deleted_at=CURRENT_TIMESTAMP WHERE id=:id")->execute(['id'=>$id]); }
 public static function assign(int $disciplineId,?int $iconId,?string $color): void { Database::connection()->prepare("UPDATE disciplines SET icon_id=:icon_id,couleur_accent=:couleur WHERE id=:id")->execute(['icon_id'=>$iconId ?: null,'couleur'=>$color ?: null,'id'=>$disciplineId]); }
}
