<?php

namespace App\Core;

/**
 * System Info - معلومات النظام
 * لجلب معلومات النظام والإصدارات
 */
class SystemInfo
{
    /**
     * جلب معلومات النظام
     */
    public static function get(): array
    {
        return [
            'php_version' => PHP_VERSION,
            'php_sapi' => php_sapi_name(),
            'server_software' => $_SERVER['SERVER_SOFTWARE'] ?? 'Unknown',
            'os' => PHP_OS,
            'memory_limit' => ini_get('memory_limit'),
            'max_execution_time' => ini_get('max_execution_time'),
            'upload_max_filesize' => ini_get('upload_max_filesize'),
            'post_max_size' => ini_get('post_max_size'),
            'timezone' => date_default_timezone_get(),
            'extensions' => [
                'pdo' => extension_loaded('pdo'),
                'pdo_mysql' => extension_loaded('pdo_mysql'),
                'redis' => extension_loaded('redis'),
                'curl' => extension_loaded('curl'),
                'gd' => extension_loaded('gd'),
                'mbstring' => extension_loaded('mbstring'),
                'json' => extension_loaded('json'),
                'zip' => extension_loaded('zip')
            ]
        ];
    }

    /**
     * جلب معلومات التطبيق
     */
    public static function getAppInfo(): array
    {
        return [
            'app_name' => 'Smart Lab LIMS',
            'version' => '2.0.0',
            'build_date' => '2025-01-01',
            'environment' => defined('DEBUG_MODE') && DEBUG_MODE ? 'development' : 'production'
        ];
    }

    /**
     * جلب معلومات قاعدة البيانات
     */
    public static function getDbInfo(\PDO $db): array
    {
        try {
            $version = $db->query('SELECT VERSION()')->fetchColumn();
            $charset = $db->query('SELECT @@character_set_database')->fetchColumn();
            $collation = $db->query('SELECT @@collation_database')->fetchColumn();
            
            return [
                'version' => $version,
                'charset' => $charset,
                'collation' => $collation,
                'status' => 'connected'
            ];
        } catch (\Throwable $e) {
            return [
                'status' => 'error',
                'error' => $e->getMessage()
            ];
        }
    }
}
