<?php
namespace Tshen;

session_start();

spl_autoload_register(function ($class) {
    $prefix = 'Tshen\\';
    $base_dir = __DIR__ . '/';
    $len = strlen($prefix);
    if (strncmp($prefix, $class, $len) !== 0) {
        return;
    }
    $relative_class = substr($class, $len);
    $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
    if (file_exists($file)) {
        require $file;
    }
});

require __DIR__ . '/helpers.php';

Config::load([
    'db_path' => __DIR__ . '/../storage/tshen.sqlite',
    'app_name' => 'TSHEN',
]);

Database::init(Config::get('db_path'));
// Run migrations automatically (create missing tables, uploads dir). This is safe and idempotent.
// The migrations file is silent when included in web requests.
require __DIR__ . '/../scripts/migrate.php';