<?php

namespace think;

define('TP_ENV', 'poc');
define('BUSINESS', 'aizhct');
define('ENTERPRISE_NO', $_SERVER['HTTP_ENTERPRISE_NO'] ?? '10001');
require __DIR__ . '/../vendor/autoload.php';
// The packaged Composer autoload paths may point at the parent POC checkout.
// Prepend only current private application/cores source, without stubbing classes.
spl_autoload_register(static function (string $class): void {
    foreach (['app\\' => 'app/', 'cores\\' => 'cores/'] as $prefix => $directory) {
        if (strpos($class, $prefix) !== 0) continue;
        $file = dirname(__DIR__) . '/' . $directory
            . str_replace('\\', '/', substr($class, strlen($prefix))) . '.php';
        if (is_file($file)) require_once $file;
        return;
    }
}, true, true);
if (getenv('POC_EXTERNAL_STUBS') === '1') require __DIR__ . '/../external_stubs.php';
if (($_SERVER['REQUEST_URI'] ?? '') === '/__poc_boundary') {
    header('Content-Type: application/json');
    echo json_encode(['external_stubs' => getenv('POC_EXTERNAL_STUBS') === '1'
        && class_exists(\app\common\Serve::class, false)
        && class_exists(\app\common\UserApi::class, false),
        'host_map' => 'prepay.code-scan.invalid',
        'host_map_refund' => 'prepay.refund10001.invalid',
        'source' => 'current private AI app']);
    return;
}
$app = (new App(dirname(__DIR__)))->setEnvName('poc');
$app->initialize();
$app->env->set('store.host', [
    'prepay.code-scan.invalid' => 2147001111,
    'prepay.refund10001.invalid' => 10001,
]);
$app->env->set('redis.hostname', '');
$http = $app->http;
$response = $http->run();
$response->send();
$http->end($response);
