#!/usr/bin/env python3
"""
Main application entry point for INDEX-SISTEM-JOCURI v2.0
"""

import os
import sys
from pathlib import Path

# Add parent directory to Python path
sys.path.insert(0, str(Path(__file__).parent.parent))

from app import create_app
from app.config import Config, ProductionConfig, DevelopmentConfig

def main():
    """Main application entry point"""
    
    # Ensure directories exist
    Config.ensure_directories()
    
    # Determine configuration
    flask_env = os.environ.get('FLASK_ENV', 'development')
    if flask_env == 'production':
        config_class = ProductionConfig
    else:
        config_class = DevelopmentConfig
    
    # Create application
    app = create_app(config_class)
    
    # Print startup information
    print("🚀 Starting INDEX-SISTEM-JOCURI v2.0")
    print("=" * 50)
    print(f"Environment: {flask_env}")
    print(f"Debug mode: {app.config['DEBUG']}")
    print(f"Database: {app.config['DATABASE_URL']}")
    print("=" * 50)
    
    # Run application
    host = os.environ.get('FLASK_HOST', '0.0.0.0')
    port = int(os.environ.get('FLASK_PORT', '5000'))
    
    app.run(
        host=host,
        port=port,
        debug=app.config['DEBUG'],
        threaded=True
    )

if __name__ == '__main__':
    main()