"""
Auto-trade kill switch.

Usage:
    python kalshi_kill.py on      -> create kill-switch file (auto-trade disabled)
    python kalshi_kill.py off     -> remove kill-switch file (auto-trade allowed)
    python kalshi_kill.py status  -> show current state

When the file E:/soccer/AUTO_TRADE_KILL exists, place_auto_order() in
daily_signals.py refuses to place ANY orders, even if AUTO_TRADE_ENABLED=True.
This is the panic button.
"""
import sys
from pathlib import Path

KILL_FILE = Path(r"E:\soccer\data\AUTO_TRADE_KILL")


def on():
    KILL_FILE.write_text("kill-switch engaged\n")
    print(f"KILL-SWITCH ENGAGED - auto-trade DISABLED ({KILL_FILE})")


def off():
    if KILL_FILE.exists():
        KILL_FILE.unlink()
        print(f"KILL-SWITCH RELEASED - auto-trade re-enabled (file removed)")
    else:
        print("Kill-switch was not engaged (file did not exist)")


def status():
    if KILL_FILE.exists():
        print(f"KILL-SWITCH IS ENGAGED ({KILL_FILE})")
        print(f"  contents: {KILL_FILE.read_text().strip()}")
    else:
        print("Kill-switch is OFF (auto-trade allowed if AUTO_TRADE_ENABLED=True)")


if __name__ == "__main__":
    cmd = sys.argv[1].lower() if len(sys.argv) > 1 else "status"
    if cmd == "on":
        on()
    elif cmd == "off":
        off()
    elif cmd == "status":
        status()
    else:
        print(f"Unknown command: {cmd}. Use: on | off | status")
        sys.exit(1)
