"""WSGI config for PEZAJOB project."""
import os
import sys

from django.core.wsgi import get_wsgi_application

# Ensure project root is on the path (legacy deployment compatibility)
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

application = get_wsgi_application()

# Serve static/media via WhiteNoise in production when not using a CDN
if os.getenv('DJANGO_WHITENOISE_WSGI_STATIC', '').lower() in ('1', 'true', 'yes'):
    try:
        from whitenoise import WhiteNoise

        base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        application = WhiteNoise(
            application,
            root=os.path.join(base_dir, 'staticfiles'),
            prefix='/static/',
        )
        application.add_files(
            os.path.join(base_dir, 'media'),
            prefix='/media/',
        )
    except ImportError:
        pass
