<?php

require_once dirname(__DIR__) . '/app_runtime.php';
require_once dirname(__DIR__) . '/app_access.php';
require_once dirname(__DIR__) . '/db_bootstrap.php';

$GLOBALS['UA_INSTALL_CONFIG_OVERRIDE'] = [
  'install_type'=>'branch',
  'server_url'=>'http://main.example/mikrotik',
  'database'=>['host'=>'', 'port'=>3306, 'name'=>'', 'user'=>'', 'pass'=>'', 'charset'=>'utf8mb4'],
  'link'=>[
    'status'=>'approved', 'instance_id'=>'branch_runtime_test',
    'secret'=>'test-secret', 'server_url'=>'http://main.example/mikrotik',
  ],
];
unset($GLOBALS['conn']);

$db = ensure_db(false);
$result = [
  'ok'=>true,
  'install_type'=>ua_install_type(),
  'home_page'=>ua_install_home_page(),
  'dashboard_allowed'=>ua_install_page_allowed('dashboard.php'),
  'all_admin_pages_allowed'=>ua_install_page_allowed('users_permissions.php'),
  'local_database_fallback_blocked'=>!($db instanceof mysqli),
];

if ($result['install_type'] !== 'branch'
    || $result['home_page'] !== 'dashboard.php'
    || !$result['dashboard_allowed']
    || !$result['all_admin_pages_allowed']
    || !$result['local_database_fallback_blocked']) {
  fwrite(STDERR, json_encode($result, JSON_UNESCAPED_UNICODE) . PHP_EOL);
  exit(1);
}

echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . PHP_EOL;

