<?php

declare(strict_types=1);

$fixture = file_get_contents(__DIR__ . '/gift_detail_fixture.php');
$http = file_get_contents(__DIR__ . '/gift_detail_http.php');
if (!is_string($fixture) || !is_string($http)) {
    throw new RuntimeException('Gift detail source unavailable');
}
$checks = 0;
$once = static function (string $source, string $needle) use (&$checks): void {
    $checks++;
    if (substr_count($source, $needle) !== 1) {
        throw new RuntimeException('Gift detail guard fragment absent/duplicate');
    }
};
$once($fixture, <<<'PHP'
$describeColumn = $dialect === 'dm' ? '"DESCRIBE"' : '`describe`';
PHP
);
$once($fixture, <<<'PHP'
$dateBind = $dialect === 'dm' ? $dateBusiness : $mysqlEpoch;
PHP
);
$once($fixture, <<<'PHP'
if ($mysqlEpoch !== 1789444800) throw new RuntimeException('Fixed Asia/Shanghai epoch drift');
PHP
);
$once($fixture, ' VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,10001,?)');
$checks++;
if (substr_count($fixture,
    ' WHERE LOG_ID=? AND USER_ID=? AND IDEMPOTENCY_KEY=? AND STORE_ID=10001') !== 2) {
    throw new RuntimeException('Detail SELECT/DELETE must both bind exact owner and key');
}
$checks++;
if (strpos($http, '/api/gift.Log/detail?') === false) {
    throw new RuntimeException('Detail HTTP path absent');
}
$checks++;
if (strpos($http, "'/api/gift.Log/list'") !== false) {
    throw new RuntimeException('Detail-only harness must not call gift list');
}
$checks++;
if (strpos($http, "'follow_location' => 0") === false) {
    throw new RuntimeException('Detail HTTP redirect guard absent');
}
echo 'GiftDetailSqlFragmentTest pass assertions=' . $checks . PHP_EOL;
