#!/usr/bin/env python3
"""
Educational Tutor Bot - Main Entry Point
Author: RSK World (https://rskworld.in)
Founded by: Molla Samser
Designer & Tester: Rima Khatun
Contact: info@rskworld.com, +91 93305 39277
Year: 2026
"""

import os
import sys
from app import app

def main():
    """Main entry point for the Educational Tutor Bot"""
    
    print("=" * 60)
    print("    EDUCATIONAL TUTOR BOT - RSK WORLD")
    print("=" * 60)
    print("Author: RSK World (https://rskworld.in)")
    print("Founded by: Molla Samser")
    print("Designer & Tester: Rima Khatun")
    print("Contact: info@rskworld.com | +91 93305 39277")
    print("Year: 2026")
    print("=" * 60)
    print()
    
    # Check for OpenAI API key
    if not os.getenv('OPENAI_API_KEY'):
        print("⚠️  WARNING: OPENAI_API_KEY environment variable not set!")
        print("   Please set your OpenAI API key to use the AI features.")
        print("   You can get one from: https://platform.openai.com/api-keys")
        print()
    
    # Check if data directory exists
    if not os.path.exists('data'):
        print("📁 Creating data directory...")
        os.makedirs('data')
        print("   Data directory created successfully!")
        print()
    
    # Check if logs directory exists
    if not os.path.exists('logs'):
        print("📁 Creating logs directory...")
        os.makedirs('logs')
        print("   Logs directory created successfully!")
        print()
    
    print("🚀 Starting Educational Tutor Bot...")
    print("📍 Server will be available at: http://localhost:5000")
    print("🎯 Features:")
    print("   • AI-powered tutoring with OpenAI")
    print("   • Multiple subjects support")
    print("   • Progress tracking")
    print("   • Chat history")
    print("   • Responsive web interface")
    print()
    print("📚 Supported Subjects:")
    print("   • Mathematics")
    print("   • Science (Physics, Chemistry, Biology)")
    print("   • History")
    print("   • English")
    print("   • Computer Science")
    print("   • And more!")
    print()
    print("⏹️  Press Ctrl+C to stop the server")
    print("=" * 60)
    print()
    
    try:
        # Run the Flask application
        app.run(
            host='0.0.0.0',
            port=5000,
            debug=True,
            use_reloader=True
        )
    except KeyboardInterrupt:
        print("\n\n🛑 Server stopped by user")
        print("👋 Thank you for using Educational Tutor Bot!")
        print("© 2026 RSK World. All rights reserved.")
    except Exception as e:
        print(f"\n❌ Error starting server: {e}")
        print("Please check your configuration and try again.")
        sys.exit(1)

if __name__ == '__main__':
    main()
