<?php
declare(strict_types=1);
// No database connection or business HTTP. Compile the real ThinkORM INSERT.
$lane = (string)($argv[1] ?? '');
if (!in_array($lane, ['B', 'C'], true)) exit(78);
$root = $lane === 'B'
    ? '/private/tmp/zhct-http-ai-macos.x2CCZX'
    : '/tmp/zhct-ai-http-20260929.3XDj3w';
require $root . '/vendor/autoload.php';
$actual = (new ReflectionClass(\app\common\database\DmBuilder::class))
    ->getFileName();
$sha = hash_file('sha256', (string)$actual);
if ($sha !== '9ece7684e98997d45183375b1d5baaca42e4aac788b1cf4d073a0ebf5752aa35') {
    throw new RuntimeException('Actual Composer builder source SHA drift');
}
$connection = new \app\common\database\Dm([]);
$builder = new \app\common\database\DmBuilder($connection);
$query = new \think\db\Query($connection);
$query->table('yoshop_delivery_rule')->strict(true)
    ->setFieldType(['delivery_id' => 'int', 'first' => 'int',
        'first_fee' => 'decimal'])
    ->data(['delivery_id' => 7, 'first' => 1, 'first_fee' => '5.50']);
$query->setOption('extra', '')->setOption('comment', '');
$sql = $builder->insert($query);
$quoted = strpos($sql, '"FIRST"') !== false;
$unquoted = preg_match('/(?<!")\bfirst\b(?!")/i', $sql) === 1;
echo json_encode(['lane' => $lane, 'actual_sha256' => $sha,
    'first_quoted' => $quoted, 'first_unquoted' => $unquoted,
    'business_http' => 0, 'database_queries' => 0,
    'compiled_sql_sha256' => hash('sha256', $sql)]), "\n";
exit($quoted && !$unquoted ? 0 : 3);
