#!/usr/bin/env python3
"""
vps-tool.py — GGVPS Troubleautomagic Support Dev Edition
Version 2.0 (Python 3 rewrite of vps-tool.sh v1.7)

Usage:
    vps-tool.py                   — run the interactive menu
    vps-tool.py <command> [args]  — run a specific command directly
    vps-tool.py help              — list all available commands
    vps-tool.py --no-summary      — skip startup summary, go to menu

Requires Python 3.6+
Optional: pip3 install colorama
"""

import sys
import os

if sys.version_info < (3, 6):
    sys.exit("Error: vps-tool requires Python 3.6 or later (found {}.{}).".format(
        sys.version_info.major, sys.version_info.minor))

# Ensure modules directory is importable regardless of invocation path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

from modules.output import colorama_missing_notice


def main():
    args = sys.argv[1:]

    # Colorama notice (once, at startup)
    colorama_missing_notice()

    # Flag: skip summary
    skip_summary = '--no-summary' in args
    if skip_summary:
        args = [a for a in args if a != '--no-summary']

    # Run startup summary unless suppressed or running a direct command
    # (Direct command invocation skips the summary for speed)
    run_startup_summary = not skip_summary and not args

    secpol = 'N'
    if run_startup_summary:
        try:
            from modules.summary import run_summary
            secpol = run_summary() or 'N'
        except Exception as e:
            from modules.output import warn
            warn(f"Summary failed: {e}")

    # Sync security policy state into security module
    from modules.security import set_secpol
    set_secpol(secpol)

    if not args:
        # Interactive menu mode
        from modules.menu import show_menu
        show_menu()
    else:
        # Direct command mode: vps-tool.py <command> [args...]
        cmd = args[0].lower()
        cmd_args = args[1:]
        from modules.menu import dispatch
        dispatch(cmd, cmd_args)


if __name__ == '__main__':
    main()
