<?php

declare(strict_types=1);

return [
    'app' => [
        'name' => $_ENV['APP_NAME'] ?? 'ServerManager',
        'env' => $_ENV['APP_ENV'] ?? 'production',
        'debug' => filter_var($_ENV['APP_DEBUG'] ?? false, FILTER_VALIDATE_BOOLEAN),
        'url' => $_ENV['APP_URL'] ?? 'http://localhost',
        'timezone' => $_ENV['APP_TIMEZONE'] ?? 'America/Santo_Domingo',
    ],

    'database' => [
        'host' => $_ENV['DB_HOST'] ?? '127.0.0.1',
        'port' => (int) ($_ENV['DB_PORT'] ?? 3306),
        'database' => $_ENV['DB_DATABASE'] ?? 'servermanager',
        'username' => $_ENV['DB_USERNAME'] ?? 'root',
        'password' => $_ENV['DB_PASSWORD'] ?? '',
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
    ],

    'session' => [
        'lifetime' => (int) ($_ENV['SESSION_LIFETIME'] ?? 1440),
        'secure' => filter_var($_ENV['SESSION_SECURE'] ?? true, FILTER_VALIDATE_BOOLEAN),
        'http_only' => filter_var($_ENV['SESSION_HTTP_ONLY'] ?? true, FILTER_VALIDATE_BOOLEAN),
        'same_site' => $_ENV['SESSION_SAME_SITE'] ?? 'Lax',
    ],

    'csrf' => [
        'token_length' => (int) ($_ENV['CSRF_TOKEN_LENGTH'] ?? 64),
        'token_expiry' => (int) ($_ENV['CSRF_TOKEN_EXPIRY'] ?? 7200),
    ],

    'rate_limit' => [
        'max_attempts' => (int) ($_ENV['RATE_LIMIT_MAX_ATTEMPTS'] ?? 5),
        'decay_minutes' => (int) ($_ENV['RATE_LIMIT_DECAY_MINUTES'] ?? 15),
    ],

    'encryption' => [
        'method' => 'aes-256-cbc',
        'master_key' => $_ENV['MASTER_ENCRYPTION_KEY'] ?? null,
        'master_key_file' => $_ENV['MASTER_ENCRYPTION_KEY_FILE'] ?? null,
    ],

    'ssh' => [
        'timeout' => (int) ($_ENV['SSH_TIMEOUT'] ?? 30),
        'keepalive_interval' => (int) ($_ENV['SSH_KEEPALIVE_INTERVAL'] ?? 10),
        'command_timeout' => (int) ($_ENV['SSH_COMMAND_TIMEOUT'] ?? 60),
    ],

    'monitoring' => [
        'interval' => (int) ($_ENV['MONITORING_INTERVAL'] ?? 30),
        'retention_days' => (int) ($_ENV['MONITORING_RETENTION_DAYS'] ?? 30),
    ],

    'api' => [
        'rate_limit' => (int) ($_ENV['API_RATE_LIMIT'] ?? 60),
        'rate_limit_window' => (int) ($_ENV['API_RATE_LIMIT_WINDOW'] ?? 60),
    ],

    'log' => [
        'path' => $_ENV['LOG_PATH'] ?? __DIR__ . '/../logs/',
        'level' => $_ENV['LOG_LEVEL'] ?? 'warning',
    ],
];
