<?php
declare(strict_types=1);require __DIR__.'/common.php';
$runtime=$argv[1]??'';if(!preg_match('#^/tmp/cdx-catalog7-[BC]-[A-Za-z0-9]+/private-runtime$#D',$runtime)||is_link($runtime)){throw new RuntimeException('Private proof repair boundary');}putenv('SM7_RUNTIME='.$runtime);
$file=$runtime.'/spec-private.json';$backup=$runtime.'/spec-before-card-projection-private.json';if(is_file($backup)){throw new RuntimeException('One-time tool repair guard');}copy($file,$backup);chmod($backup,0600);$spec=json_decode(file_get_contents($file),false,512,JSON_THROW_ON_ERROR);$changes=0;
foreach($spec as $entry){if($entry->kind!=='card'){continue;}foreach($entry->before->body->data->data as $row){if(!isset($row->card_status)||!is_int($row->card_status)||$row->card_status<0||$row->card_status>255){throw new RuntimeException('Original source uint8 projection changed');}$row->card_status=(string)$row->card_status;$changes++;}}
smSave('spec-private.json',$spec);$report=$runtime.'/report-private.json';copy($report,$runtime.'/report-before-card-projection-private.json');chmod($runtime.'/report-before-card-projection-private.json',0600);
smSave('card-oracle-tool-repair-private.json',['expected_body_uint8_projection_fields_corrected'=>$changes,'source_values_or_source_sets_changed'=>false,'original_spec_sha256'=>hash_file('sha256',$backup),'corrected_spec_sha256'=>hash_file('sha256',$file),'reason'=>'MySQL actual IFNULL(unsigned tinyint,5) native NEWDECIMAL/PDO string proven independently; C integer must fail canonical MySQL contract','original_http_wire_changed'=>false,'business_http_replayed'=>0,'database_operations'=>0]);
echo json_encode(['expected_body_fields_corrected'=>$changes,'raw_wire_changed'=>false,'source_sets_changed'=>false,'database_http_operations'=>0]),PHP_EOL;
