import logging  # Import the logging module for logging configuration

from app import AppConfig, create_app

app = create_app()

# Logging Configuration
logging.basicConfig(
    level=logging.DEBUG if app.debug else logging.INFO,
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)

logger = logging.getLogger(__name__)



if __name__ == "__main__":
    # Configuration using AppConfig from config.py
    HOST = AppConfig.HOST
    PORT = AppConfig.PORT

    try: 
        
        logger.info(f"Starting server at {HOST}:{PORT}")
        import uvicorn

        uvicorn.run(
            "main:app",  # Use "main:app" to specify the app instance
            host=HOST,
            port=PORT,
            reload=AppConfig.DEBUG,  # Use the DEBUG setting from config.py
        )
    except Exception as e:
        logger.exception(f"Failed to start the server: {str(e)}")
