<?php
declare(strict_types=1);

error_reporting(E_ALL);
ini_set('display_errors', '0');
ini_set('log_errors', '1');

require_once __DIR__ . '/helpers.php';

$configFile = __DIR__ . '/config.php';
if (!is_file($configFile)) {
    if (PHP_SAPI !== 'cli') {
        http_response_code(503);
        echo '<!doctype html><html lang="fa" dir="rtl"><head><meta charset="utf-8"><title>نصب نشده</title></head><body style="font-family:tahoma;background:#07111f;color:white;padding:35px;line-height:2"><h2>پروژه هنوز نصب نشده است</h2><p>اول نصب‌کننده گرافیکی را کامل کن.</p><a style="color:#7dd3fc" href="install.php">ورود به install.php</a></body></html>';
    } else {
        fwrite(STDERR, "app/config.php not found. Run public/install.php first.\n");
    }
    exit;
}

$config = require $configFile;
date_default_timezone_set($config['timezone'] ?? 'Asia/Tehran');

require_once __DIR__ . '/Db.php';
require_once __DIR__ . '/Security.php';
require_once __DIR__ . '/Telegram.php';
require_once __DIR__ . '/Repository.php';
require_once __DIR__ . '/Auth.php';
require_once __DIR__ . '/ChildDatabaseManager.php';
require_once __DIR__ . '/BotService.php';

$db = Db::make($config['db']);
$security = new Security((string)$config['app_key']);
$repo = new Repository($db);
