<?php
declare(strict_types=1);

$bool = static function (string $key, bool $default): bool {
    $value = getenv($key);

    if ($value === false || $value === '') {
        return $default;
    }

    return filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? $default;
};

return [
    'APP_NAME' => getenv('APP_NAME') ?: 'Zalorox',
    'APP_ENV' => getenv('APP_ENV') ?: 'local',
    'DEBUG_MODE' => $bool('DEBUG_MODE', true),
    'APP_DEBUG' => $bool('APP_DEBUG', $bool('DEBUG_MODE', true)),
    'FEATURE_TEST_MODE' => $bool('FEATURE_TEST_MODE', false),
    'SECURITY_BOT_TEST_MODE' => $bool('SECURITY_BOT_TEST_MODE', true),
    'FAKE_EMAIL_MODE' => $bool('FAKE_EMAIL_MODE', true),
    'SHOW_DEV_TOOLS' => $bool('SHOW_DEV_TOOLS', false),

    'APP_URL' => getenv('APP_URL') ?: 'http://localhost:8080',
    'MUSIC_URL' => getenv('MUSIC_URL') ?: 'http://localhost:8080/music',
    'STUDIO_URL' => getenv('STUDIO_URL') ?: 'http://localhost:8080/studyo',
    'ZPANEL_URL' => getenv('ZPANEL_URL') ?: 'http://localhost:8080/zpanel',

    'LOCAL_MODE' => $bool('LOCAL_MODE', true),
    'SUBDOMAIN_MODE' => $bool('SUBDOMAIN_MODE', false),
    'DEFAULT_LANGUAGE' => getenv('DEFAULT_LANGUAGE') ?: 'tr',

    'PAYMENT_PROVIDER' => getenv('PAYMENT_PROVIDER') ?: 'test',
    'PAYMENT_TEST_MODE' => $bool('PAYMENT_TEST_MODE', true),

    'MOD_MAX_COVER_MB' => (int) (getenv('MOD_MAX_COVER_MB') ?: 12),
    'MOD_MAX_GALLERY_ITEMS' => (int) (getenv('MOD_MAX_GALLERY_ITEMS') ?: 10),
    'MOD_GALLERY_MAX_MB' => (int) (getenv('MOD_GALLERY_MAX_MB') ?: 12),
    'MOD_COVER_UPLOAD_PATH' => getenv('MOD_COVER_UPLOAD_PATH') ?: '/public/uploads/covers/',
    'MOD_GALLERY_UPLOAD_PATH' => getenv('MOD_GALLERY_UPLOAD_PATH') ?: '/public/uploads/mod-gallery/',
    'MUSIC_ALLOWED_EXTENSIONS' => array_values(array_filter(array_map('trim', explode(',', getenv('MUSIC_ALLOWED_EXTENSIONS') ?: 'mp3,wav,ogg,m4a,flac')))),
    'MUSIC_MAX_UPLOAD_MB' => (int) (getenv('MUSIC_MAX_UPLOAD_MB') ?: 100),
    'MUSIC_UPLOAD_PATH' => getenv('MUSIC_UPLOAD_PATH') ?: '/public/uploads/music-files/',
    'MUSIC_COVER_UPLOAD_PATH' => getenv('MUSIC_COVER_UPLOAD_PATH') ?: '/public/uploads/music-covers/',
    'PROFILE_IMAGE_MAX_MB' => (int) (getenv('PROFILE_IMAGE_MAX_MB') ?: 12),
    'PROFILE_AVATAR_UPLOAD_PATH' => getenv('PROFILE_AVATAR_UPLOAD_PATH') ?: '/public/uploads/avatars/',
    'PROFILE_COVER_UPLOAD_PATH' => getenv('PROFILE_COVER_UPLOAD_PATH') ?: '/public/uploads/profile-covers/',
    'COMMUNITY_POST_MAX_CHARS' => (int) (getenv('COMMUNITY_POST_MAX_CHARS') ?: 1000),
    'COMMUNITY_IMAGE_MAX_MB' => (int) (getenv('COMMUNITY_IMAGE_MAX_MB') ?: 12),
    'COMMUNITY_IMAGE_UPLOAD_PATH' => getenv('COMMUNITY_IMAGE_UPLOAD_PATH') ?: '/public/uploads/community/',
    'STORY_IMAGE_MAX_MB' => (int) (getenv('STORY_IMAGE_MAX_MB') ?: 12),
    'STORY_IMAGE_UPLOAD_PATH' => getenv('STORY_IMAGE_UPLOAD_PATH') ?: '/public/uploads/stories/',
    'MODEL_ALLOWED_EXTENSIONS' => array_values(array_filter(array_map('trim', explode(',', getenv('MODEL_ALLOWED_EXTENSIONS') ?: 'glb,gltf,usdz')))),
    'MODEL_MAX_UPLOAD_MB' => (int) (getenv('MODEL_MAX_UPLOAD_MB') ?: 100),
    'MODEL_UPLOAD_PATH' => getenv('MODEL_UPLOAD_PATH') ?: '/public/uploads/models/',

    'db' => [
        'host' => getenv('DB_HOST') ?: '127.0.0.1',
        'port' => (int) (getenv('DB_PORT') ?: 3306),
        'name' => getenv('DB_NAME') ?: 'zalorox',
        'user' => getenv('DB_USER') ?: 'root',
        'pass' => getenv('DB_PASS') ?: '',
        'charset' => getenv('DB_CHARSET') ?: 'utf8mb4',
    ],

    'session' => [
        'name' => getenv('SESSION_NAME') ?: 'zalorox_session',
        'lifetime' => 0,
        'same_site' => 'Lax',
    ],

    'paths' => [
        'base' => dirname(__DIR__),
        'views' => dirname(__DIR__) . '/app/Views',
        'uploads' => dirname(__DIR__) . '/public/uploads',
        'logs' => dirname(__DIR__) . '/storage/logs',
    ],

    'supported_languages' => ['tr', 'en', 'de', 'fr'],
    'default_lang' => getenv('DEFAULT_LANGUAGE') ?: 'tr',
    'supported_langs' => ['tr', 'en', 'de', 'fr'],
    'session_name' => getenv('SESSION_NAME') ?: 'zalorox_session',
    'upload_path' => dirname(__DIR__) . '/public/uploads',
    'payout_delay_minutes' => 20,
    'trusted_domains' => [
        'drive.google.com',
        'docs.google.com',
        'sharemods.com',
        'mediafire.com',
        'dropbox.com',
        'onedrive.live.com',
        'mega.nz',
    ],
];
