<?php
declare(strict_types=1);if(session_status()===PHP_SESSION_NONE)session_start();require_once __DIR__.'/db_bootstrap.php';require_once __DIR__.'/output_fleet_lib.php';header('Content-Type: application/json; charset=utf-8');$conn=$GLOBALS['conn']??ensure_db(true);$input=json_decode((string)file_get_contents('php://input'),true);if(!is_array($input))$input=[];if(function_exists('ua_csrf_verify')&&!ua_csrf_verify()){http_response_code(403);echo json_encode(['ok'=>false,'error'=>'INVALID_REQUEST']);exit;}$actor=ua_output_authorized_scope($conn,(string)($input['scope_key']??''));if(empty($actor['authorized'])){http_response_code(401);echo json_encode(['ok'=>false,'error'=>'AUTH_REQUIRED']);exit;}$command=(string)($input['command_key']??'contract_print');$result=ua_output_fleet_dispatch_file($conn,$command,(string)$actor['scope'],$input);if(empty($result['ok']))http_response_code((int)($result['status']??502));echo !empty($result['body'])?$result['body']:json_encode(['ok'=>(bool)($result['ok']??false),'error'=>$result['error']??'PRINT_FAILED'],JSON_UNESCAPED_UNICODE);
