<?php
declare(strict_types=1);
namespace App\Services\Pipeline\Steps;
use App\Services\Pipeline\AbstractPipelineStep; use App\Services\UpdatePreflightService;
final class NativePreflightStep extends AbstractPipelineStep {
 public function code():string{return 'native_preflight';} public function label():string{return 'Préflight natif';} public function order():int{return 10;}
 public function execute(array $c):array {
  $r=(new UpdatePreflightService())->run((string)$c['zip_path'],(array)$c['manifest'],(string)$c['installed_version']); $issues=[];$warnings=[];
  foreach((array)($r['checks']??[]) as $x){if(!($x['ok']??false)){ $m=(string)($x['name']??'Contrôle').' : '.(string)($x['message']??''); if($x['critical']??false)$issues[]=$m;else$warnings[]=$m;}}
  $checks=(array)($r['checks']??[]); $score=(int)round(count(array_filter($checks,static fn(array $x):bool=>(bool)($x['ok']??false)))/max(1,count($checks))*100);
  return $this->result(($r['ok']??false)?($warnings?'WARNING':'PASSED'):'BLOCKED',$score,($r['ok']??false)?'Préflight natif terminé.':'Le préflight natif bloque le package.',$issues,$warnings,['checks'=>$checks],!($r['ok']??false));
 }
}
