<?php
declare(strict_types=1);

require_once dirname(__DIR__) . '/_app_guard.php';
app_guard_validate();
require_once dirname(__DIR__) . '/_auth_common.php';

try {
    $db = new PDO('sqlite:' . dirname(__DIR__) . '/db.db');
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    auth_ensure_schema($db);
    $cfg = auth_get_general_app_config($db);

    auth_json_out([
        'status' => 'ok',
        'ok' => true,
        'tmdb_api_key' => $cfg['tmdb_api_key'],
        'sports_api_url' => $cfg['sports_api_url'],
        'app_language' => $cfg['app_language'],
        'language_revision' => $cfg['language_revision'],
        'updated_at' => $cfg['general_config_updated_at'],
    ]);
} catch (Throwable $e) {
    auth_json_out([
        'status' => 'error',
        'ok' => false,
        'message' => 'general_config_unavailable',
    ]);
}
