#!/usr/bin/env python
"""
scheduler.py - Simple school schedule checker
No sample data, just real CSV data
"""

import datetime
from database import SchoolScheduleDB

def main():
    db = SchoolScheduleDB()
    
    print("🏫 School Schedule Checker")
    
    # Ask for student name
    name_query = input("\nEnter your name (or part of it): ").strip()
    
    # Search for student
    students = db.find_student(name_query)
    
    if not students:
        print("No student found.")
        return
    
    # Show found students
    print("\nFound students:")
    for i, (full_name, class_name) in enumerate(students, 1):
        print(f"{i}. {full_name} ({class_name})")
    
    # Let user select
    if len(students) > 1:
        choice = input(f"\nSelect student (1-{len(students)}): ")
        try:
            idx = int(choice) - 1
            if 0 <= idx < len(students):
                full_name, class_name = students[idx]
            else:
                print("Invalid choice.")
                return
        except:
            print("Invalid input.")
            return
    else:
        full_name, class_name = students[0]
    
    print(f"\n👤 Student: {full_name} ({class_name})")
    
    # Get current time
    now = datetime.datetime.now()
    current_day = now.strftime("%A")
    current_time = now.strftime("%H:%M")
    
    print(f"📅 Today: {current_day}")
    print(f"⏰ Time: {current_time}")
    
    # Find current class
    current_class = db.get_current_class(full_name, current_day, current_time)
    
    if current_class:
        subject, teacher, start, end = current_class
        print(f"\n🎯 CURRENT CLASS:")
        print(f"📚 {subject}")
        print(f"👨‍🏫 {teacher}")
        print(f"🕐 {start}-{end}")
    else:
        print("\n😊 Free period!")
    
    db.close()

if __name__ == "__main__":
    main()