<?php
/**
 * Compatibility bootstrap for the standalone EasyChat core bundled as an
 * internal WordPress.org library.
 *
 * The shared core still expects legacy constants from the standalone runtime.
 * Keeping those constants in this internal adapter file makes the public
 * plugin entry point small and easier for WordPress.org tooling to review.
 */

if (!defined('ABSPATH')) {
    exit;
}

function easychat_wporg_bootstrap_defines() {
    if (!defined('DS')) {
        define('DS', DIRECTORY_SEPARATOR);
    }
    if (!defined('EASYCHAT_WPORG_MODE')) {
        define('EASYCHAT_WPORG_MODE', true);
    }

    $runtime = easychat_wporg_runtime_dir();

    if (!defined('SITE_PATH')) {
        define('SITE_PATH', EASYCHAT_WPORG_CORE_DIR);
    }
    if (!defined('DIR_LIBRARY')) {
        define('DIR_LIBRARY', EASYCHAT_WPORG_CORE_DIR . DS . 'library');
    }
    if (!defined('DIR_LOGS')) {
        define('DIR_LOGS', $runtime . DS . 'log');
    }
    if (!defined('EASYCHAT_AUTOLOAD_CACHE_DIR')) {
        define('EASYCHAT_AUTOLOAD_CACHE_DIR', $runtime . DS . 'log');
    }
    if (!defined('DIR_IMAGE')) {
        define('DIR_IMAGE', $runtime . DS . 'uploads' . DS);
    }
    if (!defined('DIR_AVATARS')) {
        define('DIR_AVATARS', $runtime . DS . 'avatars' . DS);
    }
    if (!defined('HTTP_SERVER')) {
        define('HTTP_SERVER', easychat_wporg_core_base_url());
    }
    if (!defined('HTTP_AVATARS')) {
        define('HTTP_AVATARS', easychat_wporg_public_rest_query_base('attachment/avatar') . 'file=');
    }
    if (!defined('EASYCHAT_VERSION')) {
        define('EASYCHAT_VERSION', easychat_wporg_version());
    }
    if (!defined('VERSION')) {
        define('VERSION', EASYCHAT_VERSION);
    }
    if (!defined('DB_DRIVER')) {
        define('DB_DRIVER', 'mysqli');
    }
    if (!defined('DB_HOSTNAME')) {
        list($db_host, $db_port) = easychat_wporg_split_db_host();
        define('DB_HOSTNAME', $db_host);
        define('DB_PORT', $db_port);
    }
    if (!defined('DB_USERNAME')) {
        define('DB_USERNAME', DB_USER);
    }
    if (!defined('DB_DATABASE')) {
        define('DB_DATABASE', DB_NAME);
    }
    if (!defined('DB_PREFIX')) {
        define('DB_PREFIX', EASYCHAT_WPORG_DB_PREFIX);
    }
    if (!defined('VECTOR_STORAGE')) {
        define('VECTOR_STORAGE', EASYCHAT_WPORG_DB_PREFIX . 'vectors');
    }
    if (!defined('ADMIN_USERNAME')) {
        define('ADMIN_USERNAME', (string)get_option('easychat_wporg_admin_login', 'admin'));
    }
    if (!defined('ADMIN_PASSWORD')) {
        // WordPress server-side handoff не требует plaintext-пароля в wp_options.
        // Существующий manager уже хранит password_hash в таблице EasyChat.
        define('ADMIN_PASSWORD', '');
    }
}
