"""
Allow running as: python -m jyoti
Also auto-fixes PATH on Linux/macOS so the 'jyoti' command works in future sessions.
"""

import os
import sys
import platform
from pathlib import Path


def _auto_fix_path():
    """Add ~/.local/bin to PATH in shell config files if not present."""
    try:
        if platform.system() == "Windows":
            return

        home = Path.home()
        shell_configs = [
            home / ".bashrc",
            home / ".zshrc",
            home / ".profile",
            home / ".bash_profile",
        ]

        path_export_line = (
            '\n# Added by jyoti package (Happy Birthday! 🎂)\n'
            'export PATH="$HOME/.local/bin:$PATH"\n'
        )

        for config_file in shell_configs:
            if config_file.exists():
                try:
                    content = config_file.read_text(encoding="utf-8", errors="ignore")
                    if ".local/bin" not in content:
                        with open(config_file, "a", encoding="utf-8") as f:
                            f.write(path_export_line)
                except (PermissionError, OSError):
                    continue
    except Exception:
        pass


# Fix PATH before running celebration
_auto_fix_path()

from jyoti.cli import main
main()
