#!/usr/bin/env python3
# This file exists when running Anges to code itself. Hopefully the process name DO_NOT_KILL_THIS_PROCESS will prevent accidental termination.

from anges.web_interface.web_interface import init_app
import argparse
import logging
from dotenv import load_dotenv
import os

# Load environment variables from .env file
load_dotenv()

# Configure logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

def parse_arguments():
    parser = argparse.ArgumentParser(description='Run web interface for ANGES')
    parser.add_argument('--password', help='Web interface password')
    parser.add_argument('--host', help='Host address to bind')
    parser.add_argument('--port', type=int, help='Port number to listen on')
    return parser.parse_args()

# Get configuration from environment variables with defaults
args = parse_arguments()
WEB_HOST = args.host or os.getenv('WEB_HOST', '127.0.0.1')
WEB_PORT = args.port or int(os.getenv('DO_NOT_KILL_PORT', '5555'))
WEB_PASS = args.password or os.getenv('WEB_PASS')

# Create and run the app
app = init_app(WEB_PASS)
app.run(host=WEB_HOST, port=WEB_PORT, debug=True, use_reloader=False)
