from loguru import logger

from ..utilities.db_utils import get_db_setting
from ..utilities.log_utils import config_logger
from .app_factory import create_app


@logger.catch
def main():
    """
    Entry point for the web application when run as a command.
    This function is needed for the package's entry point to work properly.
    """
    # Configure logging with milestone level
    config_logger("ldr_web")

    # Create the Flask app and SocketIO instance
    app, socketio = create_app()

    # Get web server settings with defaults
    port = get_db_setting("web.port", 5000)
    host = get_db_setting("web.host", "0.0.0.0")
    debug = get_db_setting("web.debug", True)

    with app.app_context():
        socketio.run(host, port, debug=debug)


if __name__ == "__main__":
    main()
