#!/usr/bin/env php
<?php

use App\Support\TenantRuntimeBootstrap;
use Illuminate\Contracts\Console\Kernel;
use Symfony\Component\Console\Input\ArgvInput;

define('LARAVEL_START', microtime(true));

$runtimePath = __DIR__;

if (! is_file($runtimePath.'/release.php')) {
    fwrite(STDERR, "Tenant runtime release is missing or invalid.\n");
    exit(1);
}

$releasePath = require $runtimePath.'/release.php';

if (! is_string($releasePath) || ! is_file($releasePath.'/vendor/autoload.php') || ! is_file($releasePath.'/bootstrap/app.php')) {
    fwrite(STDERR, "Tenant runtime release is missing or invalid.\n");
    exit(1);
}

require $releasePath.'/vendor/autoload.php';

TenantRuntimeBootstrap::markEntrypoint(\App\Support\SwiftposEdition::CLOUD);
TenantRuntimeBootstrap::pin($runtimePath);

$app = require $releasePath.'/bootstrap/app.php';

if (in_array('runtime:describe', $_SERVER['argv'] ?? [], true)) {
    TenantRuntimeBootstrap::emitProbeAndExit($app, Kernel::class);
}

$status = $app->handleCommand(new ArgvInput);

exit($status);
