"""
Passenger WSGI entry point for GoDaddy cPanel shared hosting.

GoDaddy's Passenger looks for a callable named `application` in this file.
"""

import os
import site
import sys
from pathlib import Path

# Ensure user site-packages are on the path (pip3 install --user puts packages here).
USER_SITE = Path.home() / ".local" / "lib" / "python3.9" / "site-packages"
if USER_SITE.exists() and str(USER_SITE) not in sys.path:
    site.addsitedir(str(USER_SITE))

# Ensure the project root is importable.
PROJECT_ROOT = Path(__file__).resolve().parent
if str(PROJECT_ROOT) not in sys.path:
    sys.path.insert(0, str(PROJECT_ROOT))

# Load .env into os.environ so python-decouple picks it up.
_env_file = PROJECT_ROOT / ".env"
if _env_file.exists():
    for raw in _env_file.read_text().splitlines():
        line = raw.strip()
        if not line or line.startswith("#") or "=" not in line:
            continue
        key, _, value = line.partition("=")
        key = key.strip()
        value = value.strip().strip('"').strip("'")
        os.environ.setdefault(key, value)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")

from config.wsgi import application  # noqa: E402

__all__ = ["application"]
